3

我的应用程序是一个 java webapp (WAR),它使用 Apache Camel 和(以及其他)CXF-RS 及其相应的 Camel 组件作为 JAX-RS 的实现,向外界提供 ReSTful 服务。

当使用 HTTP POST 和有效负载调用端点之一时,我得到了异常堆栈跟踪,如下所示。请注意,com.foo.FooService 和 com.foo.Foo 类是 JAXRS 注释的服务/资源对。

我特别困惑的是 create() 方法实际上被调用了,因为据我了解,用于 Camel 的 CXF-RS 以某种方式执行了一些魔术来拦截传入请求并将请求路由到 Camel 路由。

这些是类的简化版本:

@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD) 
public class Foo implements Serializable {
// some getters and setters go here
}


@Path("/")
public class FooService {

    public FooService() {
    }

    @POST
    @Path("/foos")
    @Consumes("application/xml")
    public Response create(Foo foo) {
        throw new UnsupportedOperationException();
    }
}

我在我的 Spring XML 中配置 cxf:rsServer 如下:

<cxf:rsServer id="fooServer" serviceClass="com.foo.FooService" address="/foorest"/>

路由在 Java 中定义如下:

from("cxfrs://bean://fooServer").id("foo-restadapter-route")
    .to("jms:queue:foos").inOnly();

这是我得到的例外:

SEVERE: Error occurred during error handling, give up!
org.apache.cxf.interceptor.Fault: null while invoking public javax.ws.rs.core.Response com.foo.FooService.create(com.foo.Foo) with params [com.foo.Foo@1ed43997].
        at org.apache.cxf.service.invoker.AbstractInvoker.createFault(AbstractInvoker.java:159)
        at org.apache.cxf.service.invoker.AbstractInvoker.invoke(AbstractInvoker.java:133)
        at org.apache.cxf.jaxrs.JAXRSInvoker.invoke(JAXRSInvoker.java:133)
        at org.apache.cxf.jaxrs.JAXRSInvoker.invoke(JAXRSInvoker.java:82)
        at org.apache.cxf.interceptor.ServiceInvokerInterceptor$1.run(ServiceInvokerInterceptor.java:58)
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441)
        at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
        at java.util.concurrent.FutureTask.run(FutureTask.java:138)
        at org.apache.cxf.workqueue.SynchronousExecutor.execute(SynchronousExecutor.java:37)
        at org.apache.cxf.interceptor.ServiceInvokerInterceptor.handleMessage(ServiceInvokerInterceptor.java:106)
        at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:243)
        at org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationObserver.java:110)
        at org.apache.cxf.transport.servlet.ServletDestination.invoke(ServletDestination.java:98)
        at org.apache.cxf.transport.servlet.ServletController.invokeDestination(ServletController.java:423)
        at org.apache.cxf.transport.servlet.ServletController.invoke(ServletController.java:139)
        at org.apache.cxf.transport.servlet.AbstractCXFServlet.invoke(AbstractCXFServlet.java:142)
        at org.apache.cxf.transport.servlet.AbstractHTTPServlet.handleRequest(AbstractHTTPServlet.java:179)
        at org.apache.cxf.transport.servlet.AbstractHTTPServlet.doPost(AbstractHTTPServlet.java:103)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
        at org.apache.cxf.transport.servlet.AbstractHTTPServlet.service(AbstractHTTPServlet.java:159)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
        at org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:393)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
        at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:852)
        at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
        at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
        at java.lang.Thread.run(Thread.java:662)
Caused by: java.lang.NullPointerException
        at org.apache.camel.component.cxf.jaxrs.CxfRsInvoker.getContinuation(CxfRsInvoker.java:63)
        at org.apache.camel.component.cxf.jaxrs.CxfRsInvoker.performInvocation(CxfRsInvoker.java:52)
        at org.apache.cxf.service.invoker.AbstractInvoker.invoke(AbstractInvoker.java:89)
        ... 33 more
4

1 回答 1

0

这是一个错误camel-cxf您可以通过像这样更改路线来解决此问题

from("cxfrs://bean://fooServer?synchronous=true").id("foo-restadapter-route")
.to("jms:queue:foos").inOnly();
于 2010-11-18T02:03:57.827 回答