When you need to consume a webservice and that service is using a deprecated rpc/encoded binding style, then you are faced with a problem that there is no real good solution to. In short, the problem is that all the JAX-WS implementations from a couple of years back have ommitted their support for this configuration. “The WS-I Basic Profile limits binding styles to either Document/literal or RPC/literal, and JAX-WS was designed to honor this limitation” I can think of a couple of options to work around this problem.
- Use the older version of Axis. That is Axis before Axis2.
- Plug in your own marshal/unmarshal module in you existing JAX-WS provider.
- Consume this service with a little more “low level” approach.
I will give an example of alternative 3 using the SAAJ API.
public WebserviceCall(final String destinationUrl, final StreamSource contentOfMessage) { this.contentOfMessage = contentOfMessage; this.destination = destinationUrl; } public WebServiceReply call() throws SOAPException, IOException { final SOAPConnectionFactory connectionFactory = SOAPConnectionFactory.newInstance(); final SOAPConnection connection = connectionFactory.createConnection(); final SOAPMessage message = MessageFactory.newInstance().createMessage(); final SOAPPart soapPart = message.getSOAPPart(); soapPart.setContent(contentOfMessage); final SOAPMessage reply = connection.call(message, destination); connection.close(); final WebServiceReply wsReply = new WebServiceReply(reply); return wsReply; }
contentOfMessage is just a soap message put in a StreamSource.
WebServiceReply is just a holder of the soap message received from the remote endpoint, nothing important.
Now you must get hold of the body of the soap message. Something like “soapMessage.getSOAPBody()” This will get you a Node in return and then you can use JAX-B to unmarshal the Node into a Java object. This assumes of course that you have generated Java classes from an appropriate schema representing your Node in the xml document. Just google it and you will find lots of info.
{ final JAXBContext context = JAXBContext.newInstance(className); final Unmarshaller unmarshaller = context.createUnmarshaller(); return unmarshaller.unmarshal(node); }
An example of a simple soap 1.1 message:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ws="http://some.domain.com/"> <soapenv:Header/> <soapenv:Body> <ws:Get> <ws:Id>1</ws:Id> </ws:Get> </soapenv:Body> </soapenv:Envelope>
