Ecology-Dev-chaofa/盛虹化纤/interface/shhq/tb002.jsp

152 lines
5.4 KiB
Plaintext
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<%@ page language="java" contentType="text/html; charset=utf-8" %>
<%@ page import="weaver.general.*,java.util.*,java.math.*" %>
<%@ page import="java.util.Map" %>
<%@ page import="java.util.HashMap" %>
<%@ page import="org.apache.http.impl.client.*" %>
<%@ page import="org.apache.http.impl.client.CloseableHttpClient" %>
<%@ page import="org.apache.http.client.methods.HttpPost" %>
<%@ page import="org.apache.http.client.methods.CloseableHttpResponse" %>
<%@ page import="org.apache.http.message.BasicHeader" %>
<%@ page import="cn.hutool.core.codec.Base64" %>
<%@ page import="org.apache.http.entity.*" %>
<%@ page import="java.nio.charset.Charset" %>
<%@ page import="org.apache.http.HttpEntity" %>
<%@ page import="org.apache.http.util.EntityUtils" %>
<%@ page import="java.io.IOException" %>
<%
int sum = 0;
String url = "http://poqassrv.shenghongtec.com:50000/XISOAPAdapter/MessageServlet?senderParty=&senderService=SH_BPM_QAS&receiverParty=&receiverService=&interface=CommonInter_Info_SYN_OUT&interfaceNamespace=urn:shenghong:bpm:s4";
//
String val = "[{\"company_name\": \"江苏国望高科纤维有限公司\",\"DEPART_NAME\":\"纺丝二部\",\"DEPART_SX\":\"生产部门\",\"pernr\":\"87011888\",\"name\":\"张三\",\"id_card\":\"14052419761114803Z\",\"birthday\":\"19961011\",\"sex\":\"男\",\"address\":\"云南省德宏傣族景颇族自治州梁河县曩宋乡芒东村民委员会大地组 \",\"phone\":\"13988226825\"}]";
// 同步工号的入参
// <VALUE>[{"company_name": "江苏国望高科纤维有限公司","pernr":"87011888","name":"张三","id_card":"14052419761114803Z","birthday":"19961011","sex":"男","address":"云南省德宏傣族景颇族自治州梁河县曩宋乡芒东村民委员会大地组 ","phone":"13988226825"}]</VALUE>
String action = "SSQ_EMPINFO";
//SSQ_PMINFO
//SSQ_EMPINFO
String xml ="<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:urn=\"urn:shenghong:bpm:s4\">\n" +
" <soapenv:Header/>\n" +
" <soapenv:Body>\n" +
" <urn:CommonInter_Info>\n" +
" <ACTION>"+action+"</ACTION>\n" +
" <VALUE>"+val+"</VALUE>\n" +
" </urn:CommonInter_Info>\n" +
" </soapenv:Body>\n" +
"</soapenv:Envelope>";
String usr_pwd = "po_sender:posender0807" ;
String soapAction = "";
// S接收成功[{"PERNR":"87011888","STATE":"S","MESSAGE":"创建成功"}]
String msgMap = doPostSoap(url,xml,soapAction,usr_pwd);
String ISSUCCESS = getValue(msgMap,"ISSUCCESS");
String DATA = getValue(msgMap,"DATA");
sum++;
%>
<%!
public static String getValue(String xml,String name){
String value = "";
String begin = "<"+name+">";
String end = "</"+name+">";
if(xml.contains(name)){
value = xml.substring(
xml.indexOf(begin) ,
xml.indexOf(end)+ end.length());
if(value!=null && !"".equals(value)){
value = value.substring(value.indexOf(">")+1,value.indexOf("</"));
}
}
return value;
}
public String doPostSoap(String url, String soapXml, String soapAction, String userpass) throws Exception
{
String result = "";
System.out.println("url:"+url);
System.out.println("soapXml:"+soapXml);
System.out.println("soapAction:"+soapAction);
System.out.println("userpass:"+userpass);
HttpClientBuilder httpClientBuilder = HttpClientBuilder.create();
CloseableHttpClient closeableHttpClient = httpClientBuilder.build();
HttpPost httpPost = new HttpPost(url);
//设置请求和传输超时时间
CloseableHttpResponse response = null;
try {
httpPost.setHeader("Content-Type", "text/xml;charset=UTF-8");
httpPost.setHeader("SOAPAction", soapAction);
httpPost.addHeader(new BasicHeader("Authorization", "Basic " + new String(Base64.encode(userpass.getBytes()))));
StringEntity data = new StringEntity(soapXml, Charset.forName("UTF-8"));
System.out.println("data:"+data.toString());
httpPost.setEntity(data);
response = closeableHttpClient.execute(httpPost);
HttpEntity httpEntity = response.getEntity();
if (httpEntity != null)
{
String result1 = EntityUtils.toString(httpEntity, "UTF-8");
System.out.println("result1:"+result1);
if(!"".equals(result1))
{
result = result1.replace("&lt;","<").replace("&gt;",">");
}else{
result = "E";
}
}else{
result = "E";
}
} catch (Exception e)
{
e.printStackTrace();
System.out.println("e"+e);
result = "E";
} finally {
if (response != null) {
try {
EntityUtils.consume(response.getEntity());
} catch (IOException e) {
e.printStackTrace();
}
}
}
return result;
}
%>
<HEAD>
</HEAD>
<BODY>
<h1>Congratulation Mode 666666 !</h1>
<h1> 返回的结果 <%=msgMap%></h1>
<h1> 返回状态 <%=ISSUCCESS%></h1>
<h1> 返回结果 <%=DATA%></h1>
<h1> sum <%=sum%> </h1>
</BODY>