AgileApps Support Wiki Pre Release

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

From AgileApps Support Wiki
imported>Aeric
imported>Aeric
 
(3 intermediate revisions by the same user not shown)
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 17: Line 17:


The XML '''Request''' format expected by HelloWorldParts :
The XML '''Request''' format expected by HelloWorldParts :
<pre>
:<syntaxhighlight lang="xml" enclose="div">
<Request>
<Request>
      <auth_params>
  <auth_params>
            <username>USER</username>
      <username>USER</username>
            <password>HelloWorldParts</password>
      <password>HelloWorldParts</password>
      </auth_params>
  </auth_params>
      <query_params>
  <query_params>
              <part_number>PARTNUMBER</part_number>
      <part_number>PARTNUMBER</part_number>
      </query_params>
  </query_params>
</Request>
</Request>
</pre>
</syntaxhighlight>


:User Name: <tt>USER</tt>  
:User Name: <tt>USER</tt>  
Line 37: Line 37:
Configure the HelloWorldParts servlet to accept the following Request and Response messages:
Configure the HelloWorldParts servlet to accept the following Request and Response messages:


<pre>  
:<syntaxhighlight lang="xml" enclose="div">
http://wstest.HelloWorldParts.com:xxxx/ws/GetPartInfo?Request=
http://wstest.HelloWorldParts.com:xxxx/ws/GetPartInfo?Request=
<Request>
<Request>
  <auth_params>
  <auth_params>
  <username>USER</username>
      <username>USER</username>
  <password>HelloWorldParts</password>
      <password>HelloWorldParts</password>
  </auth_params>
  </auth_params>
  <query_params>
  <query_params>
  <part_number>M108-43H-30</part_number>
      <part_number>M108-43H-30</part_number>
</query_params>
  </query_params>
</Request>
</Request>
</pre>
</syntaxhighlight>


This is the Expected Response:
This is the Expected Response:
<pre>
:<syntaxhighlight lang="xml" enclose="div">
<?xml version="1.0"?>
<?xml version="1.0"?>
<Response>
<Response>
<part_description>SC 5000 3T/4S 2MB</part_description>
  <part_description>SC 5000 3T/4S 2MB</part_description>
<current_revision_level>I</current_revision_level>
  <current_revision_level>I</current_revision_level>
<current_eco_number>M08059</current_eco_number>
  <current_eco_number>M08059</current_eco_number>
<pending_revision_level>2</pending_revision_level>
  <pending_revision_level>2</pending_revision_level>
<pending_eco_number>C12652</pending_eco_number>
  <pending_eco_number>C12652</pending_eco_number>
<item_costed_flag>Y</item_costed_flag>
  <item_costed_flag>Y</item_costed_flag>
<ww_stock_level>1</ww_stock_level>
  <ww_stock_level>1</ww_stock_level>
<forecast></forecast><hold_name>Marketing Hold</hold_name>
  <forecast></forecast>
  <hold_name>Marketing Hold</hold_name>
</Response>
</Response>
</pre>
</syntaxhighlight>


==Configure the Platform==
==Configure the Platform==
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 93:
:;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:
#Create an [[Event Rule]] triggered by adding a record
#;Name:Java Code 2 HttpConnect
#Add an action to the Rule that '''Invokes a Method'''
#;Enabled:Checked
#Select the class and method you defined as the target of the Rule.
#;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

Latest revision as of 20:54, 12 March 2014

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