Mule ESB:Servlet - java.io.IOException:尝试在封闭流上读取

时间:2014-10-24 08:35:15

标签: servlets mule esb inbound

我使用Mule ESB版本3.5.0

我在Anypoint Studio中设置了一个项目,其中包含一个使用http:inbound-endpoint接受请求的流程,向主体添加了SOAP标头并将其转发到外部Web应用程序。我使用了图形用户界面,效果很好。生成的xml如下:

<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" contentType="text/xml"/>
    <file:outbound-endpoint path="C:/mule/Online/OUT" responseTimeout="10000" doc:name="Responses"/>
</flow>

然后,需要将mule应用程序打包为战争,以便将其部署在Tomcat应用程序服务器上。我设法创建了战争和流程,从文件系统而不是HTTP端点工作很好。阅读完文档后,我发现HTTP端点不能在servlet上下文中使用,我将自己的流程改编为这个:

<flow name="onlineService" processingStrategy="synchronous">
    <servlet:inbound-endpoint path="/in" responseTimeout="10000" />
    <component>
        <spring-object bean="SoapHeaderCreatorBean"/>
    </component>
    <file:outbound-endpoint path="C:/mule/Online/Requests" responseTimeout="10000"/>
    <http:outbound-endpoint exchange-pattern="request-response" address="http://localhost:8080/spring-webservices-sample/endpoints" method="POST" contentType="text/xml"/>
    <file:outbound-endpoint path="C:/mule/Online/Responses" responseTimeout="10000"/>
</flow>

但是现在,如果我将一些内容发送到servlet,我会收到以下异常:

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:54)
    at org.apache.commons.io.IOUtils.copyLarge(IOUtils.java:1025)
    at org.mule.transformer.simple.ObjectToOutputHandler$3.write(ObjectToOutputHandler.java:72)
    at org.mule.transport.servlet.AbstractReceiverServlet.writeResponseFromMessage(AbstractReceiverServlet.java:185)
    at org.mule.transport.servlet.AbstractReceiverServlet.writeResponse(AbstractReceiverServlet.java:157)
    at org.mule.transport.servlet.MuleReceiverServlet.doAllMethods(MuleReceiverServlet.java:246)
    at org.mule.transport.servlet.MuleReceiverServlet.doPost(MuleReceiverServlet.java:194)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:647)
    at org.mule.transport.servlet.MuleReceiverServlet.service(MuleReceiverServlet.java:176)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
    at com.googlecode.psiprobe.Tomcat70AgentValve.invoke(Tomcat70AgentValve.java:38)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1023)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:745)

我试图添加一个: <object-to-string-transformer /> servlet定义之后的组件,但似乎没有帮助...

1 个答案:

答案 0 :(得分:0)

我发现了问题: http:outbound-endpoint正在提供一个流和文件:outbound-endpoint正在使用它。我在HTTP出站端点之后放置了一个变换器(对象到字符串),这解决了我的问题:

<flow name="onlineService" processingStrategy="synchronous">
    <servlet:inbound-endpoint path="/in" responseTimeout="10000" />
    <component>
        <spring-object bean="SoapHeaderCreatorBean"/>
    </component>
    <file:outbound-endpoint path="C:/mule/Online/Requests" responseTimeout="10000"/>
    <http:outbound-endpoint exchange-pattern="request-response" address="http://localhost:8080/spring-webservices-sample/endpoints" method="POST" contentType="text/xml"/>
    <object-to-string-transformer/>
    <file:outbound-endpoint path="C:/mule/Online/Responses" responseTimeout="10000"/>
</flow>

像这样,流被存储在内存中,并且在响应返回到HTTP入站端点之前不被消耗。