1、peopleSoft系统webservice发布成功后,会提供一个wsdl URL地址,如:
5、测试运行环境:
2、利用SOAPUI工具,可查看出SOAP请求XML,
3、java客户端可以模拟SOAP请求,注意以下几点:
3.1 请求URL地址并非是wsdl地址,而是“
http://IP:port/PSIGW/PeopleSoftServiceListeningConnector/XXX”
3.2 请求时需要设置请求的header,SOAPAction=XXXXX,
3.3 遵循SOAPUI中的RAW窗口展示的请求方式,如下图
4、代码实现如下:
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpException;
import org.apache.commons.httpclient.methods.InputStreamRequestEntity;
import org.apache.commons.httpclient.methods.PostMethod;
import org.w3c.dom.Document;
public class WebServiceClient {
public static void main(String[] args) throws Exception {
test2();
}
public static void test2() throws Exception {
String soapRequestData = "<soapenv:Envelope xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/' xmlns:bl='http://xmlns.oracle.com/Enterprise/Tools/schemas/BL_MRYSTS_REQAPRVL_REQ.V1'> "
+ " <soapenv:Header/> "
+ " <soapenv:Body> "
+ " <parameter> "
+ " <bl:EMPLID>10086</bl:EMPLID> "
+ " <bl:APRVLSTS>SUB</bl:APRVLSTS>"
+ " <bl:MRYSTS>S</bl:MRYSTS>"
+ " </parameter>"
+ " </soapenv:Body>"
+ " </soapenv:Envelope>";
System.out.println("soapRequestData=" + soapRequestData);
PostMethod postMethod = new PostMethod("http://IP:port/PSIGW/PeopleSoftServiceListeningConnector/PSFT_HR");
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", "BL_MRYSTS_REQAPRVL.v1");
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);
String res = document.getElementsByTagName("ResponseInfo").item(0)
.getTextContent();
System.out.println(res);
System.out.println(in);
System.out.println(status);
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (HttpException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}
5、测试运行环境:
JDK1.7,
所需jar包,maven地址如下:
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.1.1</version>
</dependency>
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
<version>1.4</version>
</dependency>
<dependency>
<groupId>commons-httpclient</groupId>
<artifactId>commons-httpclient</artifactId>
<version>3.1</version>
</dependency>