其余的web服务响应为空使用Apache cxf

问题描述:

我已经尝试过使用Apache CXF休息webservice。我正在执行创建操作。我能够创建,虽然以json和xml格式返回响应,但我没有得到任何价值。下面是我的服务和serviceImplementation。 服务类:其余的web服务响应为空使用Apache cxf

@Path("/location/") 
@WebService 
public interface LocationService { 

    @WebMethod 
    @POST 
    @Path("location") 
    @Produces({"application/xml","application/json"}) 
    @Descriptions({ 
     @Description(value = "stores a new location data", target = DocTarget.METHOD), 
     @Description(value = "the newly created location data", target = DocTarget.RETURN) 
    }) 
    public LocationData createLocation(@Valid LocationData locationData) throws DuplicateLocationException; 

} 

ServiceImplementation:

@Service("locationService") 
public class LocationServiceEndpoint implements LocationService { 

    @Override 
    public LocationData createLocation(LocationData locationData) { 

     setNewID(locationData); 
     return locationData; 
    } 

    private void setNewID(LocationData locationData) { 
     // setting the ID 
     String id = UUID.randomUUID().toString(); 
     locationData.setId(id); 

    } 
} 

BeanClass:

@XmlRootElement(name = "LocationData") 
public class LocationData { 

    private String id; 
    @DateTimeFormat(pattern="yyyy-mm-dd") 
    private Date date; 
    @NotNull 
    private String timezone; 
    @NotNull 
    @Size(max = 20, min = 5) 
    private String location; 

    public void setTimezone(String timezone) { 
     this.timezone = timezone; 
    } 

    public String getTimezone() { 
     return timezone; 
    } 

    public void setLocation(String location) { 
     this.location = location; 
    } 

    public String getLocation() { 
     return location; 
    } 

    public void setDate(Date date) { 
     this.date = date; 
    } 

    public Date getDate() { 
     return date; 
    } 

    public String getId() { 
     return id; 
    } 

    public void setId(String id) { 
     this.id = id; 
    } 

    @Override 
    public String toString() { 
     StringBuilder sb = new StringBuilder(); 
     Formatter formatter = new Formatter(sb, Locale.US); 
     formatter.format("ID:%s\nLocation:%s\nDate:%s\nTime zone:%s\n", getId(), getLocation(), getDate(), getTimezone()); 

     return sb.toString(); 
    } 
} 

我cxf.xml

<?xml version="1.0" encoding="UTF-8"?> 
<beans xmlns="http://www.springframework.org/schema/beans" 
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
     xmlns:jaxrs="http://cxf.apache.org/jaxrs" 
     xmlns:jaxws="http://cxf.apache.org/jaxws" 
     xmlns:context="http://www.springframework.org/schema/context" 
     xmlns:util="http://www.springframework.org/schema/util" 
     xmlns:cxf="http://cxf.apache.org/core" 
     xsi:schemaLocation=" 
     http://cxf.apache.org/core http://cxf.apache.org/schemas/core.xsd 
     http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd 
     http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd 
     http://cxf.apache.org/jaxrs http://cxf.apache.org/schemas/jaxrs.xsd 
     http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd 
     http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.1.xsd"> 


    <!-- REST --> 
    <import resource="classpath:META-INF/cxf/cxf.xml" /> 
    <import resource="classpath:META-INF/cxf/osgi/cxf-extension-osgi.xml" /> 

    <!-- SOAP --> 
    <import resource="classpath:META-INF/cxf/cxf-servlet.xml" /> 


    <context:component-scan base-package="org.exampledriven.cxfexample"/> 

    <!-- PROVIDERS --> 

    <bean id="wadlProvider" class="org.apache.cxf.jaxrs.model.wadl.WadlGenerator"> 
     <property name="applicationTitle" value="CXF Test sample application" /> 
    </bean> 

    <bean id="jaxbProvider" class="org.apache.cxf.jaxrs.provider.JAXBElementProvider"> 
     <property name="marshallerProperties" ref="propertiesMap" /> 
    </bean> 

    <util:map id="propertiesMap"> 
     <entry key="jaxb.formatted.output"> 
      <value type="java.lang.Boolean">true</value> 
     </entry> 
    </util:map> 

    <bean id="jsonProvider" class="org.apache.cxf.jaxrs.provider.JSONProvider"> 
     <property name="namespaceMap" ref="jsonNamespaceMap" /> 
    </bean> 

    <util:map id="jsonNamespaceMap" map-class="java.util.Hashtable"> 
     <entry key="http://www.example.org/books" value="b" /> 
    </util:map> 

    <!-- REST SERVER --> 

    <jaxrs:server id="restContainer" address="/rest"> 
     <jaxrs:providers> 
      <ref bean="jaxbProvider" /> 
      <ref bean="jsonProvider" /> 
      <ref bean="wadlProvider" /> 
     </jaxrs:providers> 
     <jaxrs:serviceBeans> 
      <ref bean="locationService"/> 
     </jaxrs:serviceBeans> 
     <jaxrs:extensionMappings> 
      <entry key="xml" value="application/xml" /> 
      <entry key="json" value="application/json" /> 
     </jaxrs:extensionMappings>  
    </jaxrs:server> 

    <!-- SOAP SERVER --> 

    <jaxws:endpoint id="location" implementor="#locationService" address="/soap" /> 

    <!-- CXF Message logging --> 

    <cxf:bus> 
     <cxf:features> 
      <cxf:logging/> 
     </cxf:features> 
    </cxf:bus> 

    <!-- CLIENT --> 
    <!-- 
    <jaxrs:client id="locationClient" 
     address="http://localhost:8080/rest/" 
     serviceClass="org.exampledriven.cxfexample.webservice.LocationService" 
     inheritHeaders="true"> 
     <jaxrs:headers> 
      <entry key="Accept" value="application/xml"/> 
     </jaxrs:headers> 
    </jaxrs:client> 
    --> 

    <!-- Spring Validation --> 
    <bean id="validator" class="org.springframework.validation.beanvalidation.LocalValidatorFactoryBean"/> 

