public void demo10() {
String xmlData = "<![CDATA["+ "1111111"+"]]>";
String data="<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:ser=\"http://service.regulatoryplat.jsntuah.com\">\n" +
" <soapenv:Header/>\n" +
" <soapenv:Body>\n" +
" <ser:unRegApp>\n" +
" <!--Optional:-->\n" +
" \n" +
" <arg0>"+xmlData+"</arg0></ser:unRegApp>\n" +
" </soapenv:Body>\n" +
"</soapenv:Envelope>";
try {
URL url = new URL("http://127.0.0.1:8081/webservice/api?wsdl");
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("POST");
connection.setRequestProperty("content-type", "text/xml;charset=utf-8");
connection.setDoInput(true);
connection.setDoOutput(true);
String soapXML = data;
OutputStream os = connection.getOutputStream();
os.write(soapXML.getBytes());
int responseCode = connection.getResponseCode();
if(200 == responseCode){
InputStream is = connection.getInputStream();
InputStreamReader isr = new InputStreamReader(is);
BufferedReader br = new BufferedReader(isr);
StringBuilder sb = new StringBuilder();
String temp = null;
while(null != (temp = br.readLine())){
sb.append(temp);
}
is.close();
isr.close();
br.close();
System.out.println(StringEscapeUtils.unescapeXml(sb.toString()));
System.out.println(sb.toString());
cn.hutool.json.JSONObject json = XML.toJSONObject(sb.toString());
System.out.println(json.getJSONObject("soap:Envelope").getJSONObject("soap:Body").getJSONObject("ns2:unRegAppResponse").getStr("String"));
} else {
InputStream is = connection.getErrorStream();
InputStreamReader isr = new InputStreamReader(is,"utf-8");
BufferedReader in = new BufferedReader(isr);
String inputLine;
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(
new FileOutputStream("d:\\result.xml")));
while ((inputLine = in.readLine()) != null)
{
System.out.println(inputLine);
bw.write(inputLine);
bw.newLine();
bw.close();
}
in.close();
}
os.close();
} catch (Exception e) {
System.out.println(e.getMessage());
}
}