当前位置: 首页 > 知识库问答 >
问题:

尝试获取正文的骆驼交换上的NullPointerException

宋宏儒
2023-03-14

我正在尝试设置服务总线。我尝试创建的第一个服务应该将SOAP转换为JSON。我创建了一个endpoint和一个WSDL都测试成功。当我尝试转换消息时,程序返回一个NullPointerException。

我在process函数中输出了以下数据:

交换[ID-91a89d0e303b-36665-1571915569757-0-2][消息:[com.example.UpsertItemRequest@6a8344b9]]

交换getIn()消息:[com.example.UpsertItemRequest@6a8344b9]

getIn().getBody(String.class)upsertItem引发了异常,现在正在释放org.apache.cxf.interceptor。故障:NullPointerException

applicationcontext.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:camel="http://camel.apache.org/schema/spring"
   xmlns:osgi="http://www.springframework.org/schema/osgi"
   xmlns:cxf="http://camel.apache.org/schema/cxf"
   xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd  http://www.springframework.org/schema/osgi http://www.springframework.org/schema/osgi/spring-osgi.xsd       http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd       http://camel.apache.org/schema/cxf http://camel.apache.org/schema/cxf/camel-cxf-2.8.3.xsd">

<cxf:cxfEndpoint id="upsertItemCxfEndpoint"
    address="/pimcore/upsertItem"
    endpointName="a:upsertItemEndpoint"
    serviceName="a:upsertItemService"
    wsdlURL="wsdl/upsert-item.wsdl"
    serviceClass="com.example.UpsertItemEndpoint"
    xmlns:a="http://example.com"/>

<bean id="upsertItemTransformer" class="com.example.esb.UpsertItemTransformer"/>

<bean id="upsertItemLogger" class="com.example.esb.UpsertItemLogger"/>

<camelContext id="camelId" xmlns="http://camel.apache.org/schema/spring">
    <route id="upsertItem">
        <from uri="cxf:bean:upsertItemCxfEndpoint" />
        <process ref="upsertItemLogger" />
        <process ref="upsertItemTransformer" />
    </route>
</camelContext>

UpsertItemTransformer.java

package com.example.esb;

import org.apache.camel.Exchange;
import org.apache.camel.Processor;

public class UpsertItemTransformer implements Processor {
    public void process(Exchange exchange) throws Exception {
        String body = exchange.getIn().getBody(String.class);
        exchange.getOut().setBody(body.toLowerCase());
    }
}

myPost.xml

<s11:Envelope xmlns:s11='http://schemas.xmlsoap.org/soap/envelope/'>
  <s11:Body>
    <ns1:upsertItemRequest xmlns:ns1='http://example.com'>
      <ItemCode>12345</ItemCode>
      </ns1:upsertItemRequest>
  </s11:Body>
</s11:Envelope>

堆栈跟踪

