How to access a SOAP Web Service URL Endpoint from Java?
I've been searching for a concrete example for a while and I'm getting no-where. Unfortunately my preferred method using REST isn't available in this scenario I'm working on, so having to test a SOAP based approach.
The setup is, there is a SOAP WSDL file located at www.website.com/soap.wsdl
for example. And I'm trying to send and receive data from a CreateData endpoint.
When I add the WSDL file into SoapUI software to test, this generates the following SOAP message template;
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tic="{redacted}">
<soapenv:Header/>
<soapenv:Body>
<tic:CreateData>
<tic:request>{"testKey":"testValue"}</tic:request>
</tic:CreateData>
</soapenv:Body>
</soapenv:Envelope>
(I added the test JSON data)
What I can't seem to figure out is how to turn this request which works correctly in SoapUI into a functioning piece of test Java code.
When I import the WSDL into my IDE, it generates a single Java file which looks like this;
import javax.jws.WebService;
@WebService(serviceName = "{redacted}", portName = "{redacted}", endpointInterface = "{redacted}", targetNamespace = "{redacted}", wsdlLocation = "WEB-INF/wsdl/null/null.wsdl")
public class NewWebServiceFromWSDL {
public java.lang.String createData(java.lang.String request) {
//TODO implement this method
throw new UnsupportedOperationException("Not implemented yet.");
}
}
Naturally, I now have no idea what to do next. How do I go about creating a SOAP Envelope in Java? I would have expected to see some methods generated for things such as setSOAPEnvelopeHeader(), setSOAPEnvelopeBody(), setSOAPEnvelopeVariableRequest() etc. (or similar).
Then once the SOAP Envelope object has been created (however that is done), how do I then go about actually sending the message and handling the response?
Feeling confused...