我的要求是从 web 应用程序接收一个 json 对象的消息并将其(Json 对象)路由到另一个 web 应用程序,我为此目的使用骆驼,现在应该是一个相当简单的过程让我不眠之夜,我的骆驼路线如下
<camel:route>
<camel:from uri="cxfrs://bean://lmrServer" />
<camel:to uri="log:output?showAll=true"/>
<setHeader headerName="CamelHttpMethod">
<constant>POST</constant>
</setHeader>
<camel:to uri="cxfrs:http://localhost:8080/RESTfulExample/rest/message"/>
现在下面是我的错误堆栈,我可以在其中看到消息正文中的 json 对象,请让我知道我错在哪里,这将有很大帮助..提前谢谢..
[ qtp177816476-20] output INFO Exchange[I
d:ID-UKCNU1161RK1-53103-1382261880815-0-1, ExchangePattern:InOut, Properties:{Ca
melToEndpoint=log://output?showAll=true, CamelCreatedTimestamp=Sun Oct 20 10:38:
32 BST 2013}, Headers:{breadcrumbId=ID-UKCNU1161RK1-53103-1382261880815-0-2, Cam
elHttpPath=/lmr/register, CamelAcceptContentType=*/*, CamelCxfRsOperationResourc
eInfoStack=[org.apache.cxf.jaxrs.model.MethodInvocationInfo@7bfd523d], CamelHttp
Uri=/jkdlrn/lmr/register, connection=keep-alive, content-type=application/json,
Host=localhost:8081, Content-Length=67, CamelCxfRsResponseGenericType=void, Came
lHttpCharacterEncoding=ISO-8859-1, CamelCxfMessage=org.apache.cxf.message.XMLMes
sage@c6298812, CamelHttpMethod=POST, User-Agent=Apache-HttpClient/4.2.5 (java 1.
5), CamelCxfRsResponseClass=void, operationName=register}, BodyType:org.apache.c
xf.message.MessageContentsList, Body:[MemberApplication [name=xyz, organization=
avc, nic=xyz, employeeId=5920]], Out: null]
[ qtp177816476-20] DefaultErrorHandler ERROR Failed del
ivery for (MessageId: ID-UKCNU1161RK1-53103-1382261880815-0-2 on ExchangeId: ID-
UKCNU1161RK1-53103-1382261880815-0-1). Exhausted after delivery attempt: 1 caugh
t: org.apache.camel.CamelExecutionException: Exception occurred during execution
on the exchange: Exchange[Message: [MemberApplication [name=xyz, organization=a
vc, nic=xyz, employeeId=5920]]]
org.apache.camel.CamelExecutionException: Exception occurred during execution on
the exchange: Exchange[Message: [MemberApplication [name=xyz, organization=avc,
nic=xyz, employeeId=5920]]]
at org.apache.camel.util.ObjectHelper.wrapCamelExecutionException(Object
Helper.java:1287)[camel-core-2.10.3.jar:2.10.3]
at org.apache.camel.impl.DefaultExchange.setException(DefaultExchange.ja
va:282)[camel-core-2.10.3.jar:2.10.3]
at org.apache.camel.util.AsyncProcessorConverterHelper$ProcessorToAsyncP
rocessorBridge.process(AsyncProcessorConverterHelper.java:64)[camel-core-2.10.3.
jar:2.10.3]
at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelp
er.java:73)[camel-core-2.10.3.jar:2.10.3]
at org.apache.camel.processor.SendProcessor$2.doInAsyncProducer(SendProc
essor.java:122)[camel-core-2.10.3.jar:2.10.3]
at org.apache.camel.impl.ProducerCache.doInAsyncProducer(ProducerCache.j
ava:298)[camel-core-2.10.3.jar:2.10.3]
at org.apache.camel.processor.SendProcessor.process(SendProcessor.java:1
17)[camel-core-2.10.3.jar:2.10.3]
at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelp
er.java:73)[camel-core-2.10.3.jar:2.10.3]
at org.apache.camel.processor.DelegateAsyncProcessor.processNext(Delegat
eAsyncProcessor.java:99)[camel-core-2.10.3.jar:2.10.3]
at org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsy
ncProcessor.java:90)[camel-core-2.10.3.jar:2.10.3]
at org.apache.camel.management.InstrumentationProcessor.process(Instrume
ntationProcessor.java:73)[camel-core-2.10.3.jar:2.10.3]
at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelp
er.java:73)[camel-core-2.10.3.jar:2.10.3]
at org.apache.camel.processor.DelegateAsyncProcessor.processNext(Delegat
eAsyncProcessor.java:99)[camel-core-2.10.3.jar:2.10.3]
at org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsy
ncProcessor.java:90)[camel-core-2.10.3.jar:2.10.3]
at org.apache.camel.processor.interceptor.TraceInterceptor.process(Trace
Interceptor.java:91)[camel-core-2.10.3.jar:2.10.3]
at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelp
er.java:73)[camel-core-2.10.3.jar:2.10.3]
at org.apache.camel.processor.RedeliveryErrorHandler.processErrorHandler
(RedeliveryErrorHandler.java:334)[camel-core-2.10.3.jar:2.10.3]
at org.apache.camel.processor.RedeliveryErrorHandler.process(RedeliveryE
rrorHandler.java:220)[camel-core-2.10.3.jar:2.10.3]
at org.apache.camel.processor.RouteContextProcessor.processNext(RouteCon
textProcessor.java:45)[camel-core-2.10.3.jar:2.10.3]
at org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsy
ncProcessor.java:90)[camel-core-2.10.3.jar:2.10.3]
at org.apache.camel.processor.interceptor.DefaultChannel.process(Default
Channel.java:303)[camel-core-2.10.3.jar:2.10.3]
at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelp
er.java:73)[camel-core-2.10.3.jar:2.10.3]
at org.apache.camel.processor.Pipeline.process(Pipeline.java:117)[camel-
core-2.10.3.jar:2.10.3]
at org.apache.camel.processor.Pipeline.process(Pipeline.java:80)[camel-c
ore-2.10.3.jar:2.10.3]
at org.apache.camel.processor.RouteContextProcessor.processNext(RouteCon
textProcessor.java:45)[camel-core-2.10.3.jar:2.10.3]
at org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsy
ncProcessor.java:90)[camel-core-2.10.3.jar:2.10.3]
at org.apache.camel.processor.UnitOfWorkProcessor.processAsync(UnitOfWor
kProcessor.java:150)[camel-core-2.10.3.jar:2.10.3]
at org.apache.camel.processor.UnitOfWorkProcessor.process(UnitOfWorkProc
essor.java:117)[camel-core-2.10.3.jar:2.10.3]
at org.apache.camel.processor.RouteInflightRepositoryProcessor.processNe
xt(RouteInflightRepositoryProcessor.java:48)[camel-core-2.10.3.jar:2.10.3]
at org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsy
ncProcessor.java:90)[camel-core-2.10.3.jar:2.10.3]
at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelp
er.java:73)[camel-core-2.10.3.jar:2.10.3]
at org.apache.camel.processor.DelegateAsyncProcessor.processNext(Delegat
eAsyncProcessor.java:99)[camel-core-2.10.3.jar:2.10.3]
at org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsy
ncProcessor.java:90)[camel-core-2.10.3.jar:2.10.3]
at org.apache.camel.management.InstrumentationProcessor.process(Instrume
ntationProcessor.java:73)[camel-core-2.10.3.jar:2.10.3]
at org.apache.camel.component.cxf.jaxrs.CxfRsInvoker.asyncInvoke(CxfRsIn
voker.java:87)[camel-cxf-2.10.3.jar:2.10.3]
at org.apache.camel.component.cxf.jaxrs.CxfRsInvoker.performInvocation(C
xfRsInvoker.java:57)[camel-cxf-2.10.3.jar:2.10.3]
at org.apache.cxf.service.invoker.AbstractInvoker.invoke(AbstractInvoker
.java:89)[cxf-rt-core-2.5.0.jar:2.5.0]
at org.apache.cxf.jaxrs.JAXRSInvoker.invoke(JAXRSInvoker.java:166)[cxf-r
t-frontend-jaxrs-2.5.0.jar:2.5.0]
at org.apache.cxf.jaxrs.JAXRSInvoker.invoke(JAXRSInvoker.java:93)[cxf-rt
-frontend-jaxrs-2.5.0.jar:2.5.0]
at org.apache.cxf.interceptor.ServiceInvokerInterceptor$1.run(ServiceInv
okerInterceptor.java:58)[cxf-rt-core-2.5.0.jar:2.5.0]
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:47
1)[:1.7.0_25]
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)[:1
.7.0_25]
at java.util.concurrent.FutureTask.run(FutureTask.java:166)[:1.7.0_25]
at org.apache.cxf.workqueue.SynchronousExecutor.execute(SynchronousExecu
tor.java:37)[cxf-rt-core-2.5.0.jar:2.5.0]
at org.apache.cxf.interceptor.ServiceInvokerInterceptor.handleMessage(Se
rviceInvokerInterceptor.java:106)[cxf-rt-core-2.5.0.jar:2.5.0]
at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseIntercept
orChain.java:263)[cxf-api-2.5.0.jar:2.5.0]
at org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainIniti
ationObserver.java:123)[cxf-rt-core-2.5.0.jar:2.5.0]
at org.apache.cxf.transport.http_jetty.JettyHTTPDestination.serviceReque
st(JettyHTTPDestination.java:323)[cxf-rt-transports-http-jetty-2.5.0.jar:2.5.0]
at org.apache.cxf.transport.http_jetty.JettyHTTPDestination.doService(Je
ttyHTTPDestination.java:289)[cxf-rt-transports-http-jetty-2.5.0.jar:2.5.0]
at org.apache.cxf.transport.http_jetty.JettyHTTPHandler.handle(JettyHTTP
Handler.java:72)[cxf-rt-transports-http-jetty-2.5.0.jar:2.5.0]
at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandl
er.java:943)[jetty-server-7.5.4.v20111024.jar:7.5.4.v20111024]
at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandle
r.java:879)[jetty-server-7.5.4.v20111024.jar:7.5.4.v20111024]
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.j
ava:117)[jetty-server-7.5.4.v20111024.jar:7.5.4.v20111024]
at org.eclipse.jetty.server.handler.ContextHandlerCollection.handle(Cont
extHandlerCollection.java:250)[jetty-server-7.5.4.v20111024.jar:7.5.4.v20111024]
at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper
.java:110)[jetty-server-7.5.4.v20111024.jar:7.5.4.v20111024]
at org.eclipse.jetty.server.Server.handle(Server.java:349)[jetty-server-
7.5.4.v20111024.jar:7.5.4.v20111024]
at org.eclipse.jetty.server.HttpConnection.handleRequest(HttpConnection.
java:441)[jetty-server-7.5.4.v20111024.jar:7.5.4.v20111024]
at org.eclipse.jetty.server.HttpConnection$RequestHandler.content(HttpCo
nnection.java:936)[jetty-server-7.5.4.v20111024.jar:7.5.4.v20111024]
at org.eclipse.jetty.http.HttpParser.parseNext(HttpParser.java:801)[jett
y-http-7.5.4.v20111024.jar:7.5.4.v20111024]
at org.eclipse.jetty.http.HttpParser.parseAvailable(HttpParser.java:224)
[jetty-http-7.5.4.v20111024.jar:7.5.4.v20111024]
at org.eclipse.jetty.server.AsyncHttpConnection.handle(AsyncHttpConnecti
on.java:51)[jetty-server-7.5.4.v20111024.jar:7.5.4.v20111024]
at org.eclipse.jetty.io.nio.SelectChannelEndPoint.handle(SelectChannelEn
dPoint.java:586)[jetty-io-7.5.4.v20111024.jar:7.5.4.v20111024]
at org.eclipse.jetty.io.nio.SelectChannelEndPoint$1.run(SelectChannelEnd
Point.java:44)[jetty-io-7.5.4.v20111024.jar:7.5.4.v20111024]
at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPoo
l.java:598)[jetty-util-7.5.4.v20111024.jar:7.5.4.v20111024]
at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool
.java:533)[jetty-util-7.5.4.v20111024.jar:7.5.4.v20111024]
at java.lang.Thread.run(Thread.java:724)[:1.7.0_25]
[ qtp177816476-20] WebApplicationExceptionMapper WARN WebApplica
tionException has been caught : org/apache/cxf/service/factory/ReflectionService
FactoryBean
我有一种感觉,这是因为罐子,所以下面是我的 pom.xml
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<camel.version>2.10.3</camel.version>
<json.version>1.8.5</json.version>
<cxf.version>2.5.0</cxf.version>
</properties>
<dependencies>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-core</artifactId>
<version>${camel.version}</version>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-spring</artifactId>
<version>${camel.version}</version>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-jetty</artifactId>
<version>${camel.version}</version>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-cxf</artifactId>
<version>${camel.version}</version>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-script</artifactId>
<version>${camel.version}</version>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-jaxb</artifactId>
<version>${camel.version}</version>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-cache</artifactId>
<version>2.12.1</version>
</dependency>
<!-- JSON -->
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-mapper-asl</artifactId>
<version>${json.version}</version>
</dependency>
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-jaxrs</artifactId>
<version>${json.version}</version>
</dependency>
<!-- CXF -->
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-frontend-jaxrs</artifactId>
<version>${cxf.version}</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-transports-http-jetty</artifactId>
<version>${cxf.version}</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-ws-policy</artifactId>
<version>${cxf.version}</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-ws-addr</artifactId>
<version>${cxf.version}</version>
</dependency>
<!-- logging -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.6.6</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.6.6</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
<!-- testing -->
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-test-spring</artifactId>
<version>2.10.3</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<defaultGoal>install</defaultGoal>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.5.1</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.4.3</version>
<configuration>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<!-- allows the route to be ran via 'mvn camel:run' -->
<plugin>
<groupId>org.apache.camel</groupId>
<artifactId>camel-maven-plugin</artifactId>
<version>2.10.3</version>
</plugin>
<!-- -jetty -->
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>${camel.version}</version>
<configuration>
<connectors>
<connector implementation="org.eclipse.jetty.server.nio.SelectChannelConnector">
<port>8081</port>
</connector>
</connectors>
<stopPort>18080</stopPort>
</configuration>
</plugin>
</plugins>
</build>
</project>
好的,@Pith 现在我做了你建议的更改,现在它抛出以下错误
el 2.10.3 (CamelContext: camel-1) started in 0.498 seconds
[ qtp1431523121-14] output INFO Exchange[E
xchangePattern:InOut, BodyType:org.apache.cxf.message.MessageContentsList, Body:
[{"name":"xyz", "organization":"avc", "nic":"xyz", "employeeId":"5920"}]]
[ qtp1431523121-14] BusApplicationContext INFO Refreshing
org.apache.cxf.bus.spring.BusApplicationContext@1ccffe62: startup date [Tue Oct
22 15:46:42 BST 2013]; parent: org.springframework.context.support.ClassPathXml
ApplicationContext@4642ebd
[ qtp1431523121-14] DefaultErrorHandler ERROR Failed del
ivery for (MessageId: ID-UKCNU1161RK1-52360-1382453193775-0-2 on ExchangeId: ID-
UKCNU1161RK1-52360-1382453193775-0-1). Exhausted after delivery attempt: 1 caugh
t: java.lang.ClassCastException: java.util.ArrayList cannot be cast to org.apach
e.cxf.message.MessageContentsList
java.lang.ClassCastException: java.util.ArrayList cannot be cast to org.apache.c
xf.message.MessageContentsList
at org.apache.camel.component.cxf.jaxrs.DefaultCxfRsBinding.bindCamelMes
sageBodyToRequestBody(DefaultCxfRsBinding.java:166)[camel-cxf-2.10.3.jar:2.10.3]
at org.apache.camel.component.cxf.jaxrs.CxfRsProducer.invokeHttpClient(C
xfRsProducer.java:143)[camel-cxf-2.10.3.jar:2.10.3]
at org.apache.camel.component.cxf.jaxrs.CxfRsProducer.process(CxfRsProdu
cer.java:87)[camel-cxf-2.10.3.jar:2.10.3]
at org.apache.camel.util.AsyncProcessorConverterHelper$ProcessorToAsyncP
rocessorBridge.process(AsyncProcessorConverterHelper.java:61)[camel-core-2.10.3.
jar:2.10.3]
at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelp
er.java:73)[camel-core-2.10.3.jar:2.10.3]
at org.apache.camel.processor.SendProcessor$2.doInAsyncProducer(SendProc
essor.java:122)[camel-core-2.10.3.jar:2.10.3]
at org.apache.camel.impl.ProducerCache.doInAsyncProducer(ProducerCache.j
ava:298)[camel-core-2.10.3.jar:2.10.3]
at org.apache.camel.processor.SendProcessor.process(SendProcessor.java:1
17)[camel-core-2.10.3.jar:2.10.3]
at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelp
er.java:73)[camel-core-2.10.3.jar:2.10.3]
at org.apache.camel.processor.DelegateAsyncProcessor.processNext(Delegat
我在骆驼中所做的更改-上下文如下
<dataFormats>
<json library="Jackson" unmarshalTypeName="org.payment.camel.example.MemberApplication" id="jack"/>
</dataFormats>
MemberApplication 只是一个实现 Serializable 的 pojo 类。有人可以指出我错在哪里。