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

137 lines
5.3 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=S4QCLNT600&receiverParty=&receiverService=&interface=S4MdmPnoService_Out_Syn&interfaceNamespace=urn:shenghong:S4:MDM";
String url = "http://poqassrv.shenghongtec.com:50000/XISOAPAdapter/MessageServlet?senderParty=&senderService=SH_NC_QAS&receiverParty=&receiverService=&interface=mdmPnoService_Out_Syn&interfaceNamespace=urn:shenghong.NC:MDM";
//
String val = "{\"employees\":[{\"name\":\"李欣三\",\"sex\":\"女\",\"telephone\":\"18130726151\",\"phone\":\"18130726151\",\"job\":\"\",\"isjob\":\"在职\",\"mail\":\"\",\"identity\":\"341204200209191255\",\"datasource\":\"nc\",\"job_block\":\"1\"}]}";
// 获取工号的入参
// {"employees":[{"name":"赵萃","sex":"女","telephone":"XXXXX","phone":"XXXXX","job":"","isjob":"在职","mail":"","identity":"XXXXX","datasource":"nc","job_block":"1"},{"name":"浦桃美","sex":"女","telephone":"XXX","phone":"XXX","job":"","isjob":"在职","mail":"","identity":"XXXX","datasource":"nc","job_block":"1"}]}
String action = "SAP";
String xml = "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:com=\"com.pcitc.services.pno\">\n" +
" <soapenv:Header/>\n" +
" <soapenv:Body>\n" +
" <com:createEmpNo>\n" +
" <com:param1></com:param1>\n" +
" <com:param2>SAP</com:param2>\n" +
" <com:param3>"+val+"</com:param3>\n" +
" </com:createEmpNo>\n" +
" </soapenv:Body>\n" +
"</soapenv:Envelope>";
String usr_pwd = "po_sender:posender0807" ;
String soapAction = "";
Map<String,String> msgMap = doPostSoap(url,xml,soapAction,usr_pwd);
sum++;
%>
<%!
public Map<String,String> doPostSoap(String url, String soapXml, String soapAction, String userpass) throws Exception
{
Map<String,String> msgMap = new HashMap<String,String>();
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);
//设置请求和传输超时时间
String result = "";
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)
{
result = EntityUtils.toString(httpEntity, "UTF-8");
System.out.println("result:"+result);
if(!"".equals(result))
{
result = result.replace("&lt;","<").replace("&gt;",">");
msgMap.put("result",result);
}else{
msgMap.put("code","-100");
msgMap.put("sqlcode","-100");
msgMap.put("description","ERP接口返回值为空");
}
}else{
msgMap.put("code","-200");
msgMap.put("sqlcode","-200");
msgMap.put("description","ERP接口返回值为空");
}
} catch (Exception e)
{
e.printStackTrace();
System.out.println("e"+e);
msgMap.put("code","-200");
msgMap.put("sqlcode","-200");
msgMap.put("description","ERP接口调用异常:"+e);
} finally {
if (response != null) {
try {
EntityUtils.consume(response.getEntity());
} catch (IOException e) {
e.printStackTrace();
}
}
}
return msgMap;
}
%>
<HEAD>
</HEAD>
<BODY>
<h1>Congratulation Mode 666666 !</h1>
<h1> 获取工号的 </h1>
<h1> 返回结果 <%=msgMap%></h1>
<h1> sum <%=sum%> </h1>
</BODY>