Developing Listening Connector Classes

This section discusses listening connector class development and discusses how to:

  • Build servlet-based and nonservlet-based listening connectors.

  • Invoke listening connectors.

  • Control message routing.

  • Build error handling and logging into listening connectors.

If you require a listening connector that services HTTP requests, build a servlet-based listening connector. A servlet-based listening connector runs in the Servlet container on the web server.

See SDK Connector Examples.

This PeopleBook does not discuss how to install servlets on web servers.

See The servlet documentation for your web server.

Listening connectors must invoke PeopleSoft Integration Broker through the gateway manager Connect method.

IBResponse connect(IBRequest) throws
   GeneralFrameworkException
   DuplicateMessageException
   InvalidMessageException
   MessageMarshallingException 
   MessageUnmarshallingException 
   ExternalSystemContactException 
   ExternalApplicationException

By accessing and modifying key information on the IBRequest, you can control the behavior of transactions as they flow through the integration gateway.

This section describes several dispatching features that you can use to control message routing by modifying the IBRequest from the listening connector, including routing messages to:

  • Other (remote) integration gateways.

  • Specific target connectors.

  • Other PeopleSoft systems.

You can control the routing of a message to another integration gateway by specifying the uniform resource locator (URL) of the gateway in the IBRequest. You might need to forward messages to another gateway so that they can be processed by a remote PeopleSoft Integration Broker system. To do so, specify the URL of this integration gateway as follows:

. . .
IBRequest ibRequest = new IBRequest();
IbRequest.setOperationName("RemoteRoutingTest");
IbRequest.setRequestingNode("SourceSystem");
IbRequest.setPassword("myPassword");
. . .

//Specify the processing of the message to occur from 
//anotherIntegration Gateway.
ibRequest.setRemoteFrameworkURL("https://hostName/PSIGW/
PeopleSoftListeningConnector");

You can also route a message to a specific target connector by modifying the request's ConnectorInfo object as follows:

. . .  
IBRequest ibRequest = new IBRequest();
. . .

// Send a message through the HttpTargetConnector for example.
ConnectorInfo connectorInfo = ibRequest.getConnectorInfo();

connectorInfo.setConnectorClassName("HttpTargetConnector");
connectorInfo.setField("URL","http://www.externalsite.com");
connectorInfo.setField("Method","POST");
. . .

This is sample code for building error handling and logging into listening connectors:

package com.peoplesoft.pt.integrationgateway.listeningconnector;

import ...

public class HttpListeningConnector extends HttpServlet {
      public void doGet(HttpServletRequest req, 
      HttpServletResponse resp) throws ServletException, IOException {
      }

      public void doPost(HttpServletRequest req,
      HttpServletResponse resp) throws ServletException, IOException {

         String actualResponse ="";
         IBRequest request = null;
         IBResponse response = null;

      try {

         String inputString = MiscUtil.readerToString(new 
         InputStreamReader(req.getInputStream()));

         // Log the actual Input String
         Logger.logMessage("HttpListeningConnector: HTTP
         Request", inputString, Logger.STANDARD_INFORMATION);

         HttpListeningConnectorUtility util = new
         HttpListeningConnectorUtility();
         request = util.createIBRequest("XML", req, inputString);

         // Use the GatewayManager to invoke the Integration 
         // Server and return its response.
         GatewayManager conMgr = new GatewayManager();
         response = conMgr.connect(request);

         // Need to get the actual response from the 
         //IBResponse
         actualResponse = response.getContentSectionAt(0);

   } catch (InvalidMessageException ime) {
         ime.printStackTrace();
         actualResponse = getErrorXml(ime);
         Logger.logError("HTTPListeningConnector:
         InvalidMessageException", request, response,
         Logger.STANDARD_GATEWAY_EXCEPTION, ime);

   } catch (ExternalSystemContactException esce) {
         esce.printStackTrace();
         actualResponse = getErrorXml(esce);
         Logger.logError("HTTPListeningConnector: 
         ExternalSystemContactException", request, response,    
         Logger.STANDARD_GATEWAY_EXCEPTION, esce);

   } catch (ExternalApplicationException esee) {
      esee.printStackTrace();
      actualResponse = getErrorXml(esee);
      Logger.logError("HTTPListeningConnector:
      ExternalApplicationException", request, response,
      Logger.STANDARD_GATEWAY_EXCEPTION, esee);

   } catch (MessageMarshallingException mme) {
      mme.printStackTrace();
      actualResponse = getErrorXml(mme);
      Logger.logError("HTTPListeningConnector: 
      MessageMarshallingException", request, response,
      Logger.STANDARD_GATEWAY_EXCEPTION, mme);

   } catch (MessageUnmarshallingException mue) {
      mue.printStackTrace();
      actualResponse = getErrorXml(mue);
      Logger.logError("HTTPListeningConnector: 
      MessageUnmarshallingException", request, response,
      Logger.STANDARD_GATEWAY_EXCEPTION, mue);

   } catch (GeneralFrameworkException gfe)  {
      gfe.printStackTrace();
      actualResponse = getErrorXml(gfe);
      Logger.logError("HTTPListeningConnector: 
      GeneralFrameworkException", request, response,
      Logger.STANDARD_GATEWAY_EXCEPTION, gfe);
   }

   // Return the message to the original requestor that
   //invoked the Servlet
   HttpListeningConnectorUtility.
         sendResponseBackToRequestor(actualResponse, resp);

   // Log the actual output String
   Logger.logMessage("HttpListeningConnector: 
      HTTP Response", actualResponse, Logger.STANDARD_INFORMATION);

   }   // end doPost()
}