</beans> 

SOAP服务工作正常。 Rest没有生成XML和JSON格式的数据。

请帮忙!!!

LOG

2016-12-25 22:27:21,427 DEBUG [org.springframework.security.web.FilterChainProxy] - /cxf/rest/location/location.json at position 1 of 8 in additional filter chain; firing Filter: 'SecurityContextPersistenceFilter' 
2016-12-25 22:27:21,428 DEBUG [org.springframework.security.web.context.HttpSessionSecurityContextRepository] - No HttpSession currently exists 
2016-12-25 22:27:21,428 DEBUG [org.springframework.security.web.context.HttpSessionSecurityContextRepository] - No SecurityContext was available from the HttpSession: null. A new one will be created. 
2016-12-25 22:27:21,428 DEBUG [org.springframework.security.web.FilterChainProxy] - /cxf/rest/location/location.json at position 2 of 8 in additional filter chain; firing Filter: 'BasicAuthenticationFilter' 
2016-12-25 22:27:21,428 DEBUG [org.springframework.security.web.FilterChainProxy] - /cxf/rest/location/location.json at position 3 of 8 in additional filter chain; firing Filter: 'RequestCacheAwareFilter' 
2016-12-25 22:27:21,428 DEBUG [org.springframework.security.web.FilterChainProxy] - /cxf/rest/location/location.json at position 4 of 8 in additional filter chain; firing Filter: 'SecurityContextHolderAwareRequestFilter' 
2016-12-25 22:27:21,428 DEBUG [org.springframework.security.web.FilterChainProxy] - /cxf/rest/location/location.json at position 5 of 8 in additional filter chain; firing Filter: 'AnonymousAuthenticationFilter' 
2016-12-25 22:27:21,428 DEBUG [org.springframework.security.web.authentication.AnonymousAuthenticationFilter] - Populated SecurityContextHolder with anonymous token: 'org.sprin[email protected]9055c2bc: Principal: anonymousUser; Credentials: [PROTECTED]; Authenticated: true; Details: org.sprin[email protected]b364: RemoteIpAddress: 0:0:0:0:0:0:0:1; SessionId: null; Granted Authorities: ROLE_ANONYMOUS' 
2016-12-25 22:27:21,429 DEBUG [org.springframework.security.web.FilterChainProxy] - /cxf/rest/location/location.json at position 6 of 8 in additional filter chain; firing Filter: 'SessionManagementFilter' 
2016-12-25 22:27:21,429 DEBUG [org.springframework.security.web.FilterChainProxy] - /cxf/rest/location/location.json at position 7 of 8 in additional filter chain; firing Filter: 'ExceptionTranslationFilter' 
2016-12-25 22:27:21,429 DEBUG [org.springframework.security.web.FilterChainProxy] - /cxf/rest/location/location.json at position 8 of 8 in additional filter chain; firing Filter: 'FilterSecurityInterceptor' 
2016-12-25 22:27:21,429 DEBUG [org.springframework.security.web.util.AntPathRequestMatcher] - Checking match of request : '/cxf/rest/location/location.json'; against '/rest/**' 
2016-12-25 22:27:21,429 DEBUG [org.springframework.security.web.access.intercept.FilterSecurityInterceptor] - Public object - authentication not attempted 
2016-12-25 22:27:21,429 DEBUG [org.springframework.security.web.FilterChainProxy] - /cxf/rest/location/location.json reached end of additional filter chain; proceeding with original chain 
2016-12-25 22:27:21,430 DEBUG [org.apache.cxf.transport.servlet.ServletController] - Service http request on thread: Thread[qtp1179689991-19,5,main] 
2016-12-25 22:27:21,430 DEBUG [org.apache.cxf.transport.http.AbstractHTTPDestination] - Create a new message for processing 
2016-12-25 22:27:21,431 DEBUG [org.apache.cxf.transport.http.Headers] - Request Headers: {Accept=[*/*], accept-encoding=[gzip, deflate, br], Accept-Language=[en-US,en;q=0.8], connection=[keep-alive], Content-Length=[0], content-type=[application/json], Host=[localhost:8080], Origin=[chrome-extension://eipdnjedkpcnlmmdfdkgfpljanehloah], User-Agent=[Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.99 Safari/537.36]} 
2016-12-25 22:27:21,432 DEBUG [org.apache.cxf.phase.PhaseInterceptorChain] - Adding interceptor org.apache.cxf.tr[email protected] to phase pre-stream 
2016-12-25 22:27:21,432 DEBUG [org.apache.cxf.phase.PhaseInterceptorChain] - Chain [email protected] was created. Current flow: 
    receive [LoggingInInterceptor] 
    pre-stream [CertConstraintsInterceptor] 
    unmarshal [JAXRSInInterceptor] 
    pre-logical [OneWayProcessorInterceptor] 
    invoke [ServiceInvokerInterceptor] 
    post-invoke [OutgoingChainInterceptor] 

2016-12-25 22:27:21,432 DEBUG [org.apache.cxf.phase.PhaseInterceptorChain] - Invoking handleMessage on interceptor [email protected] 
2016-12-25 22:27:21,433 INFO [org.apache.cxf.interceptor.LoggingInInterceptor] - Inbound Message 
---------------------------- 
ID: 8 
Address: http://localhost:8080/cxf/rest/location/location.json 
Encoding: ISO-8859-1 
Http-Method: POST 
Content-Type: application/json 
Headers: {Accept=[*/*], accept-encoding=[gzip, deflate, br], Accept-Language=[en-US,en;q=0.8], connection=[keep-alive], Content-Length=[0], content-type=[application/json], Host=[localhost:8080], Origin=[chrome-extension://eipdnjedkpcnlmmdfdkgfpljanehloah], User-Agent=[Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.99 Safari/537.36]} 
-------------------------------------- 
2016-12-25 22:27:21,433 DEBUG [org.apache.cxf.phase.PhaseInterceptorChain] - Invoking handleMessage on interceptor [email protected]5b 
2016-12-25 22:27:21,433 DEBUG [org.apache.cxf.phase.PhaseInterceptorChain] - Invoking handleMessage on interceptor [email protected] 
2016-12-25 22:27:21,434 DEBUG [org.apache.cxf.jaxrs.utils.JAXRSUtils] - Trying to select a resource class, request path : /location/location 
2016-12-25 22:27:21,434 DEBUG [org.apache.cxf.jaxrs.utils.JAXRSUtils] - Trying to select a resource operation on the resource class org.exampledriven.cxfexample.webservice.LocationServiceEndpoint 
2016-12-25 22:27:21,435 DEBUG [org.apache.cxf.jaxrs.utils.JAXRSUtils] - No method match, method name : readLocation, request path : /location, method @Path : /rest, HTTP Method : POST, method HTTP Method : GET, ContentType : application/json, method @Consumes : */*,, Accept : application/json,, method @Produces : */*,. 
2016-12-25 22:27:21,435 DEBUG [org.apache.cxf.jaxrs.utils.JAXRSUtils] - Resource operation createLocation may get selected 
2016-12-25 22:27:21,436 DEBUG [org.apache.cxf.jaxrs.utils.JAXRSUtils] - Resource operation createLocation on the resource class org.exampledriven.cxfexample.webservice.LocationServiceEndpoint has been selected 
2016-12-25 22:27:21,437 DEBUG [org.apache.cxf.jaxrs.interceptor.JAXRSInInterceptor] - Request path is: /location/location 
2016-12-25 22:27:21,437 DEBUG [org.apache.cxf.jaxrs.interceptor.JAXRSInInterceptor] - Request HTTP method is: POST 
2016-12-25 22:27:21,437 DEBUG [org.apache.cxf.jaxrs.interceptor.JAXRSInInterceptor] - Request contentType is: application/json 
2016-12-25 22:27:21,437 DEBUG [org.apache.cxf.jaxrs.interceptor.JAXRSInInterceptor] - Accept contentType is: application/json 
2016-12-25 22:27:21,437 DEBUG [org.apache.cxf.jaxrs.interceptor.JAXRSInInterceptor] - Found operation: createLocation 
2016-12-25 22:27:21,515 WARN [org.apache.cxf.jaxrs.impl.WebApplicationExceptionMapper] - WebApplicationException has been caught : org.codehaus.jettison.json.JSONException: A JSONObject text must begin with '{' at character 0 of 
2016-12-25 22:27:21,515 DEBUG [org.apache.cxf.jaxrs.impl.WebApplicationExceptionMapper] - org.codehaus.jettison.json.JSONException: A JSONObject text must begin with '{' at character 0 of 
javax.ws.rs.WebApplicationException: javax.xml.stream.XMLStreamException: org.codehaus.jettison.json.JSONException: A JSONObject text must begin with '{' at character 0 of 
    at org.apache.cxf.jaxrs.provider.JSONProvider.readFrom(JSONProvider.java:236) 
    at org.apache.cxf.jaxrs.utils.JAXRSUtils.readFromMessageBody(JAXRSUtils.java:1036) 
    at org.apache.cxf.jaxrs.utils.JAXRSUtils.processParameter(JAXRSUtils.java:616) 
    at org.apache.cxf.jaxrs.utils.JAXRSUtils.processParameters(JAXRSUtils.java:580) 
    at org.apache.cxf.jaxrs.interceptor.JAXRSInInterceptor.processRequest(JAXRSInInterceptor.java:238) 
    at org.apache.cxf.jaxrs.interceptor.JAXRSInInterceptor.handleMessage(JAXRSInInterceptor.java:89) 
    at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:263) 
    at org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationObserver.java:123) 
    at org.apache.cxf.transport.http.AbstractHTTPDestination.invoke(AbstractHTTPDestination.java:207) 
    at org.apache.cxf.transport.servlet.ServletController.invokeDestination(ServletController.java:213) 
    at org.apache.cxf.transport.servlet.ServletController.invoke(ServletController.java:154) 
    at org.apache.cxf.transport.servlet.CXFNonSpringServlet.invoke(CXFNonSpringServlet.java:126) 
    at org.apache.cxf.transport.servlet.AbstractHTTPServlet.handleRequest(AbstractHTTPServlet.java:185) 
    at org.apache.cxf.transport.servlet.AbstractHTTPServlet.doPost(AbstractHTTPServlet.java:108) 
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:754) 
    at org.apache.cxf.transport.servlet.AbstractHTTPServlet.service(AbstractHTTPServlet.java:164) 
    at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:550) 
    at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1359) 
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:311) 
    at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:116) 
    at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:83) 
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:323) 
    at org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:113) 
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:323) 
    at org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:101) 
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:323) 
    at org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:113) 
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:323) 
    at org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:54) 
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:323) 
    at org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(RequestCacheAwareFilter.java:45) 
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:323) 
    at org.springframework.security.web.authentication.www.BasicAuthenticationFilter.doFilter(BasicAuthenticationFilter.java:150) 
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:323) 
    at org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:87) 
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:323) 
    at org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:173) 
    at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:346) 
    at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:259) 
    at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1330) 
    at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:484) 
    at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:119) 
    at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:517) 
    at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:229) 
    at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:970) 
    at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:414) 
    at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:187) 
    at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:904) 
    at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:117) 
    at org.eclipse.jetty.server.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:247) 
    at org.eclipse.jetty.server.handler.HandlerCollection.handle(HandlerCollection.java:149) 
    at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:110) 
    at org.eclipse.jetty.server.Server.handle(Server.java:347) 
    at org.eclipse.jetty.server.HttpConnection.handleRequest(HttpConnection.java:590) 
    at org.eclipse.jetty.server.HttpConnection$RequestHandler.headerComplete(HttpConnection.java:1054) 
    at org.eclipse.jetty.http.HttpParser.parseNext(HttpParser.java:601) 
    at org.eclipse.jetty.http.HttpParser.parseAvailable(HttpParser.java:214) 
    at org.eclipse.jetty.server.HttpConnection.handle(HttpConnection.java:411) 
    at org.eclipse.jetty.io.nio.SelectChannelEndPoint.handle(SelectChannelEndPoint.java:535) 
    at org.eclipse.jetty.io.nio.SelectChannelEndPoint$1.run(SelectChannelEndPoint.java:40) 
    at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:529) 
    at java.lang.Thread.run(Thread.java:745) 
