我使用Mule 3.5.0
我有一个 mule 配置,我接受 HTTP 请求,向它们添加 SOAP header ,然后将它们转发到外部服务,然后返回该服务调用的结果:
因为我想看看会发生什么,所以我将生成的请求和响应消息写入文件夹。 (请求和响应组件)。
出于测试目的,我使用 MuleClient 功能创建了一个测试方法:
@Test
public void testOnlineServiceFlow() throws Exception
{
MuleClient client = new MuleClient(muleContext);
MuleMessage result = client.send("http://localhost:1234/in", "<acc:AccountDetailsRequest xmlns:acc=\"http://com/blog/samples/webservices/accountservice\"><acc:accountNumber>12345</acc:accountNumber></acc:AccountDetailsRequest>", null);
System.out.println(result.getPayloadAsString());
}
一切正常,执行测试后,响应组件将我的响应消息写入文件夹位置:
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Header/>
<SOAP-ENV:Body>
<ns3:AccountDetailsResponse xmlns:ns2="http://webservices.samples.blog.com" xmlns:ns3="http://com/blog/samples/webservices/accountservice">
<ns3:AccountDetails>
<ns2:AccountNumber>12345</ns2:AccountNumber>
<ns2:AccountName>Joe Bloggs</ns2:AccountName>
<ns2:AccountBalance>3400.0</ns2:AccountBalance>
<ns2:AccountStatus>Active</ns2:AccountStatus>
</ns3:AccountDetails>
</ns3:AccountDetailsResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
但是当我的消息返回到客户端并且我想打印它时,出现以下异常:
org.mule.api.transformer.TransformerException: Could not read InputStream.
at org.mule.transformer.simple.ObjectToString.createStringFromInputStream(ObjectToString.java:83)
at org.mule.transformer.simple.ObjectToString.doTransform(ObjectToString.java:54)
at org.mule.transformer.AbstractTransformer.transform(AbstractTransformer.java:419)
at org.mule.DefaultMuleMessage.getPayload(DefaultMuleMessage.java:375)
at org.mule.DefaultMuleMessage.getPayloadAsString(DefaultMuleMessage.java:630)
at org.mule.DefaultMuleMessage.getPayloadAsString(DefaultMuleMessage.java:565)
at be.healthconnect.handicare.OnlineServiceTest.testOnlineServiceFlow(OnlineServiceTest.java:21)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
at org.junit.rules.TestWatcher$1.evaluate(TestWatcher.java:46)
at org.junit.internal.runners.statements.FailOnTimeout$1.run(FailOnTimeout.java:28)
Caused by: java.io.IOException: Bad chunk size: HTTP/1.1 500 Internal Server Error
at org.apache.commons.httpclient.ChunkedInputStream.getChunkSizeFromInputStream(ChunkedInputStream.java:306)
at org.apache.commons.httpclient.ChunkedInputStream.nextChunk(ChunkedInputStream.java:221)
at org.apache.commons.httpclient.ChunkedInputStream.read(ChunkedInputStream.java:176)
at java.io.FilterInputStream.read(Unknown Source)
at org.apache.commons.httpclient.AutoCloseInputStream.read(AutoCloseInputStream.java:108)
at java.io.FilterInputStream.read(Unknown Source)
at org.apache.commons.httpclient.AutoCloseInputStream.read(AutoCloseInputStream.java:127)
at org.mule.model.streaming.DelegatingInputStream.read(DelegatingInputStream.java:54)
at org.apache.commons.io.IOUtils.copyLarge(IOUtils.java:1792)
at org.apache.commons.io.IOUtils.copyLarge(IOUtils.java:1769)
at org.apache.commons.io.IOUtils.copy(IOUtils.java:1744)
at org.mule.transformer.simple.ObjectToString.createStringFromInputStream(ObjectToString.java:78)
... 18 more
我不知道失败的原因是什么以及如何解决它。我的流程配置可能有问题?
<flow name="Online_Service" doc:name="Online_Service">
<http:inbound-endpoint exchange-pattern="request-response" name="clientEndpoint" address="http://localhost:1234/in" doc:name="HTTP" contentType="text/xml"/>
<component doc:name="SOAP Header Creator">
<spring-object bean="SoapHeaderCreatorBean"/>
</component>
<file:outbound-endpoint path="C:/mule/Online/OUT" responseTimeout="10000" doc:name="Requests"/>
<http:outbound-endpoint exchange-pattern="request-response" address="http://localhost:8080/spring-webservices-sample/endpoints" doc:name="HTTP" method="POST" />
<file:outbound-endpoint path="C:/mule/Online/OUT" responseTimeout="10000" doc:name="Responses"/>
</flow>
最佳答案
看起来 http:outbound 端点正在为您提供一个流,而文件出站端点正在使用它。您应该在 http 出站端点之后放置一个转换器(例如对象到字符串),以确保流存储在内存中,并且在响应返回到 http 入站端点之前不会被消耗。
关于java - Mule - MuleMessage.getPayloadString() 给我 java.io.IOException : Bad chunk size,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26044533/