第一步: 导入依赖包
导入maven httpclient依赖包
<!-- httpclient-->
<dependency>
<groupId>commons-httpclient</groupId>
<artifactId>commons-httpclient</artifactId>
<version>3.1</version>
</dependency>
第二步:编写响应信息PO类
/**
* 人事流程管理对接ps:响应参数
* @author fanruxian
* @date 2021/11/25
*/
@Data
public class ProcessSendRes {
// 响应代码
private String statusCode;
// 响应消息
private String message;
// 公司ID
private String companyId;
// 部门ID
private String deptId;
//职位号码
private String positionNbr;
}
第三步:编写util用来拼接报文
/**
* 人事流程公司相关ps对接接口:新增公司,公司更名,公司撤销
*
* @author fanruxian
* @date 2021/11/25
*/
public class ProcessOrgUtil {
/**
* 新增公司
*
* @param url 地址
* @param deScr 公司描述
* @param desScrShort 公司简短描述
* @param commAp 组织映射代码
* @param parCompanyId 组织映射代码
* @return 响应参数
*/
public static ProcessSendRes orgCreate(String url, String deScr, String desScrShort, String commAp, String parCompanyId) {
ProcessSendRes processSendRes = new ProcessSendRes();
String soapRequestData = "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:sch=\"http://xmlns.oracle.com/Enterprise/Tools/schemas\">"
+ "<soapenv:Header/>"
+ " <soapenv:Body>"
+ " <sch:GATECOMPANYADD>"
+ " <descr>" + deScr + "</descr>"
+ " <descrshort>" + desScrShort + "</descrshort>"
+ " <commap>" + commAp + "</commap>"
+ " <parcompanyid>" + parCompanyId + "</parcompanyid>"
+ " </sch:GATECOMPANYADD>"
+ " </soapenv:Body>"
+ "</soapenv:Envelope>";
System.out.println("soapRequestData=" + soapRequestData);
PostMethod postMethod = new PostMethod(url + "/PSIGW/PeopleSoftServiceListeningConnector/C_GATE_SYNC.1.wsdl");
try {
byte[] b = soapRequestData.getBytes("utf-8");
InputStream is = new ByteArrayInputStream(b, 0, b.length);
org.apache.commons.httpclient.methods.RequestEntity re = new InputStreamRequestEntity(is, b.length, "text/xml;charset=utf-8");
postMethod.setRequestEntity(re);
postMethod.setRequestHeader("soapAction", "命名空间");
HttpClient httpClient = new HttpClient();
int status = httpClient.executeMethod(postMethod);
InputStream in = postMethod.getResponseBodyAsStream();
DocumentBuilderFactory bf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = bf.newDocumentBuilder();
Document document = db.parse(in);
final NodeList soapenv1 = document.getElementsByTagName("方法");
final NodeList childNodes = soapenv1.item(0).getChildNodes();
String statusCode = childNodes.item(0).getTextContent();
String message = childNodes.item(1).getTextContent();
String companyId = childNodes.item(2).getTextContent();
processSendRes.setStatusCode(statusCode);
processSendRes.setMessage(message);
processSendRes.setCompanyId(companyId);
System.out.println(statusCode + "\n" + message);
} catch (Exception e) {
processSendRes.setMessage(e.getMessage());
e.printStackTrace();
}
return processSendRes;
}