Additional Feed Examples

This section provides examples of the following: Implementing a real-time feed request handler.

The following example implements a real-time feed request handler from the IRequestHandler superclass.

Important! For typical real-time feed requests, the default feed service operation (PTFP_GETFEED) and feed request handler should be sufficient. Unless there is specific functionality that is needed for a real-time feed request, use the default feed service operation. For scheduled feeds, the default service operation and hence the request handler cannot be modified.

import PS_PT:Integration:IRequestHandler;
import PTFP_FEED:UTILITY:Utility;
import PTFP_FEED:XML_FEED:FeedDoc;
import PTFP_FEED:UTILITY:FeedRequest;
import PTFP_FEED:Interface:IBGetFeedList;
import PTFP_FEED:FeedFactory;
import PTFP_FEED:EXCEPTION:*;


class MyFeedHandler implements PS_PT:Integration:IRequestHandler
   /* --- Properties --- */
   
   /* --- Methods --- */
   method MyFeedHandler();
   method OnRequest(&pRequestMsg As Message) Returns Message;
   method OnError(&pRequestMsg As Message) Returns string;
end-class;


/** onRequest is defined. Other methods shown as stubs. **/


method MyFeedHandler
   
   /* method stub */
   
end-method;


method OnError
   /+ &pRequestMsg as Message +/
   /+ Returns String +/
   /+ Extends/implements PS_PT:Integration:IRequestHandler.OnError +/
   Local string &errstring;
   /* method stub */
   Return &errstring;
end-method;


/**
  * onRequest
  *
  * @param pRequestMsg Request Message.
  *
  * @exception FeedException thrown if switch user failed.
  *
  * @return Message Feed Document.
  *
  */
method OnRequest
   /+ &pRequestMsg as Message +/
   /+ Returns Message +/
   /+ Extends/implements PS_PT:Integration:IRequestHandler.OnRequest +/
   
   Local boolean &succeeded;
   Local integer &i;
   Local string &temp, &name, &value;
   Local string &errorText;
   Local string &ibTransID, &pageNum, &HTTP_IfNoneMatch, &HTTP_IfModifiedSince, &DefaultLocalNode;
   
   Local Message &responseMsg;
   Local XmlDoc &xmlDoc;
   
   Local PTFP_FEED:FeedFactory &feedFactory_inst;
   Local PTFP_FEED:UTILITY:Utility &utility = &feedFactory_inst.Utility;
   Local PTFP_FEED:XML_FEED:FeedDoc &feedDoc;
   Local PTFP_FEED:UTILITY:FeedRequest &request;
   Local PTFP_FEED:Interface:IBGetFeedList &feedListObj;
   
   
   /* Ccreate the Search Request object */
   &request = create PTFP_FEED:UTILITY:FeedRequest("FeedRequest");
   
   
   /* Get the search criteria */
   For &i = 1 To &pRequestMsg.IBInfo.IBConnectorInfo.GetNumberOfQueryStringArgs()
      
      &name = &pRequestMsg.IBInfo.IBConnectorInfo.GetQueryStringArgName(&i);
      &value = &pRequestMsg.IBInfo.IBConnectorInfo.GetQueryStringArgValue(&i);
      &succeeded = &request.addParameter(&name, &value);
      
      
      Evaluate Upper(&name)
      When Upper(&utility.QUERYPARAMETER_FEEDLIST)
         /* Feed List Request, forward the call */
         &feedListObj = create PTFP_FEED:Interface:IBGetFeedList();
         Return &feedListObj.OnRequest(&pRequestMsg);
         
      When Upper(&utility.QUERYPARAMETER_PORTALNAME)
         &request.PortalName = &value;
         Break;
         
      When Upper(&utility.QUERYPARAMETER_NODENAME)
         &request.NodeName = &value;
         Break;
         
      When Upper(&utility.QUERYPARAMETER_DATATYPEID)
         &request.DataTypeID = &value;
         Break;
         
      When Upper(&utility.QUERYPARAMETER_FEEDID)
         &request.FeedID = &value;
         Break;
         
      When Upper(&utility.QUERYPARAMETER_LANGUAGE)
         &request.LanguageCode = &value;
         Break;
         
      When Upper(&utility.QUERYPARAMETER_IBTRANSID)
         &ibTransID = &value;
         Break;
         
      When Upper(&utility.QUERYPARAMETER_PAGENUM)
         &pageNum = &value;
         Break;
         
      When Upper(&utility.QUERYPARAMETER_DEFLOCALNODE)
         &DefaultLocalNode = &value;
         Break;
         
         /* HTTP Conditonal Headers */
      When Upper(&utility.QUERYPARAMETER_IFNONEMATCH)
         &HTTP_IfNoneMatch = &value;
         Break;
         
      When Upper(&utility.QUERYPARAMETER_IFMODIFIEDSINCE)
         &HTTP_IfModifiedSince = &value;
         Break;
         
      End-Evaluate;
   End-For;
   
   
   /* Get the current user PS_TOKEN */
   &request.PS_TOKEN = GenToken();
   
   
   /* Get the FeedDoc */
   &errorText = "";
   
   try
      
      &feedDoc = &feedFactory_inst.getFeedDoc(&request);
      
   catch PTFP_FEED:EXCEPTION:NotFoundException &ex1
      &errorText = MsgGetExplainText(219, 3112, "(Message not found) Not Found");
      
   catch PTFP_FEED:EXCEPTION:PrivilegeException &ex2
      &errorText = MsgGetExplainText(219, 3113, "(Message not found) Not Authorized");
      
   catch PTFP_FEED:EXCEPTION:FeedException &ex3
      &errorText = &utility.getExceptionText(&ex3);
      
   end-try;
   
   
   /* Create the response message */
   &responseMsg = CreateMessage(Operation.PTFP_GETFEED, %IntBroker_Response);
   
   If None(&errorText) Then
      &responseMsg = &utility.setMessageHeadersAndMimeType(&responseMsg, &feedDoc, &request);
   Else
      &temp = "<?xml version='1.0' encoding='UTF-8'?><ErrorMessage>" | &errorText | "</ErrorMessage>";
      &xmlDoc = CreateXmlDoc(&temp);
      &responseMsg.SetXmlDoc(&xmlDoc);
      &responseMsg.SegmentContentType = &utility.MIMETYPE_XML;
   End-If;
   
   Return &responseMsg;
   
end-method;