简体   繁体   English

Apache骆驼,如何将消息从SOAP转移到JMS

[英]Apache camel, how to move message from SOAP to JMS

I'm learning Apache Camel framework, and try to build simple route where message is received from SOAP endpoint and is put into JMS queue (ActiveMQ). 我正在学习Apache Camel框架,并尝试构建简单的路由,该路由将从SOAP端点接收消息并将其放入JMS队列(ActiveMQ)。

I have the following route 我有以下路线

<route id="cxfToJMSRoute">
    <from uri="cxf:bean:endpoint" />
    <log message="test" />
    <wireTap uri="direct:logInfo" />
    <to uri="activemq:queue:api" />
</route>

And the endpoint and queue are defined as follows 端点和队列定义如下

<cxf:cxfEndpoint id="endpoint" address="http://localhost:1010/hello"
        serviceClass="net.webservicex.GlobalWeatherSoap" wsdlURL="META-INF/globalweather.wsdl" />

<bean id="activemq" class="org.apache.activemq.camel.component.ActiveMQComponent">
    <property name="brokerURL" value="tcp://127.0.0.1:61616"/>
</bean>

However, when I call the endpoint, the other service reading the message queue throws following error 但是,当我调用端点时,读取消息队列的其他服务抛出以下错误

org.apache.camel.RuntimeCamelException: Failed to extract body due to: javax.jms.JMSException: Failed to build body from content. Serializable class not available to broker. Reason: java.lang.ClassNotFoundException: Forbidden class org.apache.cxf.message.MessageContentsList! This class is not trusted to be serialized as ObjectMessage payload. Please take a look at http://activemq.apache.org/objectmessage.html for more information on how to configure trusted classes.. Message: ActiveMQObjectMessage {commandId = 8, responseRequired = true, messageId = ID:IT-L-R90HKRNH-64004-1511880368329-1:1:2:1:1, originalDestination = null, originalTransactionId = null, producerId = ID:IT-L-R90HKRNH-64004-1511880368329-1:1:2:1, destination = queue://api, transactionId = null, expiration = 1511880389430, timestamp = 1511880369430, arrival = 0, brokerInTime = 1511880369434, brokerOutTime = 1511880369495, correlationId = Camel-ID-IT-L-R90HKRNH-1511880338904-0-3, replyTo = temp-queue://ID:IT-L-R90HKRNH-64004-1511880368329-1:1:1, persistent = true, type = null, priority = 4, groupID = null, groupSequence = 0, targetConsumerId = null, compressed = false, userID = null, content = org.apache.activemq.util.ByteSequence@663a8b1b, marshalledProperties = org.apache.activemq.util.ByteSequence@504b2d9b, dataStructure = null, redeliveryCounter = 0, size = 1640, properties = {SOAPAction=http://www.webserviceX.NET/GetCitiesByCountry, CamelHttpCharacterEncoding=UTF-8, User_HYPHEN_Agent=Apache-HttpClient/4.1.1 (java 1.5), Host=127.0.0.1:1010, operationName=GetCitiesByCountry, operationNamespace=http://www.webserviceX.NET, breadcrumbId=ID-IT-L-R90HKRNH-1511880338904-0-1, Content_HYPHEN_Type=text/xml;charset=UTF-8, CamelHttpMethod=POST, accept_HYPHEN_encoding=gzip,deflate, connection=keep-alive, CamelHttpUri=/hello, CamelHttpPath=}, readOnlyProperties = true, readOnlyBody = true, droppable = false, jmsXGroupFirstForConsumer = false}
        at org.apache.camel.component.jms.JmsBinding.extractBodyFromJms(JmsBinding.java:160) ~[camel-jms-2.16.3.jar!/:2.16.3]
        at org.apache.camel.component.jms.JmsMessage.createBody(JmsMessage.java:236) ~[camel-jms-2.16.3.jar!/:2.16.3]
        at org.apache.camel.impl.MessageSupport.getBody(MessageSupport.java:54) ~[camel-core-2.20.1.jar!/:2.20.1]
        at org.apache.camel.builder.ExpressionBuilder$35.evaluate(ExpressionBuilder.java:905) ~[camel-core-2.20.1.jar!/:2.20.1]
        at org.apache.camel.support.ExpressionAdapter.evaluate(ExpressionAdapter.java:36) ~[camel-core-2.20.1.jar!/:2.20.1]
        at org.apache.camel.builder.ExpressionBuilder$76.evaluate(ExpressionBuilder.java:1836) ~[camel-core-2.20.1.jar!/:2.20.1]
        at org.apache.camel.support.ExpressionAdapter.evaluate(ExpressionAdapter.java:36) ~[camel-core-2.20.1.jar!/:2.20.1]
        at org.apache.camel.processor.LogProcessor.process(LogProcessor.java:64) ~[camel-core-2.20.1.jar!/:2.20.1]
        at org.apache.camel.processor.RedeliveryErrorHandler.process(RedeliveryErrorHandler.java:548) ~[camel-core-2.20.1.jar!/:2.20.1]
        at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:201) ~[camel-core-2.20.1.jar!/:2.20.1]
        at org.apache.camel.processor.Pipeline.process(Pipeline.java:138) ~[camel-core-2.20.1.jar!/:2.20.1]
        at org.apache.camel.processor.Pipeline.process(Pipeline.java:101) ~[camel-core-2.20.1.jar!/:2.20.1]
        at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:201) ~[camel-core-2.20.1.jar!/:2.20.1]
        at org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:97) ~[camel-core-2.20.1.jar!/:2.20.1]
        at org.apache.camel.component.jms.EndpointMessageListener.onMessage(EndpointMessageListener.java:112) ~[camel-jms-2.16.3.jar!/:2.16.3]
        at org.springframework.jms.listener.AbstractMessageListenerContainer.doInvokeListener(AbstractMessageListenerContainer.java:719) ~[spring-jms-4.3.12.RELEASE.jar!/:4.3.12.RELEASE]
        at org.springframework.jms.listener.AbstractMessageListenerContainer.invokeListener(AbstractMessageListenerContainer.java:679) ~[spring-jms-4.3.12.RELEASE.jar!/:4.3.12.RELEASE]
        at org.springframework.jms.listener.AbstractMessageListenerContainer.doExecuteListener(AbstractMessageListenerContainer.java:649) ~[spring-jms-4.3.12.RELEASE.jar!/:4.3.12.RELEASE]
        at org.springframework.jms.listener.AbstractPollingMessageListenerContainer.doReceiveAndExecute(AbstractPollingMessageListenerContainer.java:317) [spring-jms-4.3.12.RELEASE.jar!/:4.3.12.RELEASE]
        at org.springframework.jms.listener.AbstractPollingMessageListenerContainer.receiveAndExecute(AbstractPollingMessageListenerContainer.java:255) [spring-jms-4.3.12.RELEASE.jar!/:4.3.12.RELEASE]
        at org.springframework.jms.listener.DefaultMessageListenerContainer$AsyncMessageListenerInvoker.invokeListener(DefaultMessageListenerContainer.java:1166) [spring-jms-4.3.12.RELEASE.jar!/:4.3.12.RELEASE]
        at org.springframework.jms.listener.DefaultMessageListenerContainer$AsyncMessageListenerInvoker.executeOngoingLoop(DefaultMessageListenerContainer.java:1158) [spring-jms-4.3.12.RELEASE.jar!/:4.3.12.RELEASE]
        at org.springframework.jms.listener.DefaultMessageListenerContainer$AsyncMessageListenerInvoker.run(DefaultMessageListenerContainer.java:1055) [spring-jms-4.3.12.RELEASE.jar!/:4.3.12.RELEASE]
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [na:1.8.0_92]
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [na:1.8.0_92]
        at java.lang.Thread.run(Thread.java:745) [na:1.8.0_92]
