我正在尝试进行阻止调用以检索PDF文件,但每当我尝试使用返回的有效负载(包括发送它)时都会抛出错误。
错误是"在关闭的流"上尝试读取,我认为它正在发生,因为只有在需要时才将响应解析为xml,但到那时调用调解员关闭了连接。
以下是一个示例序列:
<call blocking="true">
<endpoint>
<http uri-template="https://myserver.com/generatePDF?id=1234" method="GET"/>
</endpoint>
</call>
<log level="custom">
<property name="msg" value="Complete"/>
</log>
<log level="custom">
<property name="body" expression="$body"/>
</log>
<log level="full"/>
观察日志,进行呼叫并等待响应。一旦响应完成,&#34;完成&#34;打印日志消息。但是当它试图访问$ body时会发生以下错误:
[2016-05-19 13:03:21,582] INFO - LogMediator msg = Complete
[2016-05-19 13:03:21,584] ERROR - SequenceMediator Error reading data handler
org.apache.axiom.om.OMException: Error reading data handler
at org.apache.axiom.om.impl.llom.OMTextImpl.internalSerialize(OMTextImpl.java:421)
at org.apache.axiom.om.impl.util.OMSerializerUtil.serializeChildren(OMSerializerUtil.java:555)
at org.apache.axiom.om.impl.llom.OMElementImpl.internalSerialize(OMElementImpl.java:875)
at org.apache.axiom.om.impl.util.OMSerializerUtil.serializeChildren(OMSerializerUtil.java:555)
at org.apache.axiom.om.impl.llom.OMElementImpl.internalSerialize(OMElementImpl.java:875)
at org.apache.axiom.om.impl.llom.OMSerializableImpl.serialize(OMSerializableImpl.java:125)
at org.apache.axiom.om.impl.llom.OMSerializableImpl.serialize(OMSerializableImpl.java:113)
at org.apache.axiom.om.impl.llom.OMElementImpl.toString(OMElementImpl.java:988)
at org.apache.synapse.util.xpath.SynapseXPath.stringValueOf(SynapseXPath.java:321)
at org.apache.synapse.mediators.MediatorProperty.getEvaluatedExpression(MediatorProperty.java:138)
at org.apache.synapse.mediators.builtin.LogMediator.setCustomProperties(LogMediator.java:216)
at org.apache.synapse.mediators.builtin.LogMediator.getCustomLogMessage(LogMediator.java:139)
at org.apache.synapse.mediators.builtin.LogMediator.getLogMessage(LogMediator.java:125)
at org.apache.synapse.mediators.builtin.LogMediator.mediate(LogMediator.java:95)
at org.apache.synapse.mediators.AbstractListMediator.mediate(AbstractListMediator.java:81)
at org.apache.synapse.mediators.AbstractListMediator.mediate(AbstractListMediator.java:48)
at org.apache.synapse.mediators.base.SequenceMediator.mediate(SequenceMediator.java:149)
at org.apache.synapse.core.axis2.ProxyServiceMessageReceiver.receive(ProxyServiceMessageReceiver.java:185)
at org.apache.axis2.engine.AxisEngine.receive(AxisEngine.java:180)
at org.apache.synapse.transport.passthru.ServerWorker.processEntityEnclosingRequest(ServerWorker.java:395)
at org.apache.synapse.transport.passthru.ServerWorker.run(ServerWorker.java:142)
at org.apache.axis2.transport.base.threads.NativeWorkerPool$1.run(NativeWorkerPool.java:172)
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)
Caused by: 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:107)
at java.util.zip.InflaterInputStream.fill(InflaterInputStream.java:238)
at java.util.zip.InflaterInputStream.read(InflaterInputStream.java:158)
at java.util.zip.GZIPInputStream.read(GZIPInputStream.java:116)
at java.io.FilterInputStream.read(FilterInputStream.java:107)
at org.wso2.carbon.relay.BinaryRelayBuilder.readAllFromInputSteam(BinaryRelayBuilder.java:39)
at org.wso2.carbon.relay.StreamingOnRequestDataSource.getInputStream(StreamingOnRequestDataSource.java:59)
at javax.activation.DataHandler.writeTo(DataHandler.java:305)
at org.apache.axiom.util.stax.XMLStreamWriterUtils.writeBase64(XMLStreamWriterUtils.java:62)
at org.apache.axiom.util.stax.XMLStreamWriterUtils.writeDataHandler(XMLStreamWriterUtils.java:138)
at org.apache.axiom.om.impl.llom.OMTextImpl.internalSerialize(OMTextImpl.java:418)
... 24 more
单步执行代码我可以看到响应在http连接上可用。输入流是围绕该连接构建的,但在调用完成后,将在清理方法中关闭HTTP连接。
首次访问正文时,会读取流,但此时它已经关闭,这会产生以下错误。
如何使用带有阻止=&#34;的真实&#34;?
的呼叫中介来检索PDFWSO2 ESB 4.9.0
将以下内容添加到axis2_blocking_client.xml
的消息构建器部分<messageBuilder contentType="application/pdf" class="org.wso2.carbon.relay.BinaryRelayBuilder" />
答案 0 :(得分:1)
二进制中继使用这些格式化程序和构建程序通过Apache Synapse中继消息(包括格式良好和消息不良),而无需处理(例如,XML验证或处理)这些消息。二进制中继包括Builder和Formatter。收到消息后,Builder会创建一个伪SOAP消息,将传入的SOAP消息的内容作为二进制XML节点附加,并通过Apache Axis2内核发送,并在发送时,二进制中继格式化程序扩展SOAP消息并将附加内容写入输出通道。因此,消息通过Apache Synapse而不处理其内容,因为消息是在字节级别处理的,甚至非XML消息也可能通过Apache Synapse。
如需了解更多信息,请read。