从WSO2 ESB中的TCP端点读取纯文本

时间:2018-08-10 02:52:35

标签: sockets tcp wso2 wso2esb integrator

我的环境是WSO2 EI 6.1.1,并且是从sourceforge 1下载的通用套接字客户端/服务器应用程序。

我正在尝试编写一个将执行此操作的TCP代理:

1-接受来自客户端的连接

2-从客户端接收一些数据包,并根据内容,它应该调用tcp端点

3-接收来自tcp端点的响应并进行调解

4-进行2和3,直到收到特定的数据包

5-回应客户

6-关闭第一个连接

tcp端点的响应始终以纯文本形式出现。

我试图读取tcp端点的响应,但是在我看来,它一直在等待SOAP消息,并因错误而崩溃。

这是我的代理服务:

<proxy xmlns="http://ws.apache.org/ns/synapse"
   name="TCP_Prx"
   startOnLoad="true"
   statistics="disable"
   trace="disable"
   transports="tcp">
   <target>
      <inSequence>
         <property xmlns:ns="http://ws.apache.org/commons/ns/payload"
                   expression="string-length(//ns:text/text()[contains(., 'call')])&gt;0"
                   name="is_call"
                   scope="default"
                   type="STRING"/>
         <log level="full">
            <property expression="$ctx:is_call" name="msg_TCPPrx"/>
         </log>
         <filter regex="true" source="$ctx:is_tpvcall">
            <then>
               <log level="custom">
                  <property name="msg_TCPPrx" value="Sending info to TCP endpoint"/>
               </log>
               <header name="Accept" scope="transport" value="text/plain"/>
               <property name="messageType" scope="axis2" value="text/plain"/>
               <call>
                    <endpoint>
                        <address uri="tcp://localhost:2200"/>
                    </endpoint>
               </call>
               <log level="full">
                  <property name="msg_TCPPrx" value="Response from TCP endpoint"/>
               </log>
            </then>
            <else/>
         </filter>
      </inSequence>
   </target>
   <parameter name="transport.tcp.recordDelimiter">0x03</parameter>
   <parameter name="transport.tcp.contentType">text/plain</parameter>
   <parameter name="transport.tcp.port">7777</parameter>
   <parameter name="transport.tcp.recordDelimiterType">byte</parameter>
   <description/>
</proxy>

发送到此代理的数据包按预期收到,问题是当我将其中一些发送到tcp端点,并且该端点返回纯文本响应时(我在前面提到的套接字测试应用程序中模仿了TCP端点)

然后,集成商会写一些错误,因为org.apache.axis2.transport.tcp.TCPTransportSender.waitForReply似乎正在等待SOAP响应。

这是我在日志文件中看到的错误:

[2018-08-09 21:50:25,856] [] ERROR - TCPTransportSender Error while processing response
org.apache.axiom.om.OMException: com.ctc.wstx.exc.WstxUnexpectedCharException: Unexpected character 'c' (code 99) in prolog; expected '<'
 at [row,col {unknown-source}]: [1,1]
        at org.apache.axiom.om.impl.builder.StAXOMBuilder.next(StAXOMBuilder.java:296)
        at org.apache.axiom.soap.impl.builder.StAXSOAPModelBuilder.getSOAPEnvelope(StAXSOAPModelBuilder.java:204)
        at org.apache.axiom.soap.impl.builder.StAXSOAPModelBuilder.<init>(StAXSOAPModelBuilder.java:154)
        at org.apache.axiom.om.impl.AbstractOMMetaFactory.createStAXSOAPModelBuilder(AbstractOMMetaFactory.java:73)
        at org.apache.axiom.om.impl.AbstractOMMetaFactory.createSOAPModelBuilder(AbstractOMMetaFactory.java:79)
        at org.apache.axiom.om.OMXMLBuilderFactory.createSOAPModelBuilder(OMXMLBuilderFactory.java:196)
        at org.apache.axis2.builder.SOAPBuilder.processDocument(SOAPBuilder.java:65)
        at org.apache.axis2.transport.TransportUtils.createDocumentElement(TransportUtils.java:188)
        at org.apache.axis2.transport.TransportUtils.createSOAPMessage(TransportUtils.java:146)
        at org.apache.axis2.transport.tcp.TCPTransportSender.waitForReply(TCPTransportSender.java:128)
        at org.apache.axis2.transport.tcp.TCPTransportSender.sendMessage(TCPTransportSender.java:58)
        at org.apache.axis2.transport.base.AbstractTransportSender.invoke(AbstractTransportSender.java:112)
        at org.apache.axis2.engine.AxisEngine$TransportNonBlockingInvocationWorker.run(AxisEngine.java:626)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
        at java.lang.Thread.run(Thread.java:748)
