Example 2: Using the HTTP Connectors

This section discusses how to:

  • Use the HTTP listening connector.

  • Use the HTTP target connector.

When using the examples for using the HTTP target connector, an HTTP server is needed to receive the HTTP request and to return a response. If using the SOAP example, the HTTP server must be able to process SOAP messages.

This section provides examples of how to set credentials for HTTP requests coming into the integration gateway, and discusses how to:

  • Set credentials in message bodies.

  • Set credentials in HTTP headers.

  • Set credentials in query strings.

  • Set credentials in SOAP-specific HTTP headers.

Setting Up for Using the HTTP Listening Connector Examples

In the PeopleSoft Pure Internet Architecture, for service operation EXAMPLE_SERVICE_OPR add a handler of type OnRequest with implementation type application Class. Create a handler application class based on the IRequestHandler interface, and for the method OnRequest add following PeopleCode


   Local XmlDoc &xmldoc;
   Local File &theFile;
   Local XmlNode &rootNode, &descNode;
   Local Message &response;
   Local string &xmldata;
   
   /* get the body of the incoming message */
   &xmldoc = &_MSG.GetXmlDoc();
   
   /* and write it out to a file */
   &theFile = GetFile("HttpRequest.txt", "W");
   &theFile.WriteString(&xmldoc.GenXmlString());
   &theFile.Close();
   
   /* create the response message */
   &response = CreateMessage(Operation.EXAMPLE_SERVICE_OPR, 
     %IntBroker_Response);
   
   /* create the body for the response message */
   &xmldata = "<?xml version='1.0'?><ConnectorTest/>";
   &xmldoc = CreateXmlDoc(&xmldata);
   &rootNode = &xmldoc.DocumentElement;
   &descNode = &rootNode.AddElement("ResponseMessage");
   &descNode.NodeValue = "This was generated in the OnRequest event.";
   
   /* add the body to the message */
   &response.SetXmlDoc(&xmldoc);
   
   /* and return the response message */   
   Return &response;

Setting Credentials in the Message Body

To set HTTP request credentials in the message body:

  1. Start Send Master, and create a new Input File project.

  2. In the URL field enter:

    http://<your_server_name>/PSIGW/HttpListeningConnector

    Replace <your_server_name> with the details of the server where the integration gateway is running. For example:

    http://machine1234/PSIGW/HttpListeningConnector
  3. In the Input section, paste the following XML. Notice that the service operation name and requesting node are present in the XML.

    <?xml version="1.0"?> 
    <IBRequest>    
      <ExternalOperationName>EXAMPLE_SERVICE_OPR.v1</ExternalOperation
       Name>
      <From>
        <RequestingNode>SOURCENODE</RequestingNode>
     </From>
     <ContentSections>
       <ContentSection>
         <Data>
           <![CDATA[<?xml version="1.0"?><ConnectorTest>
           Testing the HTTPListeningConnector. Message body.
           </ConnectorTest>]]>
         </Data>
       </ContentSection>
     </ContentSections>
    </IBRequest>
    
  4. Click the Post button to invoke service operation on the integration gateway.

  5. Check the Output section for the response. Compare the response with the XML created in the handler application class. Also check the HttpRequest.txt file created by the OnRequest PeopleCode to see the body of the request message received by the application server.

Setting Credentials in HTTP Headers

To set HTTP request credentials in the HTTP header:

  1. Start Send Master, and create a new Input File project.

  2. In the URL field enter:

    http://<your_server_name>/PSIGW/HttpListeningConnector

    Replace <your_server_name> with the details of the server where the integration gateway is running. For example:

    http://machine1234/PSIGW/HttpListeningConnector
  3. In the Headers field enter the following:

    OperationName:EXAMPLE_SERVICE_OPR.v1
    From:SOURCENODE
    
  4. In the Input section, paste the following:

    <?xml version="1.0"?>
    <ConnectorTest>
    Testing the HTTPListeningConnector. HTTP Header.
    </ConnectorTest>
    
  5. Click the Post button to sent the message to the integration gateway.

  6. Check the Output section for the response. Compare the response with the XML created in the handler application class. Also check the HttpRequest.txt file created by the OnRequest PeopleCode to see the body of the request message received by the application server.

Setting Credentials in Query Strings

