Mule ESB:无法使用流有效负载复制消息
Posted
技术标签:
【中文标题】Mule ESB:无法使用流有效负载复制消息【英文标题】:Mule ESB : Cannot copy message with a stream payload 【发布时间】:2012-03-09 05:54:19 【问题描述】:我有一个 Mule 应用程序,我在其中向多个 Web 服务发送请求并聚合我得到的响应列表,其想法是通过从处理列表的 CustomJavaClass 返回它来获取列表的第一个响应:
return responses.get(0);
如果我尝试通过浏览器访问 WSDL,我能够访问它,返回的 WSDL 看起来像它应该的样子。但我尝试通过 SoapUi 发送消息,但出现以下异常:
Exception stack is:
1. Cannot copy message with a stream payload. Payload type is "org.apache.commons.httpclient.ContentLengthInputStream". Message payload is of type: ContentLengthInputStream (org.mule.api.MessagingException)
org.mule.routing.outbound.AbstractSequenceRouter:73 (http://www.mulesoft.org/docs/site/current3/apidocs/org/mule/api/MessagingException.html)
--------------------------------------------------------------------------------
Root Exception stack trace:
org.mule.api.MessagingException: Cannot copy message with a stream payload. Payload type is "org.apache.commons.httpclient.ContentLengthInputStream". Message payload is of type: ContentLengthInputStream
at org.mule.routing.outbound.AbstractSequenceRouter.route(AbstractSequenceRouter.java:73)
at org.mule.routing.outbound.AbstractOutboundRouter$1.doInTransaction(AbstractOutboundRouter.java:102)
at org.mule.routing.outbound.AbstractOutboundRouter$1.doInTransaction(AbstractOutboundRouter.java:99)
+ 3 more (set debug level logging or '-Dmule.verbose.exceptions=true' for everything)
SOAPUi 异常:
Failed to route event via endpoint: org.mule.api.processor.MessageProcessors$LifecyleAwareMessageProcessorWrapper@ceb6dd. Message payload is of type: ContentLengthInputStream
我目前的配置:
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:mulexml="http://www.mulesoft.org/schema/mule/xml" xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation" xmlns:spring="http://www.springframework.org/schema/beans" xmlns:core="http://www.mulesoft.org/schema/mule/core" xmlns:cxf="http://www.mulesoft.org/schema/mule/cxf" xmlns:tcp="http://www.mulesoft.org/schema/mule/tcp" xmlns:jms="http://www.mulesoft.org/schema/mule/jms" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="CE-3.2.1" xsi:schemaLocation="
http://www.mulesoft.org/schema/mule/xml http://www.mulesoft.org/schema/mule/xml/current/mule-xml.xsd
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/cxf http://www.mulesoft.org/schema/mule/cxf/current/mule-cxf.xsd
http://www.mulesoft.org/schema/mule/tcp http://www.mulesoft.org/schema/mule/tcp/current/mule-tcp.xsd
http://www.mulesoft.org/schema/mule/jms http://www.mulesoft.org/schema/mule/jms/current/mule-jms.xsd ">
<flow name="flows1Flow1" doc:name="flows1Flow1">
<http:inbound-endpoint exchange-pattern="request-response" address="http://localhost:4433/miniwebservice" encoding="UTF-8" mimeType="text/xml" doc:name="HTTP"/>
<logger level="INFO" category="ddo" doc:name="Logger"/>
<all doc:name="All">
<processor-chain>
<message-properties-transformer encoding="UTF-8" mimeType="text/xml" doc:name="Message Properties">
<add-message-property key="http.method" value="#[header:INBOUND:http.method]"/>
</message-properties-transformer>
<http:outbound-endpoint exchange-pattern="request-response" address="http://localhost:4435/miniwebservice#[header:INBOUND:http.request]" encoding="UTF-8" mimeType="text/xml" doc:name="HTTP"/>
<mulexml:xslt-transformer mimeType="text/xml" maxIdleTransformers="2" maxActiveTransformers="5" xsl-file="C:\Users\kiesa\Desktop\XSLReplace.xsl" doc:name="XSLT"/>
</processor-chain>
<processor-chain>
<message-properties-transformer encoding="UTF-8" mimeType="text/xml" doc:name="Message Properties">
<add-message-property key="http.method" value="#[header:INBOUND:http.method]"/>
</message-properties-transformer>
<http:outbound-endpoint exchange-pattern="request-response" address="http://localhost:4434/miniwebservice#[header:INBOUND:http.request]" encoding="UTF-8" mimeType="text/xml" doc:name="HTTP"/>
<mulexml:xslt-transformer mimeType="text/xml" maxIdleTransformers="2" maxActiveTransformers="5" xsl-file="C:\Users\kiesa\Desktop\XSLReplace2.xsl" doc:name="XSLT"/>
</processor-chain>
</all>
<mulexml:xml-to-object-transformer doc:name="XML to Object"/>
<component class="CustomJavaClass" doc:name="Java"/>
<byte-array-to-string-transformer ignoreBadInput="true" encoding="UTF-8" mimeType="text/xml" doc:name="Byte Array to String"/>
</flow>
</mule>
【问题讨论】:
【参考方案1】:获取 WSDL 是可行的,因为 GET 请求不携带任何负载。但是当你尝试调用一个 SOAP 方法时,POST 负载是一个 InputStream,当然不能多次分派。
因此:用 a 序列化 HTTP 输入流:
<object-to-byte-array-transformer />
就在 http:inbound-endpoint 之后。
【讨论】:
如何解决与上述类似的问题:我正在使用 Mule 4.2.1 Anypoint Studio 7.3.4:Payload can be transformed by using an <object-to-byte-array-transformer> in order to be able to copy the message. Payload type is "org.mule.runtime.core.internal.streaming.bytes.ManagedCursorStreamProvider"
以上是关于Mule ESB:无法使用流有效负载复制消息的主要内容,如果未能解决你的问题,请参考以下文章
Mule ExpressionRuntimeException 消息有效负载的类型为:LinkedList
重新传递 Mule ESB 处理的失败的 activemq jms 消息时保留异常原因
Mule ESB-3.Build a webservice proxy