Stacktrace
---------------------------------------------------------------------------------------------------------------------------------------
java.lang.NullPointerException
    at com.example.esb.UpsertItemTransformer.process(UpsertItemTransformer.java:9)[222:com.example.sap_pimcore_product:1.0.0.SNAPSHOT]
    at org.apache.camel.processor.DelegateSyncProcessor.process(DelegateSyncProcessor.java:63)[43:org.apache.camel.camel-core:2.16.5]
    at org.apache.camel.management.InstrumentationProcessor.process(InstrumentationProcessor.java:77)[43:org.apache.camel.camel-core:2.16.5]
    at org.apache.camel.processor.RedeliveryErrorHandler.process(RedeliveryErrorHandler.java:460)[43:org.apache.camel.camel-core:2.16.5]
    at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:196)[43:org.apache.camel.camel-core:2.16.5]
    at org.apache.camel.processor.Pipeline.process(Pipeline.java:121)[43:org.apache.camel.camel-core:2.16.5]
    at org.apache.camel.processor.Pipeline.process(Pipeline.java:83)[43:org.apache.camel.camel-core:2.16.5]
    at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:196)[43:org.apache.camel.camel-core:2.16.5]
    at org.apache.camel.component.cxf.CxfConsumer$CxfConsumerInvoker.asyncInvoke(CxfConsumer.java:154)[44:org.apache.camel.camel-cxf:2.16.5]
    at org.apache.camel.component.cxf.CxfConsumer$CxfConsumerInvoker.invoke(CxfConsumer.java:133)[44:org.apache.camel.camel-cxf:2.16.5]
    at org.apache.cxf.interceptor.ServiceInvokerInterceptor$1.run(ServiceInvokerInterceptor.java:59)[57:org.apache.cxf.cxf-core:3.1.9]
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)[:1.8.0_222]
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)[:1.8.0_222]
    at org.apache.cxf.interceptor.ServiceInvokerInterceptor$2.run(ServiceInvokerInterceptor.java:126)[57:org.apache.cxf.cxf-core:3.1.9]
    at org.apache.cxf.workqueue.SynchronousExecutor.execute(SynchronousExecutor.java:37)[57:org.apache.cxf.cxf-core:3.1.9]
    at org.apache.cxf.interceptor.ServiceInvokerInterceptor.handleMessage(ServiceInvokerInterceptor.java:131)[57:org.apache.cxf.cxf-core:3.1.9]
    at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:308)[57:org.apache.cxf.cxf-core:3.1.9]
    at org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationObserver.java:121)[57:org.apache.cxf.cxf-core:3.1.9]
    at org.apache.cxf.transport.http.AbstractHTTPDestination.invoke(AbstractHTTPDestination.java:252)[82:org.apache.cxf.cxf-rt-transports-http:3.1.9]
    at org.apache.cxf.transport.servlet.ServletController.invokeDestination(ServletController.java:234)[82:org.apache.cxf.cxf-rt-transports-http:3.1.9]
    at org.apache.cxf.transport.servlet.ServletController.invoke(ServletController.java:208)[82:org.apache.cxf.cxf-rt-transports-http:3.1.9]
    at org.apache.cxf.transport.servlet.ServletController.invoke(ServletController.java:160)[82:org.apache.cxf.cxf-rt-transports-http:3.1.9]
    at org.apache.cxf.transport.servlet.CXFNonSpringServlet.invoke(CXFNonSpringServlet.java:180)[82:org.apache.cxf.cxf-rt-transports-http:3.1.9]
    at org.apache.cxf.transport.servlet.AbstractHTTPServlet.handleRequest(AbstractHTTPServlet.java:299)[82:org.apache.cxf.cxf-rt-transports-http:3.1.9]
    at org.apache.cxf.transport.servlet.AbstractHTTPServlet.doPost(AbstractHTTPServlet.java:218)[82:org.apache.cxf.cxf-rt-transports-http:3.1.9]
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:707)[17:javax.servlet-api:3.1.0]
    at org.apache.cxf.transport.servlet.AbstractHTTPServlet.service(AbstractHTTPServlet.java:274)[82:org.apache.cxf.cxf-rt-transports-http:3.1.9]
    at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:812)[188:org.eclipse.jetty.servlet:9.2.19.v20160908]
    at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:587)[188:org.eclipse.jetty.servlet:9.2.19.v20160908]
    at org.ops4j.pax.web.service.jetty.internal.HttpServiceServletHandler.doHandle(HttpServiceServletHandler.java:71)[211:org.ops4j.pax.web.pax-web-jetty:4.3.0]
    at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:143)[187:org.eclipse.jetty.server:9.2.19.v20160908]
    at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:577)[186:org.eclipse.jetty.security:9.2.19.v20160908]
    at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:223)[187:org.eclipse.jetty.server:9.2.19.v20160908]
    at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1127)[187:org.eclipse.jetty.server:9.2.19.v20160908]
    at org.ops4j.pax.web.service.jetty.internal.HttpServiceContext.doHandle(HttpServiceContext.java:287)[211:org.ops4j.pax.web.pax-web-jetty:4.3.0]
    at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:515)[188:org.eclipse.jetty.servlet:9.2.19.v20160908]
    at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:185)[187:org.eclipse.jetty.server:9.2.19.v20160908]
    at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1061)[187:org.eclipse.jetty.server:9.2.19.v20160908]
    at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141)[187:org.eclipse.jetty.server:9.2.19.v20160908]
    at org.ops4j.pax.web.service.jetty.internal.JettyServerHandlerCollection.handle(JettyServerHandlerCollection.java:80)[211:org.ops4j.pax.web.pax-web-jetty:4.3.0]
    at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:97)[187:org.eclipse.jetty.server:9.2.19.v20160908]
    at org.eclipse.jetty.server.Server.handle(Server.java:499)[187:org.eclipse.jetty.server:9.2.19.v20160908]
    at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:311)[187:org.eclipse.jetty.server:9.2.19.v20160908]
    at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:257)[187:org.eclipse.jetty.server:9.2.19.v20160908]
    at org.eclipse.jetty.io.AbstractConnection$2.run(AbstractConnection.java:544)[179:org.eclipse.jetty.io:9.2.19.v20160908]
    at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:635)[190:org.eclipse.jetty.util:9.2.19.v20160908]
    at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:555)[190:org.eclipse.jetty.util:9.2.19.v20160908]
    at java.lang.Thread.run(Thread.java:748)[:1.8.0_222]
