package com.jcdm.main.webservice.service;
|
|
import org.apache.commons.httpclient.HttpClient;
|
import org.apache.commons.httpclient.UsernamePasswordCredentials;
|
import org.apache.commons.httpclient.auth.AuthScope;
|
import org.apache.commons.httpclient.methods.PostMethod;
|
import org.apache.commons.httpclient.methods.RequestEntity;
|
import org.apache.commons.httpclient.methods.StringRequestEntity;
|
import org.apache.commons.io.IOUtils;
|
|
import java.io.IOException;
|
import java.io.InputStream;
|
import java.io.UnsupportedEncodingException;
|
|
public class ReportingForWork {
|
public static void main(String[] args) throws IOException {
|
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";
|
// String content = "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:urn=\"urn:sap-com:document:sap:rfc:functions\">\n" +
|
// " <soapenv:Header/>\n" +
|
// " <soapenv:Body>\n" +
|
// " <urn:ZPP_CF_MES_005>\n" +
|
// " <!--Optional:-->\n" +
|
// " <IV_WERKS>1000</IV_WERKS>\n" +
|
// " <!--Optional:-->\n" +
|
// " <IV_ZSCTZD>A0055577</IV_ZSCTZD>\n" +
|
// " </urn:ZPP_CF_MES_005>\n" +
|
// " </soapenv:Body>\n" +
|
// "</soapenv:Envelope>";
|
String content = "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:urn=\"urn:sap-com:document:sap:rfc:functions\">\n" +
|
" <soapenv:Header/>\n" +
|
" <soapenv:Body>\n" +
|
" <urn:ZPP_BC_001>\n" +
|
" <IV_AUFNR>000010569212</IV_AUFNR>\n" +
|
" <IV_VORNR>0010</IV_VORNR>\n" +
|
" <IV_LMNGA>1</IV_LMNGA>\n" +
|
" <IV_XMNGA>0</IV_XMNGA> \n" +
|
" <IV_STATU>1</IV_STATU> \n" +
|
" </urn:ZPP_BC_001>\n" +
|
" </soapenv:Body>\n" +
|
"</soapenv:Envelope>";
|
// HttpClient发送SOAP请求
|
int timeout = 10000;
|
HttpClient client = new HttpClient();
|
//如果需要用户名密码验证;不需要验证登录则不需要以下4行
|
String username = "POMESUSER";
|
String password = "12345tgb";
|
UsernamePasswordCredentials creds = new UsernamePasswordCredentials(username, password);
|
client.getState().setCredentials(AuthScope.ANY, creds);
|
|
PostMethod postMethod = new PostMethod(serviceUrl);
|
// 设置连接超时
|
client.getHttpConnectionManager().getParams().setConnectionTimeout(timeout);
|
// 设置读取时间超时
|
client.getHttpConnectionManager().getParams().setSoTimeout(timeout);
|
// 然后把Soap请求数据添加到PostMethod中
|
RequestEntity requestEntity = new StringRequestEntity(content, "text/xml", "UTF-8");
|
|
// 设置请求头部,否则可能会报 “no SOAPAction header” 的错误
|
postMethod.setRequestHeader("SOAPAction", "");
|
// 设置请求体
|
postMethod.setRequestEntity(requestEntity);
|
int status = client.executeMethod(postMethod);
|
|
if (status == 200) {// 成功
|
InputStream is = postMethod.getResponseBodyAsStream();
|
// 获取请求结果字符串
|
String result = IOUtils.toString(is);
|
// String jsonStr = xmlToJSON2(result);
|
// Gson gson = new Gson();
|
// // 将json字符串转换成对象
|
// ItemList itemList = gson.fromJson(jsonStr, ItemList.class);
|
System.out.println("返回结果:" + result);
|
} else {
|
System.out.println("错误代码:" + status + ":" + postMethod.getResponseBodyAsString());
|
}
|
}
|
}
|