春风项目四线(合箱线、总装线)
yyt
2024-01-24 01cb633562174ae7390d12b85690a45997f34be7
提交 | 用户 | 时间
55b0cb 1 package com.jcdm.main.webservice.service;
2
3 import org.apache.commons.httpclient.HttpClient;
4 import org.apache.commons.httpclient.UsernamePasswordCredentials;
5 import org.apache.commons.httpclient.auth.AuthScope;
6 import org.apache.commons.httpclient.methods.PostMethod;
7 import org.apache.commons.httpclient.methods.RequestEntity;
8 import org.apache.commons.httpclient.methods.StringRequestEntity;
9 import org.apache.commons.io.IOUtils;
10
11 import java.io.IOException;
12 import java.io.InputStream;
13 import java.io.UnsupportedEncodingException;
14
15 public class ReportingForWork {
16     public static void main(String[] args) throws IOException {
17         String serviceUrl = "http://podqapp.cfmoto.com.cn:50200/XISOAPAdapter/MessageServlet?senderParty=&senderService=BC_MES&receiverParty=&receiverService=&interface=SI_ZPP_CF_BC_001_SYN_OUT&interfaceNamespace=http://cfmoto.com/xi/MES";
18 //        String content = "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:urn=\"urn:sap-com:document:sap:rfc:functions\">\n" +
19 //                "   <soapenv:Header/>\n" +
20 //                "   <soapenv:Body>\n" +
21 //                "      <urn:ZPP_CF_MES_005>\n" +
22 //                "         <!--Optional:-->\n" +
23 //                "         <IV_WERKS>1000</IV_WERKS>\n" +
24 //                "         <!--Optional:-->\n" +
25 //                "         <IV_ZSCTZD>A0055577</IV_ZSCTZD>\n" +
26 //                "      </urn:ZPP_CF_MES_005>\n" +
27 //                "   </soapenv:Body>\n" +
28 //                "</soapenv:Envelope>";
29         String content = "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:urn=\"urn:sap-com:document:sap:rfc:functions\">\n" +
30                 "   <soapenv:Header/>\n" +
31                 "   <soapenv:Body>\n" +
32                 "      <urn:ZPP_BC_001>\n" +
33                 "         <IV_AUFNR>000010569212</IV_AUFNR>\n" +
34                 "          <IV_VORNR>0010</IV_VORNR>\n" +
35                 "           <IV_LMNGA>1</IV_LMNGA>\n" +
36                 "           <IV_XMNGA>0</IV_XMNGA>   \n" +
37                 "         <IV_STATU>1</IV_STATU>  \n" +
38                 "      </urn:ZPP_BC_001>\n" +
39                 "   </soapenv:Body>\n" +
40                 "</soapenv:Envelope>";
41         // HttpClient发送SOAP请求
42         int timeout = 10000;
43         HttpClient client = new HttpClient();
44         //如果需要用户名密码验证;不需要验证登录则不需要以下4行
45         String username = "POMESUSER";
46         String password = "12345tgb";
47         UsernamePasswordCredentials creds = new UsernamePasswordCredentials(username, password);
48         client.getState().setCredentials(AuthScope.ANY, creds);
49
50         PostMethod postMethod = new PostMethod(serviceUrl);
51         // 设置连接超时
52         client.getHttpConnectionManager().getParams().setConnectionTimeout(timeout);
53         // 设置读取时间超时
54         client.getHttpConnectionManager().getParams().setSoTimeout(timeout);
55         // 然后把Soap请求数据添加到PostMethod中
56         RequestEntity requestEntity = new StringRequestEntity(content, "text/xml", "UTF-8");
57
58         // 设置请求头部,否则可能会报 “no SOAPAction header” 的错误
59         postMethod.setRequestHeader("SOAPAction", "");
60         // 设置请求体
61         postMethod.setRequestEntity(requestEntity);
62         int status = client.executeMethod(postMethod);
63
64         if (status == 200) {// 成功
65             InputStream is = postMethod.getResponseBodyAsStream();
66             // 获取请求结果字符串
67             String result = IOUtils.toString(is);
68 //            String jsonStr = xmlToJSON2(result);
69 //            Gson gson = new Gson();
70 //            // 将json字符串转换成对象
71 //            ItemList itemList = gson.fromJson(jsonStr, ItemList.class);
72             System.out.println("返回结果:" + result);
73         } else {
74             System.out.println("错误代码:" + status + ":" + postMethod.getResponseBodyAsString());
75         }
76     }
77 }
78