繁体   English   中英

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

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

我想使用 JAVA 检索 XML 响应(SOAP Web 服务)。 客户端将以 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);
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM