Question

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?

Was it helpful?

Solution

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);
...

OTHER TIPS

Go through this GUIDE, they explain in complete details how you can compose, send and receive SOAP message over the network using SAAJ:

http://www.ibm.com/developerworks/library/x-jaxmsoap/

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top