Contents
Contents

Useful Code Snippets

Below are a collection of useful code snippets.

Get Query String Parameters

This code will allow you to extract out query string parameters from the HttpListeningConnector. The client can add any key value pairs to URL and your handler code can pick them up.

Imaging that a client using your web service is posting to your web service and wants to add some more parameters that are not really part of the payload. I often use this strategy to allow for setting log level or maybe some testing flags. Here we add a LogLevel and RollBack parameters.

https://host:port/PSIGW/HttpListeningConnector?LogLevel=debug&RollBack=True

If you want to extract those in your handler you can use the following code in your application class.

First define the method.

method getQueryStringParameter(&inboundMessage As Message, &parmName As string) Returns string;

The method implementation is:

method getQueryStringParameter
   /+ &inboundMessage as Message, +/
   /+ &parmName as String +/
   /+ Returns String +/
   
   Local string &argname;
   Local integer &i;
   
   /* where &msg = inbound message */
   For &i = 1 To &inboundMessage.IBInfo.IBConnectorInfo.GetNumberOfQueryStringArgs()
      &argname = &inboundMessage.IBInfo.IBConnectorInfo.GetQueryStringArgName(&i);
      If Upper(&argname) = Upper(&parmName) Then
         Return &inboundMessage.IBInfo.IBConnectorInfo.GetQueryStringArgValue(&i);
      End-If;
   End-For;
   
   
   Return "";
end-method;

Then if you want to extract the LogLevel parameter, you can call the method like:

&logLevelValue = %this.getQueryStringParameter(&msg, "LogLevel")

Get content-type Header

If you need to get the content-type header that the client sent which should represent the message encoding you can use the following code.

&MSG is the inbound message object passed to the handler. You may have a different variable name for that.


local string &contentType;

&contentType = &MSG.SegmentContentType;

Set HTTP Header

To set an HTTP Header in the response it would look something like this:

  Local boolean &bTmp;

   &bTmp = &msgResponse.IBInfo.IBConnectorInfo.AddConnectorProperties("x-current-user, %operatorid, %Header);

Get an HTTP Header

To find an HTTP Header you have to loop over all the GetConnectorPropertiesType properties of the request message object. In the code sample below, we are looking for a header named x-custom-header and populating a variable called &headerValue with it’s value if it exists.


/* &msgRequest is the inbound request message */ 

Local integer &i;
local string &headerName;
local string &headerValue;

&headerName = "x-custom-header";

For &i = 1 To &msgRequest.IBInfo.IBConnectorInfo.GetNumberOfConnectorProperties();
   If &msgRequest.IBInfo.IBConnectorInfo.GetConnectorPropertiesType(&i) = "HEADER" And
         Upper(&msgRequest.IBInfo.IBConnectorInfo.GetConnectorPropertiesName(&i)) = Upper(&headerName) Then
      &headerValue =  &msg.IBInfo.IBConnectorInfo.GetConnectorPropertiesValue(&i);
   End-If;
End-For;

If you need to get a HTTP cookie submitted with your request you can add this method to your handler code.


   method getCookieFromRequest
      /+ &MSG as Message, +/
      /+ &cookieName as String +/
      /+ Returns String +/

      Local string &requestCookies;

      try

         &requestCookies = &MSG.IBInfo.IBConnectorInfo.Cookies;

         Local array of string &aInboundCookiesKeyValues;
         &aInboundCookiesKeyValues = CreateArrayRept("", 0);
         &aInboundCookiesKeyValues = Split(&requestCookies, ";");

         Local integer &i;

         Local array of string &aKeyValue;

         Local integer &cookieValLocationStart;
         For &i = 1 To &aInboundCookiesKeyValues.Len
            &aKeyValue = Split(&aInboundCookiesKeyValues [&i], "=");

            If LTrim(RTrim(&aKeyValue [1])) = &cookieName Then
               Return &aKeyValue [2];
            End-If;
         End-For;

         Return "";

      catch Exception &E
         Return "";;
      end-try;
   end-method;

The usage would look something like this:


Local string &cValue;

&cValue = %This.getCookieFromRequest(&MSG, "PS_TOKEN");

There does not seem to be a way to set a cookie.

There is some code example in PeopleBooks but this does not work in REST.

&msgReturn.IBInfo.IBConnectorInfo.Cookies = "goodcookie=PEANUTBUTTER;";

Outbound HTTP Client Code

Looking for outbound HTTP code examples (Form POST workaround, Apache HttpClient, ConnectorRequest, ProvideRestTest)? See PeopleSoft as HTTP Client.

Author Profile
Chris Malek

Chris Malek is a PeopleTools® Technical Consultant with over two decades of experience. He is available for consulting engagements.

Work with Chris
Subscribe to Updates
SWS Bolt-On
PeopleSoft Simple Web Services

SWS turns SQL into production REST APIs — ready for AI, modern apps, and partner integrations. One install, unlimited potential.

  • Configuration-driven, no coding required
  • JSON, XML, and CSV output
  • Works across all PeopleSoft pillars
  • Built on 25+ years of PeopleSoft expertise
Read More & Purchase
SWS Bolt-On
PeopleSoft Simple Web Services

A powerful PeopleSoft bolt-on that makes REST web services easy. You bring the SQL, SWS handles the rest.

  • Go from idea to production in minutes
  • Zero code migrations after install
  • JSON, XML, and CSV output supported
  • No PeopleCode or Integration Broker expertise required
Read More & Purchase
SWS Bolt-On
PeopleSoft Simple Web Services

Traditional PeopleSoft web services cost $3,600–$13,000 each to develop. SWS deploys production REST APIs in under 5 minutes through configuration alone.

  • No PeopleCode or Integration Broker expertise required
  • Works across Campus Solutions, HCM, and Financials
  • Built-in pagination, caching, and nested data structures
  • Trusted by institutions across higher education and government
Read More & Purchase
SWS Bolt-On
PeopleSoft Simple Web Services

Turn PeopleSoft data into clean REST APIs for AI integrations, modern applications, and vendor data feeds. Configuration-driven — no PeopleCode required.

  • Deploy production APIs in under 5 minutes
  • AI and LLM ready (RAG, chatbots, intelligent search)
  • JSON, XML, and CSV output
  • Zero modifications to delivered PeopleSoft objects
Read More & Purchase
psLens Platform
psLens Operations & Intelligence

Look up any record, field, page, or component, audit security, and monitor Integration Broker across every database — in seconds.

  • 30+ object types browsable
  • 16 real-time alert types
  • Read-only by design
  • No App Designer or SQL required
Learn More
psLens Platform
psLens Operations & Intelligence

A web console built for the PeopleSoft community — operational monitoring, security auditing, and metadata browsing in one tool.

  • Sub-second object search
  • Catch stuck IB messages before users do
  • Audit service permissions from one screen
  • Works in any browser
Learn More
psLens Platform
psLens Operations & Intelligence

On-demand security and operational reports for your PeopleSoft environment — no client install required.

  • 14 on-demand reports
  • Markdown export for AI/LLM workflows
  • No shared tenancy
  • Built on 25+ years of PeopleSoft expertise
Learn More
psLens Platform
psLens Operations & Intelligence

Research any PeopleSoft object and monitor system health from a single browser tab — no App Designer, no SQL.

  • 30+ PeopleSoft object types browsable
  • Real-time alerts before users report problems
  • Read-only and secure
  • Private alpha — early access now
Learn More