protected ResponseMessage httpProtocol_http(String businessServiceName,RequestMessage message) throws Exception {
String url_str = protocol + ":" + "//" + host + ":" + port + uri;
logger.debug("asip服务地址:" + url_str);
URL url = new URL(url_str);
URLConnection connection = url.openConnection();
/**
* 构建soap消息
*/
StringBuffer soapMessage = new StringBuffer();
soapMessage.append("<soap:Envelope xmlns:soap=\"" + SOAP_NS + "\" soap:encodingStyle=\"" + ENCODINGSTYLE_NS
+ "\" xmlns:xsd=\"" + XSD_NS + "\" xmlns:xsi=\"" + XSI_NS + "\">");
soapMessage.append("<soap:Body>");
soapMessage.append("<ns1:call xmlns:ns1=\"http://service.asip.regaltec.com/\">");
soapMessage.append("<ns1:in0>").append(businessServiceName).append("</ns1:in0>");
soapMessage.append("<ns1:in1>").append(StringEscapeUtils.escapeXml(message.toString())).append(
"</ns1:in1>");
soapMessage.append("<ns1:in2>").append("").append("</ns1:in2>");
soapMessage.append("</ns1:call>");
soapMessage.append("</soap:Body>");
soapMessage.append("</soap:Envelope>");
logger.debug("发送到asip的soap消息内容:" + soapMessage);
byte[] b = soapMessage.toString().getBytes();
HttpURLConnection con = (HttpURLConnection) connection;
con.setRequestProperty("Content-Length", String.valueOf(b.length));
con.setRequestProperty("Content-Type", "text/xml; charset=utf-8");
con.setRequestMethod("POST");
con.setDoOutput(true);
con.setDoInput(true);
OutputStream out = con.getOutputStream();
out.write(b);
out.close();
// 发送完毕
// 读取响应
InputStreamReader isr = new InputStreamReader(con.getInputStream());
BufferedReader in = new BufferedReader(isr);
String inputLine = null;
StringBuffer result = new StringBuffer();
while ((inputLine = in.readLine()) != null) {
result.append(inputLine);
}
in.close();
logger.debug("接收到asip的soap消息内容:" + result);
/**
* 解析soap消息
*/
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setNamespaceAware(true);
DocumentBuilder builder = factory.newDocumentBuilder();
Document doc = builder.parse(new InputSource(new StringReader(result.toString())));
String callResponse = getAsipReturnString(doc);
return ResponseMessage.newInstance(callResponse);
}