2013-04-04 24 views
0

當我在流中使用兩個HTTP端點時,Mule引發此異常。我已經找到了解決這個問題的方法:以異步模式使用第二個HTTP端點,但這不是一個好方法。Mule HTTP java.io.IOException:試圖在封閉流中讀取

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) 

我的代碼:

<flow doc:name="httpPost" name="httpPost"> 
    <http:inbound-endpoint doc:name="HTTP" keep-alive="true" 
     exchange-pattern="request-response" host="localhost" path="service" 
     port="8082" /> 

    <http:body-to-parameter-map-transformer /> 

    <!-- This component is just set to show the message accecpted from the request --> 
    <scripting:component> 
     <scripting:script engine="groovy"> 
      println payload['name'] 
      return payload['name']+'123' 
     </scripting:script> 
    </scripting:component> 
</flow> 

<flow doc:name="httpPost" name="client"> 
    <http:inbound-endpoint doc:name="HTTP" name="httpClient" 
     exchange-pattern="request-response" host="localhost" path="client" 
     port="8082" encoding="UTF-8" /> 

    <http:body-to-parameter-map-transformer /> 

    <scripting:component> 
     <scripting:script engine="groovy"> 
      payload['name'] = 'opasso' 
      def paramstr = "" 
       for(param in payload){ 
       paramstr = paramstr + "&amp;" + param.key+ "=" + param.value 
      } 
      println "querystr:$paramstr" 
      return paramstr.substring(1) 
     </scripting:script> 
    </scripting:component> 

    <http:outbound-endpoint address="http://localhost:8082/service" 
     exchange-pattern="request-response" contentType="application/x-www-form-urlencoded" 
     method="POST" encoding="UTF-8" /> 

    <!-- This component is just set to show the message accecpted from the request --> 
    <scripting:component> 
     <scripting:script engine="groovy"> 
      def msg = "return payload:$payload;".toString() 
      println msg 
      return payload 
     </scripting:script> 
    </scripting:component> 
</flow> 

回答

0

的問題是有關您在scripting:componenthttp:outbound-endpoint產生的信息流的有效載荷做時髦的業務。該腳本可能會消耗輸入流,使其處於不能再使用的狀態。

嘗試在http:outbound-endpoint之後立即添加一個<object-to-string-transformer />以將該串流化爲一個字符串,以便可以在scripting:component和Mule中使用該有效負載。

+0

它解決了這個問題,非常感謝! – opasso 2013-04-05 06:26:05