0

我使用 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 应用程序打包为 war,以便将其部署在 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 定义之后添加一个组件,但这似乎没有帮助......

4

1 回答 1

0

我发现了问题: http:outbound-endpoint 正在提供一个流,而 file: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 入站端点之前不会被消耗。

于 2014-10-24T12:38:52.843 回答