Using the ConnectorRequest Built-In Function

The ConnectorRequest function enables you to build a message object and perform a POST or GET using any target connector. With this function, you use the Message object to populate connector values.

Response messages are returned unstructured in the IB_GENERIC message. The IB_GENERIC message is delivered out-of-the-box.

The ConnectorRequest function features optional user exception logic. If you pass the optional parameter true and a user exception occurs anywhere in the function, the response message returns a Response Status property set to false. Always read the Response Status property of the response message to determine if the call was successful. If it was not successful, interrogate the IBException object within the Message object to get the details of the exception.

The following example shows using the ConnectorRequest function to perform a GET to obtain a stock quote.

Local XmlDoc &Output;
Local String &Exception;

Local Message &MSG1, &MSG2;

&MSG = CreateMessage(OPERATION.QE_FLIGHTPLAN);

&MSG.IBInfo.IBConnectorInfo.ConnectorName = "HTTPTARGET";
&MSG.IBInfo.IBConnectorInfo.ConnectorClassName = "HttpTargetConnector";

&nReturn = &MSG.IBinfo.IBConnectorInfo.AddConnectorProperties
    ("Method", "GET", %HttpProperty);
&nReturn = &MSG.IBinfo.IBConnectorInfo.AddConnectorProperties
    ("URL", "http://finance.yahoo.com/d/quotes.txt/?symbols
    =PSFT&format=l1c1d1t1", %HttpProperty);

&MSG2 = %IntBroker.ConnectorRequest(&MSG, true); // user exception property (true) passed

If &MSG2.ResponseStatus = %IB_Status_Success Then
    &Output = &MSG2.GetXmlDoc(); // get the data out of the message

Else
    &Exception = &MSG2.IBException.ToString()); // read the exception

End-If;

The following example shows sample code to read the response Message object to get exception details if using user exception logic:

&Response_MSG = %IntBroker.ConnectorRequest (&MSG, True);

If  &Response_MSG.ResponseStatus = %IB_Status_Success Then
    /* Perform successful processing of Response Message */

Else
    /* Read the IB Exception object for exception specifics. */
    &error = &Response_MSG.IBException.ToString ();

End-If;