2019-10-24 11:12:54,271 | WARN  | tp1559046516-107 | PhaseInterceptorChain            | 57 - org.apache.cxf.cxf-core - 3.1.9 | Application {http://example.com}upsertItemService#{http://example.com}upsertItem has thrown exception, unwinding now
org.apache.cxf.interceptor.Fault: NullPointerException
    at org.apache.camel.component.cxf.CxfConsumer$CxfConsumerInvoker.checkFailure(CxfConsumer.java:301)[44:org.apache.camel.camel-cxf:2.16.5]
    at org.apache.camel.component.cxf.CxfConsumer$CxfConsumerInvoker.setResponseBack(CxfConsumer.java:275)[44:org.apache.camel.camel-cxf:2.16.5]
    at org.apache.camel.component.cxf.CxfConsumer$CxfConsumerInvoker.asyncInvoke(CxfConsumer.java:169)[44:org.apache.camel.camel-cxf:2.16.5]
    at org.apache.camel.component.cxf.CxfConsumer$CxfConsumerInvoker.invoke(CxfConsumer.java:133)[44:org.apache.camel.camel-cxf:2.16.5]
    at org.apache.cxf.interceptor.ServiceInvokerInterceptor$1.run(ServiceInvokerInterceptor.java:59)[57:org.apache.cxf.cxf-core:3.1.9]
    at org.apache.cxf.interceptor.ServiceInvokerInterceptor.handleMessage(ServiceInvokerInterceptor.java:96)[57:org.apache.cxf.cxf-core:3.1.9]
    at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:308)[57:org.apache.cxf.cxf-core:3.1.9]
    at org.apache.cxf.phase.PhaseInterceptorChain.resume(PhaseInterceptorChain.java:278)[57:org.apache.cxf.cxf-core:3.1.9]
    at org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationObserver.java:78)[57:org.apache.cxf.cxf-core:3.1.9]
    at org.apache.cxf.transport.http.AbstractHTTPDestination.invoke(AbstractHTTPDestination.java:252)[82:org.apache.cxf.cxf-rt-transports-http:3.1.9]
    at org.apache.cxf.transport.servlet.ServletController.invokeDestination(ServletController.java:234)[82:org.apache.cxf.cxf-rt-transports-http:3.1.9]
    at org.apache.cxf.transport.servlet.ServletController.invoke(ServletController.java:208)[82:org.apache.cxf.cxf-rt-transports-http:3.1.9]
    at org.apache.cxf.transport.servlet.ServletController.invoke(ServletController.java:160)[82:org.apache.cxf.cxf-rt-transports-http:3.1.9]
    at org.apache.cxf.transport.servlet.CXFNonSpringServlet.invoke(CXFNonSpringServlet.java:180)[82:org.apache.cxf.cxf-rt-transports-http:3.1.9]
    at org.apache.cxf.transport.servlet.AbstractHTTPServlet.handleRequest(AbstractHTTPServlet.java:299)[82:org.apache.cxf.cxf-rt-transports-http:3.1.9]
    at org.apache.cxf.transport.servlet.AbstractHTTPServlet.doPost(AbstractHTTPServlet.java:218)[82:org.apache.cxf.cxf-rt-transports-http:3.1.9]
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:707)[17:javax.servlet-api:3.1.0]
    at org.apache.cxf.transport.servlet.AbstractHTTPServlet.service(AbstractHTTPServlet.java:274)[82:org.apache.cxf.cxf-rt-transports-http:3.1.9]
    at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:812)[188:org.eclipse.jetty.servlet:9.2.19.v20160908]
    at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:587)[188:org.eclipse.jetty.servlet:9.2.19.v20160908]
    at org.ops4j.pax.web.service.jetty.internal.HttpServiceServletHandler.doHandle(HttpServiceServletHandler.java:71)[211:org.ops4j.pax.web.pax-web-jetty:4.3.0]
    at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:143)[187:org.eclipse.jetty.server:9.2.19.v20160908]
    at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:577)[186:org.eclipse.jetty.security:9.2.19.v20160908]
    at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:223)[187:org.eclipse.jetty.server:9.2.19.v20160908]
    at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1127)[187:org.eclipse.jetty.server:9.2.19.v20160908]
    at org.ops4j.pax.web.service.jetty.internal.HttpServiceContext.doHandle(HttpServiceContext.java:287)[211:org.ops4j.pax.web.pax-web-jetty:4.3.0]
    at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:515)[188:org.eclipse.jetty.servlet:9.2.19.v20160908]
    at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:185)[187:org.eclipse.jetty.server:9.2.19.v20160908]
    at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1061)[187:org.eclipse.jetty.server:9.2.19.v20160908]
    at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141)[187:org.eclipse.jetty.server:9.2.19.v20160908]
    at org.ops4j.pax.web.service.jetty.internal.JettyServerHandlerCollection.handle(JettyServerHandlerCollection.java:80)[211:org.ops4j.pax.web.pax-web-jetty:4.3.0]
    at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:97)[187:org.eclipse.jetty.server:9.2.19.v20160908]
    at org.eclipse.jetty.server.Server.handleAsync(Server.java:549)[187:org.eclipse.jetty.server:9.2.19.v20160908]
    at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:318)[187:org.eclipse.jetty.server:9.2.19.v20160908]
    at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:257)[187:org.eclipse.jetty.server:9.2.19.v20160908]
    at org.eclipse.jetty.io.AbstractConnection$2.run(AbstractConnection.java:544)[179:org.eclipse.jetty.io:9.2.19.v20160908]
    at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:635)[190:org.eclipse.jetty.util:9.2.19.v20160908]
    at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:555)[190:org.eclipse.jetty.util:9.2.19.v20160908]
    at java.lang.Thread.run(Thread.java:748)[:1.8.0_222]
