2016-02-19 57 views
0

嗨,我需要在apache cxf服务器中实现异步处理请求。到目前为止,我认为我需要添加AsyncResponse请求。但它没有奏效。Apache cxf服务器异步请求处理

@GET 
@Path("/test") 
@Produces(MediaType.APPLICATION_XML) 
@Consumes(MediaType.APPLICATION_XML) 
void sample(@Suspended AsyncResponse asyncResponse); 

@Override 
    public void sample(AsyncResponse asyncResponse) { 
     asyncResponse.setTimeout(3, TimeUnit.MINUTES); 
     asyncResponse.setTimeoutHandler(new TimeoutHandler() { 
      @Override 
      public void handleTimeout(AsyncResponse asyncResponse) { 
       asyncResponse.resume("Sample"); 
      } 
     }); 

    } 

当我发送请求到终点时,它会抛出异常。

WebApplicationExceptionMapper - WebApplicationException has been caught, status: 415 
javax.ws.rs.WebApplicationException 
    at org.apache.cxf.jaxrs.utils.JAXRSUtils.readFromMessageBody(JAXRSUtils.java:1054) 
    at org.apache.cxf.jaxrs.utils.JAXRSUtils.processParameter(JAXRSUtils.java:614) 
    at org.apache.cxf.jaxrs.utils.JAXRSUtils.processParameters(JAXRSUtils.java:578) 
    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:262) 
    at org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationObserver.java:122) 
    at org.apache.cxf.transport.http_jetty.JettyHTTPDestination.serviceRequest(JettyHTTPDestination.java:344) 
    at org.apache.cxf.transport.http_jetty.JettyHTTPDestination.doService(JettyHTTPDestination.java:310) 
    at org.apache.cxf.transport.http_jetty.JettyHTTPHandler.handle(JettyHTTPHandler.java:72) 
    at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:943) 
    at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:879) 
    at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:117) 
    at org.eclipse.jetty.server.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:250) 
    at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:110) 
    at org.eclipse.jetty.server.Server.handle(Server.java:345) 
    at org.eclipse.jetty.server.HttpConnection.handleRequest(HttpConnection.java:441) 
    at org.eclipse.jetty.server.HttpConnection$RequestHandler.headerComplete(HttpConnection.java:919) 
    at org.eclipse.jetty.http.HttpParser.parseNext(HttpParser.java:582) 
    at org.eclipse.jetty.http.HttpParser.parseAvailable(HttpParser.java:218) 
    at org.eclipse.jetty.server.AsyncHttpConnection.handle(AsyncHttpConnection.java:51) 
    at org.eclipse.jetty.io.nio.SelectChannelEndPoint.handle(SelectChannelEndPoint.java:586) 
    at org.eclipse.jetty.io.nio.SelectChannelEndPoint$1.run(SelectChannelEndPoint.java:44) 
    at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:598) 
    at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:533) 

我想知道我实现了异步是正确的道路,如果它是什么,是我的执行问题的方式。

回答

1

不知道你是否仍在寻找答案。您的实现看起来很好,通过查看堆栈跟踪,似乎服务器无法正确理解请求。如果您正在使用任何过滤器,请检查web.xml。过滤器应该具有此属性(true)以支持异步调用。

你的过滤器应该应该寻找这样的..

<filter> 
    <filter-name>XXXXXX</filter-name> 
    <filter-class>xxx.xxx.xxx.XXXXXX</filter-class> 
    <async-supported>true</async-supported> 
</filter>