在Active MQ中使用XML spring的JMS SOAP

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了在Active MQ中使用XML spring的JMS SOAP相关的知识,希望对你有一定的参考价值。

我试图构建一个驼峰路由,它将从一个队列中获取消息并以SOAP格式组合消息,并将相同的消息发布到托管在其他网络中的一个Web服务。但我无法做到这一点。

我的驼峰配置如下:

<?xml version="1.0" encoding="UTF-8"?>
<!--
       ~ Copyright 2011 FuseSource
         ~
           ~    Licensed under the Apache License, Version 2.0 (the "License");
             ~    you may not use this file except in compliance with the License.
               ~    You may obtain a copy of the License at
                 ~
                   ~        http://www.apache.org/licenses/LICENSE-2.0
                     ~
                       ~    Unless required by applicable law or agreed to in writing, software
                         ~    distributed under the License is distributed on an "AS IS" BASIS,
                           ~    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
                             ~    See the License for the specific language governing permissions and
                               ~    limitations under the License.
                               -->
<beans xmlns="http://www.springframework.org/schema/beans"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xmlns:cxf="http://camel.apache.org/schema/cxf"
      xmlns:jaxws="http://cxf.apache.org/jaxws"
      xmlns:soap="http://cxf.apache.org/bindings/soap"
      xsi:schemaLocation="
        http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans.xsd
        http://camel.apache.org/schema/cxf
        http://camel.apache.org/schema/cxf/camel-cxf.xsd
        http://camel.apache.org/schema/spring
        http://camel.apache.org/schema/spring/camel-spring.xsd
         ">



 <cxf:cxfEndpoint id="Nova-ws"
        address="http://10.47.32.20:8080/XMLServer/NovaNpsService"
        endpointName="c:NovaNpsServicePort"
        serviceName="c:NovaNpsService"
        wsdlURL="wsdl/NovaNpsService.wsdl"
        xmlns:c="http://soap.xmlserver.web.tollpost.no/">
        <cxf:binding>
            <soap:soapBinding version="1.2"/>
        </cxf:binding>
    </cxf:cxfEndpoint>

<camelContext id="ASTAtoNova" xmlns="http://camel.apache.org/schema/spring">
 <route id="ASTA_TO_NOVA_CXF" autoStartup="true" >

            <from uri="activemqNpsDK://CopyToNovaCXF.VirtualTopic.queue/nova.productionEventsAsta?jmsMessageType=Bytes"/>
            <log message="Putting one message on cxf webservice."/>
<doTry>
                                <doCatch>
                                <exception>java.lang.Exception</exception>
                                <rollback />
                                </doCatch>
<setBody><simple>&lt;soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:soap="http://soap.xmlserver.web.tollpost.no/"&gt;&lt;soapenv:Header/&gt;&lt;soapenv:Body&gt;&lt;soap:setItemDamage&gt;&lt;soap:userId&gt;${in.header.userId}&lt;/soap:userId&gt;&lt;soap:locationType&gt;${in.header.locationType}&lt;/soap:locationType&gt;&lt;soap:locationId&gt;${in.header.locationId}&lt;/soap:locationId&gt;&lt;soap:parcelId&gt;${in.header.itemId}&lt;/soap:parcelId&gt;&lt;soap:controlPoint&gt;${in.header.controlPoint}&lt;/soap:controlPoint&gt;&lt;soap:reasonCode&gt;${in.header.reasonCode}&lt;/soap:reasonCode&gt;&lt;soap:description&gt;${in.header.description}&lt;/soap:description&gt;&lt;soap:picture&gt;${body}&lt;/soap:picture&gt;&lt;/soap:setItemDamage&gt;&lt;/soapenv:Body&gt;&lt;/soapenv:Envelope&gt;</simple></setBody>
<to uri="cxf:bean:Nova-ws?dataFormat=PAYLOAD" />
</doTry>

           </route>


    </camelContext>



    <bean id="jmsConnectionFactoryNpsDK" class="org.apache.activemq.ActiveMQConnectionFactory">
                   <property name="brokerURL" value="failover:(tcp://10.127.83.43:15616,tcp://10.127.83.44:15616)?jms.copyMessageOnSend=false&amp;jms.sendTimeout=10000&amp;jms.closeTimeout=3000&amp;initialReconnectDelay=1000&amp;maxReconnectDelay=20000&amp;timeout=30000&amp;randomize=false&amp;useExponentialBackOff=false&amp;trackMessages=true" />
                    <property name="UserName" value="admin" />
                    <property name="Password" value="admin" />

                        </bean>

        <bean id="pooledConnectionFactoryNpsDK" class="org.apache.activemq.pool.PooledConnectionFactory" init-method="start" destroy-method="stop">
                        <property name="maxConnections" value="40" />
                                        <property name="connectionFactory" ref="jmsConnectionFactoryNpsDK" />
                                                </bean>

        <bean id="jmsConfigNpsDK" class="org.apache.camel.component.jms.JmsConfiguration">
                        <property name="connectionFactory" ref="pooledConnectionFactoryNpsDK" />
                                        <property name="concurrentConsumers" value="1" />
                                                </bean>

        <bean id="txmanagerNpsDK" class="org.springframework.jms.connection.JmsTransactionManager">
                        <property name="connectionFactory" ref="pooledConnectionFactoryNpsDK" />
                                </bean>

        <bean id="activemqNpsDK" class="org.apache.activemq.camel.component.ActiveMQComponent">
                <property name="configuration" ref="jmsConfigNpsDK" />
                <property name="transacted" value="true" />
                <property name="transactionManager" ref="txmanagerNpsDK" />
                <property name="cacheLevelName" value="CACHE_CONSUMER" />
        </bean>

