我使用的是Mule 3.5.0
我有一个mule配置,我接受HTTP请求,我向它们添加一个SOAP标头,然后将它们转发到外部服务,并返回该服务调用的结果:
由于我想看看会发生什么,我将生成的请求和响应消息写入文件夹。 (请求和响应组件)。
出于测试目的,我使用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>
答案 0 :(得分:1)
似乎http:outbound端点正在为您提供流,而文件出站端点正在使用此流。您应该在http出站端点之后放置一个转换器(例如对象到字符串),以确保在将响应返回到http入站端点之前将流存储在内存中并且不消耗。