Невозможно отправить сообщение во внешнее веб-приложение с помощью верблюда

Мое требование - получить сообщение об объекте json из веб-приложения и направить его (объект Json) в другое веб-приложение. Я использую верблюда для этой цели, что должно быть довольно простым процессом, который теперь дает мне бессонные ночи, мой верблюд маршрут указан ниже

                 <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 - это просто класс pojo, реализующий Serializable. Может кто-нибудь указать мне, где я ошибаюсь.

2 ответа

Если вы хотите отправить JSON, вы должны маршалировать свой объект раньше.

Вы можете сделать это так:

<dataFormats>
    <!-- here we define a Json data format with the id jack and that it should use the TestPojo as the class type when
         doing unmarshal. The unmarshalTypeName is optional, if not provided Camel will use a Map as the type -->
    <json id="jack" library="Jackson" unmarshalTypeName="org.apache.camel.component.jackson.TestPojo"/>
</dataFormats>

<camel:route>
     <camel:from uri="cxfrs://bean://lmrServer" />
        <camel:to uri="log:output?showAll=true"/>
             <setHeader headerName="CamelHttpMethod">
         <constant>POST</constant>
        </setHeader> 
     <camel:marshal ref="jack"/>
     <camel:to uri="cxfrs:http://localhost:8080/RESTfulExample/rest/message"/>
 </camel:route>

См. Документ для более подробной информации: документ Camel-JSON.

Тело биржи содержит объект

BodyType:org.apache.cxf.message.MessageContentsList, Body:[MemberApplication [name=xyz, organization=avc, nic=xyz, employeeId=5920]]

не должно ли это быть преобразовано в JSON перед отправкой

<camel:to uri="cxfrs:http://localhost:8080/RESTfulExample/rest/message"/>
Другие вопросы по тегам