</beans>

如果有人可以提供帮助,那将会非常有帮助。

在日志中我可以看到以下异常

java.lang.IllegalArgumentException: The PayLoad elements cannot fit with the message parts of the BindingOperation. Please check the BindingOperation and PayLoadMessage.
        at org.apache.camel.component.cxf.CxfEndpoint$CamelCxfClientImpl.setParameters(CxfEndpoint.java:977)[250:org.apache.camel.camel-cxf:2.12.0.redhat-611424]
        at org.apache.cxf.endpoint.ClientImpl.doInvoke(ClientImpl.java:521)[206:org.apache.cxf.cxf-api:2.7.0.redhat-611423]
        at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:467)[206:org.apache.cxf.cxf-api:2.7.0.redhat-611423]
        at org.apache.camel.component.cxf.CxfProducer.process(CxfProducer.java:112)[250:org.apache.camel.camel-cxf:2.12.0.redhat-611424]
        at org.apache.camel.processor.SendProcessor.process(SendProcessor.java:110)[156:org.apache.camel.camel-core:2.12.0.redhat-611424]
        at org.apache.camel.management.InstrumentationProcessor.process(InstrumentationProcessor.java:72)[156:org.apache.camel.camel-core:2.12.0.redhat-611424]
        at org.apache.camel.processor.RedeliveryErrorHandler.process(RedeliveryErrorHandler.java:398)[156:org.apache.camel.camel-core:2.12.0.redhat-611424]
        at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:191)[156:org.apache.camel.camel-core:2.12.0.redhat-611424]
        at org.apache.camel.processor.Pipeline.process(Pipeline.java:118)[156:org.apache.camel.camel-core:2.12.0.redhat-611424]
        at org.apache.camel.processor.Pipeline.process(Pipeline.java:80)[156:org.apache.camel.camel-core:2.12.0.redhat-611424]
        at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:191)[156:org.apache.camel.camel-core:2.12.0.redhat-611424]
        at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:105)[156:org.apache.camel.camel-core:2.12.0.redhat-611424]
        at org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:87)[156:org.apache.camel.camel-core:2.12.0.redhat-611424]
        at org.apache.camel.component.jms.EndpointMessageListener.onMessage(EndpointMessageListener.java:103)[158:org.apache.camel.camel-jms:2.12.0.redhat-611423]
        at org.springframework.jms.listener.AbstractMessageListenerContainer.doInvokeListener(AbstractMessageListenerContainer.java:562)[151:org.apache.servicemix.bundles.spring-jms:3.2.12.RELEASE_1]
        at org.springframework.jms.listener.AbstractMessageListenerContainer.invokeListener(AbstractMessageListenerContainer.java:500)[151:org.apache.servicemix.bundles.spring-jms:3.2.12.RELEASE_1]
        at org.springframework.jms.listener.AbstractMessageListenerContainer.doExecuteListener(AbstractMessageListenerContainer.java:468)[151:org.apache.servicemix.bundles.spring-jms:3.2.12.RELEASE_1]
        at org.springframework.jms.listener.AbstractPollingMessageListenerContainer.doReceiveAndExecute(AbstractPollingMessageListenerContainer.java:325)[151:org.apache.servicemix.bundles.spring-jms:3.2.12.RELEASE_1]
        at org.springframework.jms.listener.AbstractPollingMessageListenerContainer.receiveAndExecute(AbstractPollingMessageListenerContainer.java:243)[151:org.apache.servicemix.bundles.spring-jms:3.2.12.RELEASE_1]
        at org.springframework.jms.listener.DefaultMessageListenerContainer$AsyncMessageListenerInvoker.invokeListener(DefaultMessageListenerContainer.java:1101)[151:org.apache.servicemix.bundles.spring-jms:3.2.12.RELEASE_1]
        at org.springframework.jms.listener.DefaultMessageListenerContainer$AsyncMessageListenerInvoker.executeOngoingLoop(DefaultMessageListenerContainer.java:1093)[151:org.apache.servicemix.bundles.spring-jms:3.2.12.RELEASE_1]
        at org.springframework.jms.listener.DefaultMessageListenerContainer$AsyncMessageListenerInvoker.run(DefaultMessageListenerContainer.java:990)[151:org.apache.servicemix.bundles.spring-jms:3.2.12.RELEASE_1]
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)[:1.7.0_51]
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)[:1.7.0_51]
        at java.lang.Thread.run(Thread.java:744)[:1.7.0_51]
