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.Read More & Purchase
Below are a collection of useful code snippets.
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.
RESTListeningConnectorbecause you define all allowed parameters in the service operation configuration and those are mapped to a
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
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")
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;
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);
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 )) = &cookieName Then Return &aKeyValue ; 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;";