Caused by: java.lang.NullPointerException
    at com.example.esb.UpsertItemTransformer.process(UpsertItemTransformer.java:9)[222:com.example.sap_pimcore_product:1.0.0.SNAPSHOT]
    at org.apache.camel.processor.DelegateSyncProcessor.process(DelegateSyncProcessor.java:63)[43:org.apache.camel.camel-core:2.16.5]
    at org.apache.camel.management.InstrumentationProcessor.process(InstrumentationProcessor.java:77)[43:org.apache.camel.camel-core:2.16.5]
    at org.apache.camel.processor.RedeliveryErrorHandler.process(RedeliveryErrorHandler.java:460)[43:org.apache.camel.camel-core:2.16.5]
    at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:196)[43:org.apache.camel.camel-core:2.16.5]
    at org.apache.camel.processor.Pipeline.process(Pipeline.java:121)[43:org.apache.camel.camel-core:2.16.5]
    at org.apache.camel.processor.Pipeline.process(Pipeline.java:83)[43:org.apache.camel.camel-core:2.16.5]
    at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:196)[43:org.apache.camel.camel-core:2.16.5]
    at org.apache.camel.component.cxf.CxfConsumer$CxfConsumerInvoker.asyncInvoke(CxfConsumer.java:154)[44:org.apache.camel.camel-cxf:2.16.5]
    at org.apache.camel.component.cxf.CxfConsumer$CxfConsumerInvoker.invoke(CxfConsumer.java:133)[44:org.apache.camel.camel-cxf:2.16.5]
    at org.apache.cxf.interceptor.ServiceInvokerInterceptor$1.run(ServiceInvokerInterceptor.java:59)[57:org.apache.cxf.cxf-core:3.1.9]
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)[:1.8.0_222]
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)[:1.8.0_222]
    at org.apache.cxf.interceptor.ServiceInvokerInterceptor$2.run(ServiceInvokerInterceptor.java:126)[57:org.apache.cxf.cxf-core:3.1.9]
    at org.apache.cxf.workqueue.SynchronousExecutor.execute(SynchronousExecutor.java:37)[57:org.apache.cxf.cxf-core:3.1.9]
    at org.apache.cxf.interceptor.ServiceInvokerInterceptor.handleMessage(ServiceInvokerInterceptor.java:131)[57:org.apache.cxf.cxf-core:3.1.9]
    at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:308)[57:org.apache.cxf.cxf-core:3.1.9]
    at org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationObserver.java:121)[57:org.apache.cxf.cxf-core:3.1.9]
    at org.apache.cxf.transport.http.AbstractHTTPDestination.invoke(AbstractHTTPDestination.java:252)[82:org.apache.cxf.cxf-rt-transports-http:3.1.9]
    at org.apache.cxf.transport.servlet.ServletController.invokeDestination(ServletController.java:234)[82:org.apache.cxf.cxf-rt-transports-http:3.1.9]
    at org.apache.cxf.transport.servlet.ServletController.invoke(ServletController.java:208)[82:org.apache.cxf.cxf-rt-transports-http:3.1.9]
    at org.apache.cxf.transport.servlet.ServletController.invoke(ServletController.java:160)[82:org.apache.cxf.cxf-rt-transports-http:3.1.9]
    at org.apache.cxf.transport.servlet.CXFNonSpringServlet.invoke(CXFNonSpringServlet.java:180)[82:org.apache.cxf.cxf-rt-transports-http:3.1.9]
    at org.apache.cxf.transport.servlet.AbstractHTTPServlet.handleRequest(AbstractHTTPServlet.java:299)[82:org.apache.cxf.cxf-rt-transports-http:3.1.9]
    at org.apache.cxf.transport.servlet.AbstractHTTPServlet.doPost(AbstractHTTPServlet.java:218)[82:org.apache.cxf.cxf-rt-transports-http:3.1.9]
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:707)[17:javax.servlet-api:3.1.0]
    at org.apache.cxf.transport.servlet.AbstractHTTPServlet.service(AbstractHTTPServlet.java:274)[82:org.apache.cxf.cxf-rt-transports-http:3.1.9]
    at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:812)[188:org.eclipse.jetty.servlet:9.2.19.v20160908]
    at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:587)[188:org.eclipse.jetty.servlet:9.2.19.v20160908]
    at org.ops4j.pax.web.service.jetty.internal.HttpServiceServletHandler.doHandle(HttpServiceServletHandler.java:71)[211:org.ops4j.pax.web.pax-web-jetty:4.3.0]
    at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:143)[187:org.eclipse.jetty.server:9.2.19.v20160908]
    at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:577)[186:org.eclipse.jetty.security:9.2.19.v20160908]
    at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:223)[187:org.eclipse.jetty.server:9.2.19.v20160908]
    at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1127)[187:org.eclipse.jetty.server:9.2.19.v20160908]
    at org.ops4j.pax.web.service.jetty.internal.HttpServiceContext.doHandle(HttpServiceContext.java:287)[211:org.ops4j.pax.web.pax-web-jetty:4.3.0]
    at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:515)[188:org.eclipse.jetty.servlet:9.2.19.v20160908]
    at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:185)[187:org.eclipse.jetty.server:9.2.19.v20160908]
    at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1061)[187:org.eclipse.jetty.server:9.2.19.v20160908]
    at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141)[187:org.eclipse.jetty.server:9.2.19.v20160908]
    at org.ops4j.pax.web.service.jetty.internal.JettyServerHandlerCollection.handle(JettyServerHandlerCollection.java:80)[211:org.ops4j.pax.web.pax-web-jetty:4.3.0]
    at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:97)[187:org.eclipse.jetty.server:9.2.19.v20160908]
    at org.eclipse.jetty.server.Server.handle(Server.java:499)[187:org.eclipse.jetty.server:9.2.19.v20160908]
    at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:311)[187:org.eclipse.jetty.server:9.2.19.v20160908]
    ... 5 more