2018-03-05 16:31:13,684 WARN  [org.apache.camel.component.jms.EndpointMessageListener] (Camel (ASTAtoNova) thread #70 - JmsConsumer[CopyToNovaCXF.VirtualTopic.queue/nova.productionEventsAsta]) | Execution of JMS message listener failed. Caused by: [org.apache.camel.RuntimeCamelException - java.lang.IllegalArgumentException: The PayLoad elements cannot fit with the message parts of the BindingOperation. Please check the BindingOperation and PayLoadMessage.]
org.apache.camel.RuntimeCamelException: java.lang.IllegalArgumentException: The PayLoad elements cannot fit with the message parts of the BindingOperation. Please check the BindingOperation and PayLoadMessage.
        at org.apache.camel.util.ObjectHelper.wrapRuntimeCamelException(ObjectHelper.java:1363)[156:org.apache.camel.camel-core:2.12.0.redhat-611424]
        at org.apache.camel.component.jms.EndpointMessageListener$EndpointMessageListenerAsyncCallback.done(EndpointMessageListener.java:186)[158:org.apache.camel.camel-jms:2.12.0.redhat-611423]
        at org.apache.camel.component.jms.EndpointMessageListener.onMessage(EndpointMessageListener.java:107)[158:org.apache.camel.camel-jms:2.12.0.redhat-611423]
        at org.springframework.jms.listener.AbstractMessageListenerContainer.doInvokeListener(AbstractMessageListenerContainer.java:562)[151:org.apache.servicemix.bundles.spring-jms:3.2.12.RELEASE_1]
        at org.springframework.jms.listener.AbstractMessageListenerContainer.invokeListener(AbstractMessageListenerContainer.java:500)[151:org.apache.servicemix.bundles.spring-jms:3.2.12.RELEASE_1]
        at org.springframework.jms.listener.AbstractMessageListenerContainer.doExecuteListener(AbstractMessageListenerContainer.java:468)[151:org.apache.servicemix.bundles.spring-jms:3.2.12.RELEASE_1]
        at org.springframework.jms.listener.AbstractPollingMessageListenerContainer.doReceiveAndExecute(AbstractPollingMessageListenerContainer.java:325)[151:org.apache.servicemix.bundles.spring-jms:3.2.12.RELEASE_1]
        at org.springframework.jms.listener.AbstractPollingMessageListenerContainer.receiveAndExecute(AbstractPollingMessageListenerContainer.java:243)[151:org.apache.servicemix.bundles.spring-jms:3.2.12.RELEASE_1]
        at org.springframework.jms.listener.DefaultMessageListenerContainer$AsyncMessageListenerInvoker.invokeListener(DefaultMessageListenerContainer.java:1101)[151:org.apache.servicemix.bundles.spring-jms:3.2.12.RELEASE_1]
        at org.springframework.jms.listener.DefaultMessageListenerContainer$AsyncMessageListenerInvoker.executeOngoingLoop(DefaultMessageListenerContainer.java:1093)[151:org.apache.servicemix.bundles.spring-jms:3.2.12.RELEASE_1]
        at org.springframework.jms.listener.DefaultMessageListenerContainer$AsyncMessageListenerInvoker.run(DefaultMessageListenerContainer.java:990)[151:org.apache.servicemix.bundles.spring-jms:3.2.12.RELEASE_1]
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)[:1.7.0_51]
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)[:1.7.0_51]
        at java.lang.Thread.run(Thread.java:744)[:1.7.0_51]
