Friday 17 February 2017

Providing REST Web Service from PeopleSoft



In my last article we have seen how can we consume a 3rd party rest web service in PeopleSoft. In this example we will see how can we provide a REST web service from PeopleSoft.
Here we are using a custom table to send the data based on the request from the external application. We will be using GET method to get the details from this custom table.
Input parameter in the request will be employee id.
Steps:
  1. Create documents for request and response.
  2. Create request and response messages based on the above created documents.
  3. Create REST service.
  4. Create GET service operations.
  5. Give security to Service Operations.
  6. Create handler application class and assign it to the service operation.
  7. Test the REST web service.

  1. Create documents for request and response.
Navigate to PeopleTools → Documents → Documents Builder
Add a new value
Save the changes.
Similarly create a document for response also.
NOTE: If you are creating a document where you have to include the fields of a record then you can got to PeopleTools → Document → Document Utilities → Create Document from Record
  1. Create messages
Navigate to PeopleTools → Integration Broker → Intergration Setup → Messages
Click on Add
Save the changes.
Create a message for response
Click on Add
Save the changes.
  1. Create REST service

Navigate to PeopleTools Integration Broker Integration Setup Services


Click Add

Save the changes.

  1. Create Service Operation
Open the above created service and a service operation.
Click on Add
Save the changes.
Give security to Service Operation
Save the changes.
  1. Create handler application class and assign it to the service operation.
Create a application class to read the employee id from the incoming request and to send back the employee details.
Now use this as handler in the service operation.
Save the changes.
  1. Test the service operation
Open sendmaster or any other web service testing tool
Get the url by clicking validate link
Click on Generate URL
Use this url in sendmaster.
Similarly change the employee id to 2 and test




Monday 13 February 2017

Consume REST Web Service in PeopleSoft

In this example we will see how can we consume a REST web service in PeopleSoft. Before we start we should have some basic idea on REST web service. Unlike the SOAP based web services where we have  request and responses in xml form, here the request will be in form of URI (Uniform Resource Identifier) and the response can be in xml or json etc.
In REST we have four types of operations
GET – To retrieve data
POST – Update Data
PUT – Insert Data
DELETE – Delete Data
For Example:
here the parameter countrycode will vary as per the request.
So, http://services.groupkt.com/state/get/IND/all will give the list of states present in India. Similarly, http://services.groupkt.com/state/get/USA/all will list down all the states present in USA.
Other variant of this service is
There is one more input parameter in the URI stateCode. So, this URI will give details of a state identified by stateCode of country identified by countryCode

There is one more variant also, to search for a particular state in a country.
http://services.groupkt.com/state/search/IND?text=ma will list down all the states in India having text “ma” in them.

Before we go ahead, let us understand the request and response formats. We will be using PeopleTools documents technology to build the request and response messages.
In the request, we have seen that there are three types of input parameters – countryCode, stateCode and texttoSearch
So, our request document will also have three parameters of type String.
In the response, there are four parameters – country, name, abbr, capital
So, our response document will have four parameters of type String.
Steps for Implementation
  1. Create request and response documents

Navigate to PeopleTools Documents Document Builder

Add a New Value


Now, we will add three parameters to it.



Similarly, add the other two parameters also.


Validate and save the document.

Similarly, we will now create a document for the response.


As, we can see, results are under the tag “result”, we will create a document with name result to match the response.












Now, we will create another document which will include the above created document.
In this document we will insert a collection since the results are repeating.





Validate and Save the document.

  1. Create request and response messages

Navigate to PeopleTools Integration Broker Integration Setup Messages

Add a New value


Click Add

Click Save

Similarly, add the message for response.



Click Save

  1. Create REST service

Navigate to PeopleTools Integration Broker Integration Setup Services

Add a New Value



Save the changes.

  1. Create Service Operation
Open the above created service
Click on the highlighted Add button
We have three URI’s for this service
http://services.groupkt.com/state/get/{countryCode}/all
http://services.groupkt.com/state/get/{countryCode}/{stateCode}
http://services.groupkt.com/state/search/{countryCode}?text={text to search}
So, the base URL will be http://services.groupkt.com/state
Save the changes.
Validate the URI’s
Click on Generate URL
Make sure that the url is correct.
Similarly, you can verify other two URL’s
  1. PeopleCode to invoke the REST Service Operation

We have create a simple page to invoke the operation depending on various search options.


PeopleCode



Read the response and write it into file. (In continuation to above code)














The above code is written in “Search States By” FieldChange event.

  1. Test the REST Web Service

Search by Country



Output File:



Search by Country and State



Output File:



Search by Country and Text



Output File: