I would like to send and receive a SOAP message using the SAAJ API between a TCP server and client. I can easily write to a TCP socket by using the SOAPMessage class by using its method writeTo for writing into a stream but how do I read a SOAP message from a TCP stream? Which class/method might be useful?
You can use javax.xml.ws.Endpoint
, here is an example
@WebServiceProvider
@ServiceMode(Mode.MESSAGE)
public class SOAPServer implements Provider<SOAPMessage> {
public SOAPMessage invoke(SOAPMessage request) {
... process request and create response
return response;
}
public static void main(String[] args) throws Exception {
Endpoint.publish("http://localhost:1111/test", new SOAPServer());
}
}
send a request
...
URL endpoint = new URL("http://localhost:1111/test");
SOAPMessage response = connection.call(message, endpoint);
...