如何从 soap 网络服务检索未知 XML 并使用 java 插入数据库

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

我想使用 JAVA 检索 XML 响应(SOAP 网络服务)。 客户端将以 XML 格式发送请求,并且 java 代码应该能够接收 XML 格式的响应。

一个XML的例子如下:

<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>

您能否建议使用 java 实施的步骤?

如果你知道请求,你可以使用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);
}