Difference between revisions of "Integration to a Web Service Using HttpConnection"

From AgileApps Support Wiki
imported>Aeric
imported>Aeric
Line 1: Line 1:
This example uses the [[HttpConnection Class]] to attach to a external web service while executing a [[Data Policy]].<br>It uses the [[Web Service HttpConnection]] code sample.
This example uses the [[HttpConnection Class]] to attach to an external web service.<br>It uses the [[Web Service HttpConnection]] code sample.


===About the Example===
===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 <tt>www.HelloWorldParts.com</tt>.
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 <tt>www.HelloWorldParts.com</tt>.


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|Configure the Platform]] for details.
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|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. Β 
;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. Β 
Line 10: Line 10:
===Configure HelloWorldParts Webservice===
===Configure HelloWorldParts Webservice===


#HelloWorldParts should expose their web service to recieve request and response messages as XML
#HelloWorldParts should expose their web service to receive request and response messages as XML
#A Servlet should be created that can receive request in XML and respond in XML format
#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: <tt>http://bvtest.HelloWorldParts.com:xxxx/GetPartInfo</tt>
#:For Example, assume the following Servlet has been created on HelloWorldParts: <tt>http://bvtest.HelloWorldParts.com:xxxx/GetPartInfo</tt>
Line 68: Line 68:
The platform will contain two objects, defined with this relationship:
The platform will contain two objects, defined with this relationship:
:*Invoice object includes a [[Subform]] based on the Parts object
:*Invoice object includes a [[Subform]] based on the Parts object
::*A [[Data Policy]] is defined that is:
::*A [[Rule]] is defined to:
:::*Triggered when a the Parts Grid in an Invoice Record is updated with a Part Number and Saved
:::*Fire 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
::::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
:*Parts object has a [[Lookup]] field to the Invoice object


Line 92: Line 92:
:;Item Cost:Text Area, Width = 30, Height = 4 Β 
:;Item Cost:Text Area, Width = 30, Height = 4 Β 


===Add a Data Policy===
===Add a Rule===
#Create a class and a method for the data policy to execute.
#Create a class and a method for the Rule to execute.
#Copy this [[Web Service HttpConnection|Code Sample]] into the method
#Copy this [[Web Service HttpConnection|Code Sample]] into the method
#Create a [[Data Policy]] using these parameters:
{{TBD|}}
#;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===
===Try it Out===


Verify that the action works as intended by activating the data policy from the platform:
Verify that the action works as intended by activating the Rule from the platform:
#Open the Invoice object (appears as a tab in the application)
#Open the Invoice object (appears as a tab in the application)
#Add a record and populate the grid with a valid part number
#Add a record and populate the grid with a valid part number
#Save the record
#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
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

Revision as of 02:31, 12 January 2013

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 :

<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 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

__TBD__

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