Caused by: javax.xml.stream.XMLStreamException: org.codehaus.jettison.json.JSONException: A JSONObject text must begin with '{' at character 0 of 
    at org.codehaus.jettison.mapped.MappedXMLInputFactory.createXMLStreamReader(MappedXMLInputFactory.java:46) 
    at org.codehaus.jettison.AbstractXMLInputFactory.createXMLStreamReader(AbstractXMLInputFactory.java:106) 
    at org.codehaus.jettison.AbstractXMLInputFactory.createXMLStreamReader(AbstractXMLInputFactory.java:93) 
    at org.apache.cxf.jaxrs.provider.JSONUtils.createStreamReader(JSONUtils.java:141) 
    at org.apache.cxf.jaxrs.provider.JSONProvider.createReader(JSONProvider.java:257) 
    at org.apache.cxf.jaxrs.provider.JSONProvider.createReader(JSONProvider.java:248) 
    at org.apache.cxf.jaxrs.provider.JSONProvider.readFrom(JSONProvider.java:212) 
    ... 61 more 
Caused by: org.codehaus.jettison.json.JSONException: A JSONObject text must begin with '{' at character 0 of 
    at org.codehaus.jettison.json.JSONTokener.syntaxError(JSONTokener.java:439) 
    at org.codehaus.jettison.json.JSONObject.<init>(JSONObject.java:170) 
    at org.codehaus.jettison.mapped.MappedXMLInputFactory.createXMLStreamReader(MappedXMLInputFactory.java:43) 
    ... 67 more 
