在wso2 ESB中我想调用TCP服务器。在下面的示例代码中,我尝试调用但是在tcp服务器中我遇到了异常而且它没有连接。
<api context="/ex" name="ex" xmlns="http://ws.apache.org/ns/synapse">
<resource methods="POST">
<inSequence>
<property name="ContentType" scope="axis2" type="STRING" value="text/plain"/>
<log level="full"/>
<property name="OUT_ONLY" scope="default" type="STRING" value="true"/>
<property name="FORCE_SC_ACCEPTED" scope="axis2" type="STRING" value="value"/>
<send>
<endpoint>
<address uri="tcp://ipaddress:9090"/>
</endpoint>
</send>
</inSequence>
<outSequence>
<send/>
</outSequence>
<faultSequence/>
</resource>
TCP服务器的java代码,用于打印已恢复的消息。
public class ser {
public static void main(String[] args) //throws Exception
{
try
{
ServerSocket serverSocket = new ServerSocket(9090);
System.out.println("wainting for clients...");
boolean stop = false;
//while(!stop)
Socket socket = serverSocket.accept();
PrintWriter out = new PrintWriter(socket.getOutputStream(), true);
out.println("Hello client!");
BufferedReader input = new BufferedReader(new InputStreamReader(socket.getInputStream()));
String clientInput = input.readLine();
System.out.println(clientInput);
input.close();
out.close();
socket.close();
serverSocket.close();
} catch (Exception e)
{
System.out.println(e.toString());
}
}
}
由于ESB api是POST请求,我在postaman(restclient)中调用text / plain,消息为 hello 。
但是当我通过restclient从ESB打电话时,我在服务器套接字中得到了这些异常
java.net.SocketException:软件导致连接中止:recv失败
那么,如何在wso2 esb中建立tcp连接。