To set HTTP request credentials in a query string:

  1. Start Send Master, and create a new Input File project.

  2. In the URL field enter:

    http://your_server_name/PSIGW/HttpListeningConnector?&Operation=
    EXAMPLE_SERVICE_OPR.v1&From=SOURCENODE
    

    Replace <your_server_name> with the details of the server where the integration gateway is running. For example:

    http://machine1234/PSIGW/HttpListeningConnector?&Operation=
    EXAMPLE_SERVICE_OPR.VERSION_1&From=SOURCENODE
    
  3. In the Input section, paste the following:

    <?xml version="1.0"?>
    <ConnectorTest>
    Testing the HTTPListeningConnector. Query String.
    </ConnectorTest>
    
  4. Click the Post button to invoke service operation on the integration gateway.

  5. Check the Output section for the response. Compare the response with the XML created in the handler application class. Also check the HttpRequest.txt file created by the OnRequest PeopleCode to see the body of the request message received by the application server.

Setting Credentials in SOAP-Specific HTTP Headers

To set HTTP request credentials in a SOAP-specific HTTP header:

  1. Start Send Master, and create a new Input File project.

  2. In the URL field enter:

    http://your_server_name/PSIGW/HttpListeningConnector
    

    Replacing <your_server_name> with the details of the server where the gateway is running. For example:

    http://machine1234/PSIGW/HttpListeningConnector
  3. In the Header field, add the following:

    SOAPAction: http://peoplesoft.com/EXAMPLE_SERVICE_OPR.v1/SOURCENODE//
    
  4. In the Input section, paste the following:

    <?xml version="1.0"?>
    <SOAP-ENV:Envelope xmlns:SOAP-ENC="http://schemas.xmlsoap.encoding/
     "xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
        <SOAP-ENV:Body>
          <ConnectorTest>
             <Text>
               Testing the HTTPListeningConnector. SOAP Message.
             </Text>
          </ConnectorTest>
        </SOAP-ENV:Body>
    </SOAP-ENV:Envelope>
    
  5. Click the Post button to invoke service operation on the integration gateway.

  6. Check the Output section for the response. Compare the response with the XML created in the handler application class; that XML will be returned wrapped in a SOAP envelope. Also check the HttpRequest.txt file created by the OnRequest PeopleCode to see the body of the request message received by the application server.

This section provides examples of using the HTTP target connector and discusses how use the connector to:

  • Send standard HTTP requests.

  • Send SOAP messages in HTTP requests.

Sending Standard HTTP Requests

To send a standard HTTP request:

  1. In PeopleSoft Application Designer, open the EXAMPLE_WORKREC record and add the following PeopleCode to the FieldChange event for the TEST field.

    &msg = CreateMessage(Operation.EXAMPLE_SERVICE_OPR);
    
    &xmldata = "<?xml version='1.0'?><ConnectorTest/>";
    
    /* create an XmlDoc */
    &xmlDoc = CreateXmlDoc(&xmldata);
    &rootNode = &xmlDoc.documentelement;
    &descNode = &rootNode.addelement("HTTPtest");
    &descNode.nodevalue = "This will be sent to an HTTP server.";
    
    /* put the XML in the message */
    &msg.setxmldoc(&xmlDoc);
    
    /* send the request */
    &response = %IntBroker.SyncRequest(&msg);
    
    /* and echo it back to the user */
    &xmlDoc = &response.getxmldoc();
    MessageBox(0, "", 0, 0, &xmlDoc.genxmlstring());
    

    Note that this code assumes that the response from the server is properly formatted XML.

  2. In the PeopleSoft Pure Internet Architecture, open the node definition for TARGETNODE. Set the Connector ID to HTTPTARGET. Set the URL property value to the address of the HTTP server that will process the request.

  3. Open the EXAMPLE_PAGE page, and click on the Test button. The HTTP response will be displayed in the resulting message box.

Sending SOAP Messages in HTTP Requests

To send a SOAP message in an HTTP request:

  1. In PeopleSoft Application Designer, open the EXAMPLE_WORKREC record and add the following PeopleCode to the FieldChange event for the TEST field.

    &msg = CreateMessage(Operation.EXAMPLE_SERVICE_OPR);
    
    /* create a SOAP document */
    &soapReq = CreateSOAPDoc();
    
    &soapReq.AddMethod("TestNode", 1);
    &soapReq.AddParm("Text", "This is a SOAP request.");
    
    /* put the XML in the message */
    &msg.setxmldoc(&soapReq.xmlDoc);
    
    /* send the request */
    &response = %IntBroker.SyncRequest(&msg);
    
    /* and echo it back to the user */
    &xmlDoc = &response.getxmldoc();
    MessageBox(0, "", 0, 0, &xmlDoc.genxmlstring());
    
  2. In the PeopleSoft Pure Internet Architecture, open the node definition for TARGETNODE.

    1. On the Node Definitions-Connectors tab, set the Connector ID to HTTPTARGET.

    2. Set the URL property value to the address of the HTTP server that will process the request.

  3. Open the EXAMPLE_PAGE page, and click on the Test button. The HTTP response will be displayed in the resulting message box.