2016-12-25 22:27:21,520 DEBUG [org.apache.cxf.phase.PhaseInterceptorChain] - Invoking handleMessage on interceptor [email protected] 
2016-12-25 22:27:21,520 DEBUG [org.apache.cxf.phase.PhaseInterceptorChain] - Invoking handleMessage on interceptor [email protected] 
2016-12-25 22:27:21,520 DEBUG [org.apache.cxf.phase.PhaseInterceptorChain] - Invoking handleMessage on interceptor [email protected] 
2016-12-25 22:27:21,521 DEBUG [org.apache.cxf.interceptor.OutgoingChainInterceptor] - Interceptors contributed by bus: [[email protected]] 
2016-12-25 22:27:21,521 DEBUG [org.apache.cxf.interceptor.OutgoingChainInterceptor] - Interceptors contributed by service: [] 
2016-12-25 22:27:21,521 DEBUG [org.apache.cxf.interceptor.OutgoingChainInterceptor] - Interceptors contributed by endpoint: [[email protected]] 
2016-12-25 22:27:21,522 DEBUG [org.apache.cxf.interceptor.OutgoingChainInterceptor] - Interceptors contributed by binding: [[email protected]] 
2016-12-25 22:27:21,522 DEBUG [org.apache.cxf.phase.PhaseInterceptorChain] - Chain [email protected] was created. Current flow: 
    prepare-send [MessageSenderInterceptor] 
    pre-stream [LoggingOutInterceptor] 
    marshal [JAXRSOutInterceptor] 