Caused by: com.ctc.wstx.exc.WstxUnexpectedCharException: Unexpected character 'c' (code 99) in prolog; expected '<'
 at [row,col {unknown-source}]: [1,1]
        at com.ctc.wstx.sr.StreamScanner.throwUnexpectedChar(StreamScanner.java:639)
        at com.ctc.wstx.sr.BasicStreamReader.nextFromProlog(BasicStreamReader.java:2052)
        at com.ctc.wstx.sr.BasicStreamReader.next(BasicStreamReader.java:1134)
        at org.apache.axiom.util.stax.wrapper.XMLStreamReaderWrapper.next(XMLStreamReaderWrapper.java:225)
        at org.apache.axiom.util.stax.dialect.DisallowDoctypeDeclStreamReaderWrapper.next(DisallowDoctypeDeclStreamReaderWrapper.java:34)
        at org.apache.axiom.om.impl.builder.StAXOMBuilder.parserNext(StAXOMBuilder.java:681)
        at org.apache.axiom.om.impl.builder.StAXOMBuilder.next(StAXOMBuilder.java:214)
        ... 15 more
[2018-08-09 21:50:25,859] [] ERROR - TCPTransportSender Error while sending a TCP request
org.apache.axis2.AxisFault: Error while processing response
        at org.apache.axis2.transport.base.AbstractTransportSender.handleException(AbstractTransportSender.java:226)
        at org.apache.axis2.transport.tcp.TCPTransportSender.waitForReply(TCPTransportSender.java:133)
        at org.apache.axis2.transport.tcp.TCPTransportSender.sendMessage(TCPTransportSender.java:58)
        at org.apache.axis2.transport.base.AbstractTransportSender.invoke(AbstractTransportSender.java:112)
        at org.apache.axis2.engine.AxisEngine$TransportNonBlockingInvocationWorker.run(AxisEngine.java:626)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
        at java.lang.Thread.run(Thread.java:748)
Caused by: org.apache.axiom.om.OMException: com.ctc.wstx.exc.WstxUnexpectedCharException: Unexpected character 'c' (code 99) in prolog; expected '<'
 at [row,col {unknown-source}]: [1,1]
        at org.apache.axiom.om.impl.builder.StAXOMBuilder.next(StAXOMBuilder.java:296)
        at org.apache.axiom.soap.impl.builder.StAXSOAPModelBuilder.getSOAPEnvelope(StAXSOAPModelBuilder.java:204)
        at org.apache.axiom.soap.impl.builder.StAXSOAPModelBuilder.<init>(StAXSOAPModelBuilder.java:154)
        at org.apache.axiom.om.impl.AbstractOMMetaFactory.createStAXSOAPModelBuilder(AbstractOMMetaFactory.java:73)
        at org.apache.axiom.om.impl.AbstractOMMetaFactory.createSOAPModelBuilder(AbstractOMMetaFactory.java:79)
        at org.apache.axiom.om.OMXMLBuilderFactory.createSOAPModelBuilder(OMXMLBuilderFactory.java:196)
        at org.apache.axis2.builder.SOAPBuilder.processDocument(SOAPBuilder.java:65)
        at org.apache.axis2.transport.TransportUtils.createDocumentElement(TransportUtils.java:188)
        at org.apache.axis2.transport.TransportUtils.createSOAPMessage(TransportUtils.java:146)
        at org.apache.axis2.transport.tcp.TCPTransportSender.waitForReply(TCPTransportSender.java:128)
        ... 6 more

并且继续...

我还配置了axis2.xml文件,以根据官方文档启用TCP发送器和接收器。

所以,我的问题是:

  1. 我应该怎么做才能避免这些错误?

  2. 您是否认为有更好的方法来实现我正在尝试使用WSO2平台组件完成的任务?

感谢您可能给我的任何意见。我真的很感激!

1 个答案:

答案 0 :(得分:0)

这是ESB的默认行为,它接受SOAP作为输入并接受SOAP格式作为输出。 呼叫中介后,请尝试使用以下代码段并检查其是否有效。

<property name="messageType" scope="axis2" value="text/plain"/>
<property name="contentType" scope="axis2" value="text/plain"/>