PeopleSoft Web Services – Java Client

Below is the working script of the PeopleSoft Web Services Java Client with WSSE Authentication aling with custom namespaces and body elements :

package com.psclient;

import java.io.ByteArrayOutputStream;

import javax.xml.soap.MessageFactory;
import javax.xml.soap.SOAPBody;
import javax.xml.soap.SOAPConnection;
import javax.xml.soap.SOAPConnectionFactory;
import javax.xml.soap.SOAPElement;
import javax.xml.soap.SOAPEnvelope;
import javax.xml.soap.SOAPMessage;
import javax.xml.soap.SOAPPart;

import org.apache.ws.security.WSConstants;
import org.apache.ws.security.message.WSSecHeader;
import org.apache.ws.security.message.WSSecUsernameToken;

public class SOAPCredClient {
public static void main(String[] args) throws Exception {
getMarketParticipantList();
}

private static void getMarketParticipantList() throws Exception {

final String endpoint = “http://<host>/module/PeopleSoftServiceListeningConnector”;

SOAPConnectionFactory sfc = SOAPConnectionFactory.newInstance();
SOAPConnection connection = sfc.createConnection();
SOAPMessage soapMessage = MessageFactory.newInstance().createMessage();
SOAPPart soapPart = soapMessage.getSOAPPart();
SOAPEnvelope soapEnvelope = soapPart.getEnvelope();
soapEnvelope.addNamespaceDeclaration(“namespace1”, “http://xmlns.oracle.com/Enterprise/Tools/schemas/custom_schema”);
soapEnvelope.addNamespaceDeclaration(“namespace2”, “http://xmlns.oracle.com/Enterprise/Tools/schemas/custom schema”);
/*Forming the message body*/

SOAPBody soapBody = soapEnvelope.getBody();

SOAPElement elemnt = soapBody.addChildElement(“Request_message”, “namespace2”);
SOAPElement elemnt2 = elemnt.addChildElement(“PERSON_RQST_PART”,”namespace2″);
SOAPElement element3 = elemnt2.addChildElement(“Personnel”,”namespace2″);
element3.setAttribute(“class”, “R”);
SOAPElement element4 = element3.addChildElement(“EmployeeID”,”namespace2″);
element4.addTextNode(“1234”);
SOAPPart soappart = soapMessage.getSOAPPart();
WSSecHeader wsheader = new WSSecHeader();
wsheader.insertSecurityHeader(soappart);
WSSecUsernameToken token = new WSSecUsernameToken();
token.setPasswordType(WSConstants.PASSWORD_TEXT);
token.setUserInfo(“username”, “passqword!”);
token.build(soappart, wsheader);

soapMessage.getMimeHeaders().addHeader(“SOAPAction”, “soap header name”);
SOAPMessage response = connection.call(soapMessage, endpoint);

ByteArrayOutputStream out = new ByteArrayOutputStream();
String xml = “”;
try {
response.writeTo(out);
soapMessage.writeTo(out);

xml = out.toString(“UTF-8”);
} catch (Exception e)
{
System.out.println(“”+e);
}

System.out.println(“”+xml);
}

}

One thought on “PeopleSoft Web Services – Java Client

  • March 27, 2013 at 3:02 pm
    Permalink

    Worked…great thank you..

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *