Author Info
Chris Malek

Chris Malek is a PeopleTools® Technical Consultant with two decades of experience working on PeopleSoft enterprise software projects. He is available for consulting engagements.

About Chris Work with Chris
Looking for pain-free PeopleSoft web services? 😀
PeopleSoft Simple Web Services (SWS)

Introducing a small but powerful PeopleSoft bolt-on that makes web services very easy. If you have a SQL statement, you can turn that into a web service in PeopleSoft in a few minutes.

Contents

REST Run-time Detection and Code Samples

This section is going to cover some code samples related to REST handlers.

Detecting if the Handler is running under REST or HTTP Context

There are time where you may need to create a Service Operation Handler that serves both REST and HTTP services. Most of the code in the handler might be the same between those two. The real difference is generally how you detect parameters. This can be useful when you do not want to duplicate code and you need to serve legacy and new clients. This section will not pertain to all readers in practice.

First let’s take a look at how we can determine at run-time if the service is running under a REST web service setup. You can call the GetURIDocument() method on the Request message object. If it throws and error then you know you are NOT running under REST and you can assume HTTP. Here is a code sample. You will see that we have a try/catch block. Often times, you will have a try/catch block wrapping your entire onRequest handler which is NOT in this code sample. This “Is running under REST context” check needs to have it’s own nested try/catch block so it does not bubble up to the parent.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import PS_PT:Integration:IRequestHandler;

class syncTest implements PS_PT:Integration:IRequestHandler
   method onRequest(&msgRequest As Message) Returns Message;
end-class;

method onRequest
   /+ &msgRequest as Message +/
   /+ Returns Message +/
   /+ Extends/implements PS_PT:Integration:IRequestHandler.OnRequest +/


   Local Message &msgReturn;
   &msgReturn = CreateMessage(@("Operation." | &msgRequest.OperationName), %IntBroker_Response);


   Local XmlDoc &xmlout;
   &xmlout = CreateXmlDoc("<?xml version='1.0'?><response/>");


   local boolean &bIsREST = false;

   try
      local Document &reqURIDoc;
      &reqURIDoc = &msgRequest.GetURIDocument();
      &bIsREST = True;
   catch Exception &e
      &bIsREST = False;
   end-try;


   &response.SetXmlDoc(&xmlout);
   Return &response;

end-method;

Detecting REST method

There are a few ways to structure your REST Services when you have multiple Methods:

  • GET
  • POST
  • DELETE

You can:

  • Have a different handler for each HTTP Method - (I don’t recommend this)
  • Have a one handler that processes all methods. (Recommended)

When you have a single handler processing different HTTP Methods you are going to need to detect the HTTP Method at run-time and take the appropriate action. Here is a code sample that shows how to detect the HTTP Method.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import PS_PT:Integration:IRequestHandler;

class syncTest implements PS_PT:Integration:IRequestHandler
   method onRequest(&msgRequest As Message) Returns Message;
end-class;

method onRequest
   /+ &msgRequest as Message +/
   /+ Returns Message +/
   /+ Extends/implements PS_PT:Integration:IRequestHandler.OnRequest +/


   Local Message &msgReturn;
   &msgReturn = CreateMessage(@("Operation." | &msgRequest.OperationName), %IntBroker_Response);


   Local XmlDoc &xmlout;
   &xmlout = CreateXmlDoc("<?xml version='1.0'?><response/>");

    Evaluate %This.getRequestMessage().HTTPMethod
      When %IntBroker_HTTP_GET
         /* do some logic */
         Break;
      When %IntBroker_HTTP_POST
         /* do some logic */
         Break;
      When %IntBroker_HTTP_DELETE
         /* do some logic */
         Break;
      When %IntBroker_HTTP_PUT
         /* do some logic */
         Break;
         
      When %IntBroker_HTTP_HEAD
         /* do some logic */
         break;
    End-Evaluate;
 

   &response.SetXmlDoc(&xmlout);
   Return &response;

end-method;

Detecting Content Type

  • TODO

Detecting Accept Type

  • TODO