Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to retrieve Unknown XML from soap web service and insert into database using java

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?

like image 693
user3522354 Avatar asked Jun 28 '26 20:06

user3522354


1 Answers

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);
}
like image 85
Optional Avatar answered Jul 01 '26 09:07

Optional