在WSO2 ESB中,我编写了一个API,该API将发送请求,并且将按照axis2.xml中配置的out顺序接收响应。
<api xmlns="http://ws.apache.org/ns/synapse" name="web" context="/web">
<resource methods="POST">
<inSequence>
<property name="FORCE_SC_ACCEPTED" value="true" scope="axis2" type="STRING"/>
<property name="OUT_ONLY" value="true" scope="default" type="STRING"/>
<send>
<endpoint>
<http method="POST" uri-template="ws://localhost:8080/websocket/server"/>
</endpoint>
</send>
</inSequence>
<outSequence>
<send/>
</outSequence>
<faultSequence/>
</resource>
</api>
上面的API能够将数据发送到WebSocket,但是我无法按照我根据axis2.xml中的配置创建的输出顺序来获取响应。
outflowDispatchSeq.xml
<?xml version="1.0" encoding="UTF-8"?>
<sequence name="outflowDispatchSeq" trace="disable" xmlns="http://ws.apache.org/ns/synapse">
<log level="full">
<property name="message" value="*********************************************************************************************"/>
</log>
</sequence>
我得到的答复是
[2018-09-08 23:21:08,715] [] INFO - LogMediator To: , MessageID: urn:uuid:1890ba9a-1aa3-4d20-ae37-ca261951793a, Direction: request, message = ********************************************************************************************, Envelope: <?xml version='1.0' encoding='utf-8'?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"><soapenv:Body/></soapenv:Envelope>
websocket服务器代码(JAVA):
package com.trinity.websocket;
import javax.websocket.OnClose;
import javax.websocket.OnError;
import javax.websocket.OnMessage;
import javax.websocket.OnOpen;
import javax.websocket.server.ServerEndpoint;
@ServerEndpoint("/server")
public class websocket {
@OnOpen
public void handleOpen()
{
System.out.println("*****websocket handle open method****");
}
@OnMessage
public String handleMessage(String message)
{
System.out.println("message=====>"+message);
String s="echo-->"+message;
System.out.println(s);
return "{\"websocketResponse\":\"dummy\"}";
}
@OnClose
public void handleClose()
{
System.out.println("******handleClose****");
}
@OnError
public void handleError(Throwable t)
{
t.printStackTrace();
}
}
在WebSocket服务器控制台中,我收到了ESB发送的消息,并且连接是持久的。
但上述webSocket服务器Link for github可以使用上述相同的API和out序列。我正在收到响应,因此,我没有收到服务器或ESB端缺少的内容。