2016-12-25 22:27:21,522 DEBUG [org.apache.cxf.phase.PhaseInterceptorChain] - Invoking handleMessage on interceptor [email protected] 
2016-12-25 22:27:21,523 DEBUG [org.apache.cxf.phase.PhaseInterceptorChain] - Adding interceptor org.apache.cxf.inte[email protected]1cea4141 to phase prepare-send-ending 
2016-12-25 22:27:21,524 DEBUG [org.apache.cxf.phase.PhaseInterceptorChain] - Chain [email protected] was modified. Current flow: 
    prepare-send [MessageSenderInterceptor] 
    pre-stream [LoggingOutInterceptor] 
    marshal [JAXRSOutInterceptor] 
    prepare-send-ending [MessageSenderEndingInterceptor] 

2016-12-25 22:27:21,524 DEBUG [org.apache.cxf.phase.PhaseInterceptorChain] - Invoking handleMessage on interceptor [email protected] 
2016-12-25 22:27:21,524 DEBUG [org.apache.cxf.phase.PhaseInterceptorChain] - Invoking handleMessage on interceptor [email protected] 
2016-12-25 22:27:21,527 DEBUG [org.apache.cxf.phase.PhaseInterceptorChain] - Invoking handleMessage on interceptor org.apache.cxf.inte[email protected]1cea4141 
2016-12-25 22:27:21,528 INFO [org.apache.cxf.interceptor.LoggingOutInterceptor] - Outbound Message 
--------------------------- 
ID: 8 
Response-Code: 500 
Content-Type: text/xml 
Headers: {Date=[Sun, 25 Dec 2016 16:57:21 GMT], Content-Length=[0]} 
-------------------------------------- 
2016-12-25 22:27:21,532 DEBUG [org.apache.cxf.transport.servlet.ServletController] - Finished servicing http request on thread: Thread[qtp1179689991-19,5,main] 
2016-12-25 22:27:21,532 DEBUG [org.springframework.security.web.access.ExceptionTranslationFilter] - Chain processed normally 
2016-12-25 22:27:21,532 DEBUG [org.springframework.security.web.context.HttpSessionSecurityContextRepository] - SecurityContext is empty or contents are anonymous - context will not be stored in HttpSession. 
2016-12-25 22:27:21,532 DEBUG [org.springframework.security.web.context.SecurityContextPersistenceFilter] - SecurityContextHolder now cleared, as request processing completed 

