Integration to a Web Service Using HttpConnection

From AgileApps Support Wiki

This example uses the HttpConnection Class to attach to an external web service.
It uses the Web Service HttpConnection code sample.

About the Example

In this example, the platform is configured to connect to an external domain using web services and retrieve data from the web service. The external domain in this example is www.HelloWorldParts.com.

Specifically, the platform contains an application composed of two objects, Parts and Invoice, where the objects are related. Code in the Invoice object makes the HttpConnection request and retrieves the Parts information. See Configure the Platform for details.

Expected Outcome
When an invoice is entered (Add a Record), the platform will query the HelloWorldParts web service for a part number and populate a record in the Parts object.

Configure HelloWorldParts Webservice

  1. HelloWorldParts should expose their web service to receive request and response messages as XML
  2. A Servlet should be created that can receive request in XML and respond in XML format
    For Example, assume the following Servlet has been created on HelloWorldParts: http://bvtest.HelloWorldParts.com:xxxx/GetPartInfo
    Note that these are non-functional URLs for the purposes of this demonstration
  3. The platform connects to the HelloWorldParts webservice should just POST the XML-Request String using parameter name: Request

The XML Request format expected by HelloWorldParts :

<syntaxhighlight lang="xml" enclose="div">

<Request>

  <auth_params>
     <username>USER</username>
     <password>HelloWorldParts</password>
  </auth_params>
  <query_params>
     <part_number>PARTNUMBER</part_number>
  </query_params>

</Request> </syntaxhighlight>

User Name: USER
Password: HelloWorldParts
The part number in RequestXML is parsed by the servlet, which will return the Part field information in XML

Request and Response

Configure the HelloWorldParts servlet to accept the following Request and Response messages:

<syntaxhighlight lang="xml" enclose="div">

http://wstest.HelloWorldParts.com:xxxx/ws/GetPartInfo?Request= <Request>

  <auth_params>
     <username>USER</username>
     <password>HelloWorldParts</password>
  </auth_params>
  <query_params>
     <part_number>M108-43H-30</part_number>
  </query_params>

</Request> </syntaxhighlight>

This is the Expected Response:

<syntaxhighlight lang="xml" enclose="div">

<?xml version="1.0"?> <Response>

  <part_description>SC 5000 3T/4S 2MB</part_description>
  <current_revision_level>I</current_revision_level>
  <current_eco_number>M08059</current_eco_number>
  <pending_revision_level>2</pending_revision_level>
  <pending_eco_number>C12652</pending_eco_number>
  <item_costed_flag>Y</item_costed_flag>
  <ww_stock_level>1</ww_stock_level>
  <forecast></forecast>
  <hold_name>Marketing Hold</hold_name>

</Response> </syntaxhighlight>

Configure the Platform

The platform will contain two objects, defined with this relationship:

  • Invoice object includes a Subform based on the Parts object
  • A Rule is defined to:
  • Fire when a the Parts Grid in an Invoice Record is updated with a Part Number and Saved
Makes an HttpConnection request to the HelloWorldParts data base, retrieve the part data, and update the fields in the grid
  • Parts object has a Lookup field to the Invoice object

Create the Objects and Build the Relationship

To configure the platform, create the following objects, with fields defined as follows:

Invoice Object
Create the following fields in this object
Invoice Number
String
Part Number
Text Field, Maximum Storage Length = 50, Display Length = 30
WSResponse
Text Area, Width = 30, Height = 4
Subform
Choose Object Name = Parts
Parts Object
Create the following fields in this object
Part Number
Text Area, Width = 30, Height = 4
Parts Description
Text Area, Width = 30, Height = 4
Level
Text Area, Width = 30, Height = 4
Forecast
Text Area, Width = 30, Height = 4
Current Eco
Text Area, Width = 30, Height = 4
Pending Eco
Text Area, Width = 30, Height = 4
Version#
Text Area, Width = 30, Height = 4
Pending Revision
Text Area, Width = 30, Height = 4
Item Cost
Text Area, Width = 30, Height = 4

Add a Rule

  1. Create a class and a method for the Rule to execute.
  2. Copy this Code Sample into the method
  3. Create an Event Rule triggered by adding a record
  4. Add an action to the Rule that Invokes a Method
  5. Select the class and method you defined as the target of the Rule.

Try it Out

Verify that the action works as intended by activating the Rule from the platform:

  1. Open the Invoice object (appears as a tab in the application)
  2. Add a record and populate the grid with a valid part number
  3. Save the record

The expected result is that the grid is populated with data from HelloWorldParts, and that a Parts record is created (or updated) with detailed information