简体   繁体   中英

Mule - MuleMessage.getPayloadString() gives me java.io.IOException: Bad chunk size

I use Mule 3.5.0

I have a mule configuration where I accept HTTP requests, I add a SOAP header to them and I forward them to an external service and the result of that service call is returned:

ule子流量

Since I want to see what happens I write the generated request and response messages to folders. (Requests and Responses components).

For testing purposes I created a test method using the MuleClient functionality:

@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());
}

Everything works fine and after executing my test my response message is written to the folder location by the Responses component:

<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> 

But then when my message returns in my client and I want to print it, I got following exception:

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

I don't know what the reason of this failure and how I could resolve it. Probably something is wrong in my flow configuration?

<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>    

It seems that the http:outbound endpoint is giving you a stream and the file outbound endpoint is consuming this. You should put a transformer (such as object-to-string) after the http outbound endpoint so as to make sure that the stream is stored in memory and not consumed before the response is given back to the http inbound endpoint.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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