I want to retrieve XML response (SOAP web service) using JAVA. The client will send the request in an XML format and java code should be able to receive a response in XML format.
Example of one XML is as below:
<soapenv:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:web="WebService">
<soapenv:Header/>
<soapenv:Body>
<web:SystemStatus soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<order xsi:type="xsd:int">?</order>
</web:SystemStatus>
</soapenv:Body>
</soapenv:Envelope>
Could you suggest steps to implement using java?
If you know the request, you can use java.net.HttpURLConnection
String soapXml = "";// your request_xml_in_question
java.net.URL url = new java.net.URL("your_Service_url");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
// Set the necessary header fields
conn.setRequestProperty("SOAPAction", "your_Service_url");
conn.setDoOutput(true);
// Send the request
java.io.OutputStreamWriter wr = new java.io.OutputStreamWriter(conn.getOutputStream());
wr.write(soapXml);
wr.flush();
// Read the response
java.io.BufferedReader rd = new java.io.BufferedReader(new java.io.InputStreamReader(conn.getInputStream()));
String line;
while ((line = rd.readLine()) != null) {
System.out.println(line);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With