title: Mule HTTP java.io.IOException: Attempted read on closed stream
body: <p>When I used two HTTP endpoints in a flow, Mule throws this exception. I've found the way to deal with this problem: use the second HTTP endpoint in asynchronous mode, but it is not a good way.</p>
  
  <pre><code>ERROR DefaultSystemExceptionStrategy [[testdemo].connector.http.mule.default.receiver.03]: Caught exception in Exception Strategy: Attempted read on closed stream.
  java.io.IOException: Attempted read on closed stream.
      at org.apache.commons.httpclient.AutoCloseInputStream.isReadAllowed(AutoCloseInputStream.java:183)
      at org.apache.commons.httpclient.AutoCloseInputStream.read(AutoCloseInputStream.java:126)
      at org.mule.model.streaming.DelegatingInputStream.read(DelegatingInputStream.java:58)
      at org.apache.commons.io.IOUtils.copyLarge(IOUtils.java:1025)
      at org.mule.transformer.simple.ObjectToOutputHandler$3.write(ObjectToOutputHandler.java:76)
      at org.mule.transport.http.HttpServerConnection.writeResponse(HttpServerConnection.java:315)
      at org.mule.transport.http.HttpMessageReceiver$HttpWorker.run(HttpMessageReceiver.java:164)
      at org.mule.work.WorkerContext.run(WorkerContext.java:311)
      at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
      at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
      at java.lang.Thread.run(Unknown Source)
  </code></pre>
  
  <p>my code :</p>
  
  <pre><code>&lt;flow doc:name="httpPost" name="httpPost"&gt;
      &lt;http:inbound-endpoint doc:name="HTTP" keep-alive="true"
          exchange-pattern="request-response" host="localhost" path="service"
          port="8082" /&gt;
  
      &lt;http:body-to-parameter-map-transformer /&gt;
  
      &lt;!-- This component is just set to show the message accecpted from the request --&gt;
      &lt;scripting:component&gt;
          &lt;scripting:script engine="groovy"&gt;
              println payload['name']
              return payload['name']+'123'
          &lt;/scripting:script&gt;
      &lt;/scripting:component&gt;
  &lt;/flow&gt;
  
  &lt;flow doc:name="httpPost" name="client"&gt;
      &lt;http:inbound-endpoint doc:name="HTTP" name="httpClient"
          exchange-pattern="request-response" host="localhost" path="client"
          port="8082" encoding="UTF-8" /&gt;
  
      &lt;http:body-to-parameter-map-transformer /&gt;
  
      &lt;scripting:component&gt;
          &lt;scripting:script engine="groovy"&gt;
              payload['name'] = 'opasso'
              def paramstr = ""
                  for( param in payload){
                  paramstr = paramstr + "&amp;amp;" + param.key+ "=" + param.value
              }
              println "querystr:$paramstr"
              return paramstr.substring(1)
          &lt;/scripting:script&gt;
      &lt;/scripting:component&gt;
  
      &lt;http:outbound-endpoint address="http://localhost:8082/service"
          exchange-pattern="request-response" contentType="application/x-www-form-urlencoded"
          method="POST" encoding="UTF-8" /&gt;
  
      &lt;!-- This component is just set to show the message accecpted from the request --&gt;
      &lt;scripting:component&gt;
          &lt;scripting:script engine="groovy"&gt;
              def msg = "return payload:$payload;".toString()
              println msg
              return payload
          &lt;/scripting:script&gt;
      &lt;/scripting:component&gt;
  &lt;/flow&gt;
  </code></pre>