更新: 我已经添加在服务的另一种方法用于实现类执行读取操作和与其对应的逻辑。现在我能够以xml和json格式获得响应。我已经添加了以下方法

@WebMethod 
@GET 
@Path("{location}") 
@Descriptions({ 
    @Description(value = "returns a location data ", target = DocTarget.METHOD), 
    @Description(value = "the location data", target = DocTarget.RETURN) 
}) 
public LocationData readLocation(@Description(value = "the string representation of the location") @PathParam("location") @NotNull @Size(max=10, min=5) String location) throws LocationNotFoundException; 

但我想以JSON和XML格式的响应,同时执行创建操作本身

输出:Instead of Delhi, i will be having location, when i click on URL i get blank page

相反德里,我将其“位置”,当我在URL点击我得到的空白页

+0

我已经发布的评论作为答案的总结,而且似乎意见已被标记为过时。请考虑将答案标记为已接受,或者如果它有帮助,请立即投诉 – pedrofb

(注释中的解决方案)

根本的问题是INV的需要OKE使用URL链接

@POST 
@Path("location") 
@Produces({"application/xml","application/json"}) 
public LocationData createLocation(@Valid LocationData locationData) throws DuplicateLocationException; 

这是不可能的一个JAX-RS方法发送一个请求POST与一个URL JSON点击。单击链接或在浏览器工具栏中引入URL,执行GET请求。

第二种方法可行,因为使用GET和URL路径/rest/location/{location}。此方法无法接收JSON数据,但可以返回JSON。

您必须使用AJAX哟调用REST服务,POST发送json或XML。另外,您可以使用查询的URL发布数据点击参数

rest/location/create?location=Delhi&timezone= 

但是,这是不是很orthodoxe