Integration to a Web Service Using HttpConnection
This example uses the HttpConnection Class to attach to a external web service while executing a Data Policy.
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. A Data Policy is enabled in the Invoice object that makes the HttpConnection to request and retrieve 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
- HelloWorldParts should expose their web service to recieve request and response messages as XML
- 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
- 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 :
<Request> <auth_params> <username>USER</username> <password>HelloWorldParts</password> </auth_params> <query_params> <part_number>PARTNUMBER</part_number> </query_params> </Request>
- 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:
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>
This is the Expected Response:
<?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>
Configure the Platform
The platform will contain two objects, defined with this relationship:
- Invoice object includes a Subform based on the Parts object
- A Data Policy is defined that is:
- Triggered when a the Parts Grid in an Invoice Record is updated with a Part Number and Saved
- The data policy will make 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 Data Policy
- Create a class and a method for the data policy to execute.
- Copy this Code Sample into the method
- Create a Data Policy using these parameters:
- Name
- Java Code 2 HttpConnect
- Enabled
- Checked
- Activation Trigger
- Action Based
- Activation Sequence
- After Triggering Actions
- Triggering Actions
- Select the 'Update' checkbox
- Policy Triggering Criteria
- Save your changes
- Specify the Data Policy action:
- Click [Add Action]
- Click Invoke Java Method
- Enter an Action Name
- Choose the class and method you created
Try it Out
Verify that the action works as intended by activating the data policy from the platform:
- Open the Invoice object (appears as a tab in the application)
- Add a record and populate the grid with a valid part number
- 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