共有1个答案

沈鸿光
2023-03-14

我猜想NPE不是来自阅读正文,而是来自访问out消息正文。

在Camel中,out消息通常不存在。如果不存在,Camel会自动使用in消息。

因此,强烈建议Camel的最佳做法是不使用out消息,只更新in消息。当然也有一些特殊的例外情况,但当你需要它们时,你会发现它们。

所以做这个吧

public void process(Exchange exchange) throws Exception {
    String body = exchange.getIn().getBody(String.class);
    exchange.getIn().setBody(body.toLowerCase());
}

顺便说一句:处理器接口的使用和测试相当笨拙。改用pojo!

  • Java bean非常容易测试
 类似资料:
  • 我已经创建了一个服务代理。 代理(请求类型为)和实际服务(请求类型。)之间有一个处理器。 进入< code > process(Exchange Exchange)方法的交换体属于< code>TypeA。 我能够使用下面的代码行访问数据 现在,我想将此信息更改为。 我使用下面的代码添加主体。 我得到了 现在,我想使用调用真正的服务,它来自。 我尝试进入处理器,但出现以下异常 真正的Web服务没有

  • 我有一个简单的路线,看起来像这样: CXF 配置也非常简单: 此简单路由失败,出现以下异常 这是消息历史记录,表明它在

  • 我正在设置路由1中骆驼交换的属性。我正在尝试在拆分器内的第二条路由中更新该属性。但是在拆分器的第二次迭代中,我得到的是我在路由1中设置的原始值,而不是新的更新值。下面是我正在尝试的示例。。 豆子里面: 为什么不更新属性?甚至我也试着在标题中设置。同样的结果。非常感谢。

  • 脚本: CSV文件被发送到我的endpoint,Pojo将java数据和消息转换为我的一条路由,比如(“direct:consume”)路由,然后处理器处理该文件,处理消息并创建新的输出 问题: 文件只包含代码中断的一行 文件包含多行代码工作 尝试: 试图找到一种方法来确定交易记录的数量。getIn()。getBody() 阅读stackoverflow 阅读有关exchange的文档 在不知道记

  • 我有一条骆驼路线,如下所示。 bean方法顾名思义,分别将body设置为“Hello”和“World”。 我还设置了onException子句,如下所示: 假设,我将一条消息放在队列“开始”上,正文为“测试消息”。在第一个杜米豆中成功处理后,我在第二个杜米豆中抛出一个运行时异常。我希望看到实际的消息或(原始消息内容完好无损,即“测试消息”)被发送到我的死信队列。 但是,死信队列上的消息内容是“He

  • 在camel中,不是所有endpoint都支持INOUT,对吗 如果是,那么文档的哪一部分说明了哪个endpoint支持哪个,或者这是一种隐含的知识。 它需要来支持。 下面是我得出结论的代码示例。 我正在玩骆驼示例-jms-file,我将其修改为 队列1-- 然后我使用下面的代码发送msg到队列: 执行上述操作时给出以下响应: 如果我们观察执行输出,我们将看到收到的响应在从文件开始的路由完成之前打