調用webservice接口,返回xml(String)轉義

import org.apache.commons.lang3.StringEscapeUtils; //依賴的包


StringBuilder content = new StringBuilder();
content.append("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
content.append("<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:ser=\"http://service.interfacemodule.lbcs.midea.com\">");
content.append("<soapenv:Header/>");
content.append("<soapenv:Body>");
content.append("<ser:doCheckQrcode>");
content.append("<ser:inParams><![CDATA[<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>");
content.append("<input><qrcode>").append(params.get("qrcode")).append("</qrcode>")
.append("<checkCode>").append(params.get("checkCode")).append("</checkCode></input>]]></ser:inParams>");
content.append("</ser:doCheckQrcode>").append("</soapenv:Body>").append("</soapenv:Envelope>");

System.out.println(content.toString());

HttpClientUtil httpClient = (HttpClientUtil) ContextUtils.getBean("httpClient");
String result = "";
Output output = null;
try {
result = httpClient.postSoap(LbcsURL, content.toString(), "doCheckQrcode");
if(StringUtil.isPresent(result)){
String xml = StringEscapeUtils.unescapeHtml4(result); //轉義操做 xml = xml.substring(xml.indexOf("<ns:return>")+"<ns:return>".length(),xml.indexOf("</ns:return>")); JAXBContext context = JAXBContext.newInstance(Output.class); Unmarshaller unmarshaller = context.createUnmarshaller(); output = (Output)unmarshaller.unmarshal(new StringReader(xml)); }} catch (Exception e) { e.printStackTrace();}return JSONObject.parseObject(output.toString());
相關文章
相關標籤/搜索