The work requires Java to call the WebService interface provided by PeopleSoft, but the PeopleSoft implementers do not provide the Java call case code, SOAPUI can be called, but the Java code has not been written, self-learning and transferred through the Java HTTP Post Simulation method, thanks to Tianya zhouyun0243 and Google!
Import Java.io.bufferedreader;import java.io.file;import Java.io.filereader;import Java.io.ioexception;import Java.io.inputstream;import Java.io.outputstream;import Java.net.httpurlconnection;import java.net.URL;// Jar package to be Commons-io import Org.apache.commons.io.ioutils;public class TestWebService {public static void main (string[] args) {try {soapspecialconnection ();} catch (Exception e) {e.printstacktrace ()}} public static void Soapspecialconnection () throws exception{string s = new String (); StringBuilder SoapHeader = new StringBuilder ();//soapui automatically generated request XML path, write incoming parameter file File = new file ("D:\\1.xml"); BufferedReader reader = null;try {reader = new BufferedReader (new FileReader (file)); String tempstring = null;//reads one line at a time until NULL is read into the file end while ((tempstring = Reader.readline ()) = null) {Soapheader.append ( tempstring);} Reader.close ();} catch (IOException e) {e.printstacktrace ();} finally {if (reader! = null) {try {reader.close ();} catch (IOException E1) {} }}system.out.println ("soapheader=" +soapHeader)///Set the related properties of the SOAP request message//url from the SOAPUI's Request1 raw label post, without a space in the URL string url= "http://10.60.217.86:9527/ dji-hrservice/services/hrservice.hrservicehttpsoap11endpoint/http/1.1 "; URL u = new url (URL); HttpURLConnection conn = (httpurlconnection) u.openconnection (); Conn.setdoinput (true); Conn.setdooutput (true); Conn.setusecaches (false); Conn.setdefaultusecaches (false);//host,content-type, SOAPAction from SOAPUI's request1 raw tag host,content-typ,soapactione get Conn.setrequestproperty ("Host", " 10.60.217.86:9527 "), Conn.setrequestproperty (" Content-type "," Ext/xml;charset=utf-8 "); Conn.setrequestproperty (" Content-length ", String.valueof (Soapheader.length ())) Conn.setrequestproperty (" SOAPAction "," urn: Getworkattendancebyuidanddate "); Conn.setrequestmethod (" POST ");//define output stream outputstream = Conn.getoutputstream () ; if (null! = SoapHeader) {byte[] b = soapheader.tostring (). GetBytes ("Utf-8");//Send SOAP request message Output.write (b, 0, b.length);} Output.flush (); Output.close ();//define input stream, get SOAP response message inputstream input = Conn.getinputStream ();//need to set the encoding format, otherwise it will garbled s=ioutils.tostring (input, "UTF-8"); Input.close (); SYSTEM.OUT.PRINTLN ("Output of xml=" +s);}}
SOAPUI's Request1 's raw tag signal
Call WebService with Java HTTP POST emulation SOAPUI