I'm confusing with creating a custom connector for WSO2 ESB 5.0.0. I need a custom connector for legacy device (thermometer). This connector will be called via ESB REST API. The only thing the connector should do is to create socket connection to given IP address (connector input parameter) and then parse the response data. The program works perfectly alone. However, I don't know how to integrate it to custom connector. Especially how to send data from the connector as a response to API call.
My connector code:
@Override
public void connect(MessageContext messageContext) throws ConnectException {
Object templateParam = getParameter(messageContext, "generated_param");
try {
log.info("sample connector received message :" + templateParam);
/**Add your connector code here
**/
Socket socket = new Socket("172.16.xxx.xxx", 2000);
BufferedWriter out = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream(), "UTF8"));
BufferedReader in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
out.write("*SRTC\r");
out.flush();
System.out.println(in.readLine());
out.close();
in.close();
socket.close();
} catch (Exception e) {
throw new ConnectException(e);
}
}
Where the message in in.readLine() should be send ???