Caused by: java.lang.IllegalArgumentException: The PayLoad elements cannot fit with the message parts of the BindingOperation. Please check the BindingOperation and PayLoadMessage.
        at org.apache.camel.component.cxf.CxfEndpoint$CamelCxfClientImpl.setParameters(CxfEndpoint.java:977)[250:org.apache.camel.camel-cxf:2.12.0.redhat-611424]
        at org.apache.cxf.endpoint.ClientImpl.doInvoke(ClientImpl.java:521)[206:org.apache.cxf.cxf-api:2.7.0.redhat-611423]
        at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:467)[206:org.apache.cxf.cxf-api:2.7.0.redhat-611423]
        at org.apache.camel.component.cxf.CxfProducer.process(CxfProducer.java:112)[250:org.apache.camel.camel-cxf:2.12.0.redhat-611424]
        at org.apache.camel.processor.SendProcessor.process(SendProcessor.java:110)[156:org.apache.camel.camel-core:2.12.0.redhat-611424]
        at org.apache.camel.management.InstrumentationProcessor.process(InstrumentationProcessor.java:72)[156:org.apache.camel.camel-core:2.12.0.redhat-611424]
        at org.apache.camel.processor.RedeliveryErrorHandler.process(RedeliveryErrorHandler.java:398)[156:org.apache.camel.camel-core:2.12.0.redhat-611424]
        at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:191)[156:org.apache.camel.camel-core:2.12.0.redhat-611424]
        at org.apache.camel.processor.Pipeline.process(Pipeline.java:118)[156:org.apache.camel.camel-core:2.12.0.redhat-611424]
        at org.apache.camel.processor.Pipeline.process(Pipeline.java:80)[156:org.apache.camel.camel-core:2.12.0.redhat-611424]
        at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:191)[156:org.apache.camel.camel-core:2.12.0.redhat-611424]
        at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:105)[156:org.apache.camel.camel-core:2.12.0.redhat-611424]
        at org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:87)[156:org.apache.camel.camel-core:2.12.0.redhat-611424]
        at org.apache.camel.component.jms.EndpointMessageListener.onMessage(EndpointMessageListener.java:103)[158:org.apache.camel.camel-jms:2.12.0.redhat-611423]
        ... 11 more
答案

要将SOAP消息发送到CXF端点,您不能像以前那样提供soap:Envelope String。 CXF端点的主体是不同的。 CXF将基于WSDL将Body自行封装到Envelope中。

也许检查一下:

CXF-How to get and set SOAPheaders in PAYLOAD mode

当然还有更多文档..

但重点是:

Camel消息Body for CXF端点不是信封String。

改变2.0 ...我们只是在图层下使用常见的Camel DefaultMessageImpl。 Message.getBody()将返回一个org.apache.camel.component.cxf.CxfPayload对象,该对象具有SOAP消息头和Body元素的getter。此更改允许将本机CXF消息与Camel消息解耦。

因此,您必须将您的主体设置为在PAYLOAD模式下通过CXF端点发送为CxfPayload对象,其中包含适当的部分。

当然你可以发送soap:信封字符串,而不是通过CXF Endpoint组件,但只是常规的HTTP POST操作 - 当然不是好主意:-)

以上是关于在Active MQ中使用XML spring的JMS SOAP的主要内容,如果未能解决你的问题,请参考以下文章

JMS进阶-Spring整合Active MQ

JMS 之 Active MQ的安全机制

JMS 之 Active MQ 启动嵌入式Broke

JMS 之 Active MQ 启动嵌入式Broke

JMS 之 Active MQ 的消息传输

带有 Active-MQ 的 Mule 发布/订阅模型。如何在 Active-MQ JMS 中的消息到达时以异步方式调用 tomcat-consumers