Read plain text from tcp endpoint in WSO2 ESB

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP



Read plain text from tcp endpoint in WSO2 ESB



My environment is WSO2 EI 6.1.1 and a generic socket client/server application downloaded from sourceforge 1.



I'm trying to write a TCP proxy that is going to do this:



1- Accept a connection from a client



2- Receive some packets from the client and based on content it should make calls to a tcp endpoint



3- Receive the responses from the tcp endpoint and mediate them



4- Do 2 and 3 until receive a specific packet



5- Respond to client



6- Close the very first connection



The response from the tcp endpoint always comes in plain text.



I have tried to read the response from the tcp endpoint but it seems to me that it is always expecting a SOAP message, crashing with an error.



Here is my proxy service:


<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>



The packets sent to this proxy are received as expected, the problem is when I send some of them to the tcp endpoint and that endpoint returns a plain text response (I'm imulating the TCP endpoint with the socket test app mentioned early)



Then the Integrator write some errors because org.apache.axis2.transport.tcp.TCPTransportSender.waitForReply seems to be waiting a SOAP response.



Here is the error I get in the log file:


[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



and it continues...



I also configured my axis2.xml file to enable TCP sender and receiver as per official documentation.



so, my questions are:



what should i do to avoid these errors ?



Do you think there is a better way to implement what I'm trying to accomplish using WSO2 platform components ?



Thanks for any input you might give me. I do really appreciate it!




1 Answer
1



That's the default behaviour of an ESB where it accepts SOAP as input and accepts SOAP format as output.
after the call mediator try using the below snippet and check whether it works or not.


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





Thanks for your quick reply, the result is exactly the same. I imagine the class org.apache.axis2.transport.tcp.TCPTransportSender.waitForReply is running before any other mediation class in synapse layer.
– Jairo FERNANDEZ
Aug 10 at 9:37






Can you share entire log trace so that i can view , that will give a better idea as what exactly is happening
– amg_amit
Aug 10 at 9:53





Here is a link to my drive, where you can view the entire stack trace: docs.google.com/document/d/…
– Jairo FERNANDEZ
Aug 10 at 10:31






Is this log from the beginning ?
– amg_amit
Aug 10 at 10:33





No, it is not. I think this is the relevant part of it but anyway I'm going to upload the entire log shortly and let you know.
– Jairo FERNANDEZ
Aug 10 at 12:10






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Firebase Auth - with Email and Password - Check user already registered

Dynamically update html content plain JS

Creating a leaderboard in HTML/JS