How to catch tcp client request message in wso2 esb proxy service

时光怂恿深爱的人放手 提交于 2019-12-12 05:59:15

问题


Im new comer to Wso2 esb. Now I'm working with tcp protocol and proxy service. I have some question. I send some message to the proxy service through tcp protocol. I need get this message to the property mediator in the proxy service. But my way not catch that value in the property mediator.
Here is my proxy service

<?xml version="1.0" encoding="UTF-8"?>
<proxy name="TCPProxyService" startOnLoad="true" transports="tcp" xmlns="http://ws.apache.org/ns/synapse">
    <target>
        <inSequence>
            <property description="" expression="get-property('message')" name="MessageValue" scope="default" type="STRING"/>
            <log description="" level="custom">
                <property name="property_name" value="============================="/>
                <property expression="get-property('MessageValue')" name="inputValue"/>
            </log>
            <sequence key="in-sequence"/>
            <log/>
            <respond/>
        </inSequence>
        <outSequence/>
        <faultSequence/>
    </target>
    <parameter name="transport.tcp.responseClient">true</parameter>
    <parameter name="transport.tcp.inputType">string</parameter>
    <parameter name="transport.tcp.recordDelimiter">|</parameter>
    <parameter name="transport.tcp.contentType">text/plain</parameter>
    <parameter name="transport.tcp.port">6789</parameter>
    <parameter name="transport.tcp.recordDelimiterType">character</parameter>
</proxy>

Here is my Java client for send tcp request

import java.io.*;
import java.net.*;

class TCPClient {
    public static void main(String argv[]) throws Exception {
        String delimiter = "|";
        int modifiedSentence;
        Socket clientSocket = new Socket("localhost", 6789);
        DataOutputStream outToServer = new 
           DataOutputStream(clientSocket.getOutputStream());
        BufferedReader inFromServer = new BufferedReader(new 
        InputStreamReader(clientSocket.getInputStream()));
        String message = "Pietoo,Klaas,also" + delimiter;
        outToServer.writeBytes(message);
        outToServer.flush();
        while ((modifiedSentence = inFromServer.read()) > -1){
           System.out.print((char)modifiedSentence);
        }
        clientSocket.close();
        }
}

I tried to add below property mediator with get-property expression. What is the wrong with this.

property description="" expression="get-property('message')" name="MessageValue" scope="default" type="STRING"/>


回答1:


try a <log level="full"/> in your proxy def, send it a message with your java client and have a look to wso2-esb-service.log : you should see a soap message like this

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
    <soapenv:Body>
        <text xmlns="http://ws.apache.org/commons/ns/payload">your|data</text>
    </soapenv:Body>
</soapenv:Envelope>

You can get the text value with :

<property xmlns:tp="http://ws.apache.org/commons/ns/payload" name="MessageValue" expression="$body/tp:text"/>


来源:https://stackoverflow.com/questions/44653915/how-to-catch-tcp-client-request-message-in-wso2-esb-proxy-service

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!