Caused by: javax.jms.JMSException: Failed to build body from content. Serializable class not available to broker. Reason: java.lang.ClassNotFoundException: Forbidden class org.apache.cxf.message.MessageContentsList! This class is not trusted to be serialized as ObjectMessage payload. Please take a look at http://activemq.apache.org/objectmessage.html for more information on how to configure trusted classes.
        at org.apache.activemq.util.JMSExceptionSupport.create(JMSExceptionSupport.java:36) ~[activemq-client-5.14.5.jar!/:5.14.5]
        at org.apache.activemq.command.ActiveMQObjectMessage.getObject(ActiveMQObjectMessage.java:208) ~[activemq-client-5.14.5.jar!/:5.14.5]
        at org.apache.camel.component.jms.JmsBinding.extractBodyFromJms(JmsBinding.java:135) ~[camel-jms-2.16.3.jar!/:2.16.3]
        ... 25 common frames omitted
Caused by: java.lang.ClassNotFoundException: Forbidden class org.apache.cxf.message.MessageContentsList! This class is not trusted to be serialized as ObjectMessage payload. Please take a look at http://activemq.apache.org/objectmessage.html for more information on how to configure trusted classes.
        at org.apache.activemq.util.ClassLoadingAwareObjectInputStream.checkSecurity(ClassLoadingAwareObjectInputStream.java:112) ~[activemq-client-5.14.5.jar!/:5.14.5]
        at org.apache.activemq.util.ClassLoadingAwareObjectInputStream.resolveClass(ClassLoadingAwareObjectInputStream.java:57) ~[activemq-client-5.14.5.jar!/:5.14.5]
        at java.io.ObjectInputStream.readNonProxyDesc(ObjectInputStream.java:1620) ~[na:1.8.0_92]
        at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1521) ~[na:1.8.0_92]
        at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1781) ~[na:1.8.0_92]
        at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1353) ~[na:1.8.0_92]
        at java.io.ObjectInputStream.readObject(ObjectInputStream.java:373) ~[na:1.8.0_92]
        at org.apache.activemq.command.ActiveMQObjectMessage.getObject(ActiveMQObjectMessage.java:206) ~[activemq-client-5.14.5.jar!/:5.14.5]
        ... 26 common frames omitted

So do I have to convert the message to POJO myself before the JMS? 那么,我必须在JMS之前将消息本身转换为POJO吗? I'm completely new to Camel, but I got the impression Camel should handle type conversions automatically. 我是Camel的新手,但给我的印象是Camel应该自动处理类型转换。

You dont want to send Java objects to a JMS broker, so instead you can convert the message to be text based via by adding 您不想将Java对象发送到JMS代理,因此可以通过添加以下命令将消息转换为基于文本的消息:

<convertBodyTo type="String"/>
<to uri="activemq:queue:api" />

Before sending to the JMS broker. 发送到JMS代理之前。

You may need to add camel-jaxb on the classpath to allow Camel to automatic convert your POJO class to text as XML. 您可能需要在类路径上添加camel-jaxb,以允许Camel自动将POJO类转换为XML文本。 Or you can configure your SOAP endpoint to not use POJO type and just raw XML, then Camel can send that raw XML directly to JMS as text based. 或者,您可以将SOAP端点配置为不使用POJO类型而仅使用原始XML,然后Camel可以将该原始XML作为基于文本的形式直接发送到JMS。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM