This document describes a simple example on how to provide a REST web service from PeopleSoft.
We are going to provide a service that returns the ISO2 code and the name of a country. The input will be an ISO3 country code.
Content
- Step 1: Define
documents
- Step 2: Define
messages
- Step 3: Create
service
- Step 3a: Define
security
- Step 3b: Set
request parameters
- Step 3c: Set
response parameters
- Step 4: Create a
handler
- Step 4a: Write
handler code
- Step 5: Provide
the REST service
- Step 6: Testing
Step 1: Define documents
Define documents for input and output messages. Go to: PeopleTools > Documents > Documents Builder
Create a new document with the following parameters, this will be the request:
Package | C_COUNTRY_INFO_REST_PKG |
Document Name | C_COUNTRY_INFO_REQ |
Version Name | v1 |
Set the root element to request and create a primitive called country_code_iso3. This should be a string of length 3.
On the JSON tab set the JSON label also to request.
Create a second document with the following parameters, this will be the response:
Package | C_COUNTRY_INFO_REST_PKG |
Document Name | C_COUNTRY_INFO_RESP |
Version Name | v1 |
Add two primitives here called country_code_iso2 and description. Make sure to set the proper type and length.
Step 2: Define messages
Go to: PeopleTools > Integration Broker > Integration Setup > Messages
Create two messages one for the request and one for the response. The request:
The response:
Step 3: Create service
Go to: PeopleTools > Integration Broker > Integration Setup > Services
Create a new web service named C_COUNTRY_INFO_REST. Don’t forget to check the Is Provider checkbox.
Save the service and add a new service operation named C_GET_COUNTRY_INFO:
On the general tab you have to do a couple of things:
- Define security
- Set request parameters
- Set response parameters
Step 3a: Define security
Click on the Service Operation Security link and assign a permission list to the service operation. The user that calls the service must have this permission list assigned via a role to be able to execute the operation.
Step 3b: Set request parameters
In the URI scroll fill in, use the following as a template: country/{country_code_iso3}
The REST base URL is pre-populated. Your REST service will later be available on a URL which is the combination of the base URL and the template. In this example, if you want to query the Netherlands it will be:
http://*******:9084/PSIGW/RESTListeningConnector/PSFT_CORE/C_GET_COUNTRY_INFO.v1/country/NLD
As document template use the created request message.
Step 3c: Set response parameters
For the response setup use the created response message and set content-type to application/json.
Step 4: Create a handler
On the “Handlers” tab of the service operation you have to link an application class which handles the requests and returns a response.
In Application Designer create an application package like in the example below:
As code use some place holder code so you can save the application package:
import PS_PT:Integration:IRequestHandler;
class Country implements PS_PT:Integration:IRequestHandler
method Country();
method OnRequest(&MSG As Message) Returns Message;
end-class;
/* constructor */
method Country
end-method;
method OnRequest
/+ &MSG as Message +/
/+ Returns Message +/
/+ Extends/implements PS_PT:Integration:IRequestHandler.OnRequest +/
/* Variable Declaration */
Return Null;
end-method;
Now on the “Handlers” tab link the application package to the service operation as shown below.
Click on details and fill in the parameters as shown.
Step 4a: Write handler code
Now you can finish the handler code. See the example below.
import PS_PT:Integration:IRequestHandler; class Country implements PS_PT:Integration:IRequestHandler method Country(); method OnRequest(&MSG As Message) Returns Message; end-class; /* constructor */ method Country end-method; method OnRequest /+ &MSG as Message +/ /+ Returns Message +/ /+ Extends/implements PS_PT:Integration:IRequestHandler.OnRequest +/ /* Variable Declaration */ Local string &strISO3; Local Record &rcdCountryTbl; Local Document &docReq, &docResp; Local Compound &compReq, &compResp; Local Message &msgResp; /* Get input parameters from request */ &docReq = &MSG.GetURIDocument(); &compReq = &docReq.DocumentElement; &strISO3 = &compReq.GetPropertyByName("country_code_iso3").value; /* Message */ If &MSG.HTTPMethod = %IntBroker_HTTP_GET Then /* Get ISO2 and country description */ &rcdCountryTbl = CreateRecord(Record.COUNTRY_TBL); &rcdCountryTbl.COUNTRY.Value = &strISO3; If &rcdCountryTbl.SelectByKey() Then /* Create response mesage*/ &msgResp = CreateMessage(Operation.C_GET_COUNTRY_INFO_GET, %IntBroker_Response); /* Get document and root compound */ &docResp = &msgResp.GetDocument(); &compResp = &docResp.DocumentElement; /* Set primitives */ &compResp.GetPropertyByName("country_code_iso2").Value = Left(&rcdCountryTbl.COUNTRY_2CHAR.Value, 2); &compResp.GetPropertyByName("description").Value = Left(&rcdCountryTbl.DESCR.Value, 100); Else /* Do something to handle non existing countries.... this is not implemented in this example */ /* Only the happy flow works */ End-If; End-If; /* Return response */ Return &msgResp; end-method;
Step 5: Provide the REST service
Go to: PeopleTools > Integration Broker > Web Service > Provide Web Service
Here search for the REST web service and go through the wizard to publish the service. This will provide a WADL which you can use to provide to 3rd parties so they can integrate.
Step 6: Testing
Like mentioned in step 3b you can now use the following URL to test your service:
http://<serverIP>:port/PSIGW/RESTListeningConnector/PSFT_CORE/C_GET_COUNTRY_INFO.v1/country/NLD
Just copy and paste it in your browser and you will get the result shown below:
For more thorough testing you can use a tool like SoapUI:
No comments:
Post a Comment