如何在wso2 esb代理服务中捕获tcp客户端请求消息 [英] How to catch tcp client request message in wso2 esb proxy service
问题描述
我是 Wso2 esb 的新手.现在我正在使用 tcp 协议和代理服务.我有一些问题.我通过 tcp 协议向代理服务发送一些消息.我需要将此消息发送给代理服务中的属性中介.但是我的方法没有在属性中介中捕获该值.
这是我的代理服务
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>
这是我的 Java 客户端,用于发送 tcp 请求
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();
}
}
我尝试使用 get-property 表达式添加以下属性介体.这有什么问题.
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"/>
property description="" expression="get-property('message')" name="MessageValue" scope="default" type="STRING"/>
推荐答案
在您的代理定义中尝试 <log level="full"/>
,向您的 Java 客户端发送消息并查看 wso2-esb-service.log :您应该看到这样的soap消息
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"/>
这篇关于如何在wso2 esb代理服务中捕获tcp客户端请求消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!