Integration Broker - Part 3 - Consuming a 3rd-Party Web Service

 The example has been created and tested on the following software environment:

   Peoplesoft Application: FSCM 9.2
   Peoplesoft Peopletools: 8.53.02
   Database: Oracle


Assumptions:
1) The Integration Broker is configured correctly.
2) The Soap Client is installed on your Desktop.


The major steps will be the following:
1) Selecting and reviewing a web service
2) Consuming a web service in PeopleSoft
3) Creating a new Peoplesoft Page for using Web Service
4) Testing online page to get quote for a stock using consumed web service


1) Selecting and reviewing a web service
We will be working with is a simple web service for getting the Stock quotes for the day. The WSDL for this web service is available at 
http://www.webservicex.net/stockquote.asmx?wsdl
First thing is to check this web service is available. In your browser, open a new window (or tab) in your browser and type the above URL in the address bar and press enter. You should see something similar to the following screen.
Let us load the web service in soapUI and review what it needs and what it can provide.
Start soapUI and create a new SOAP project. Fill in the following:
Project name: StockQuoteSoap
Initial WSDL/WADL: 
http://www.webservicex.net/stockquote.asmx?wsdl
Click the Ok button.
The project loads. To load the request to SOAP editor, double click on the Request1 as highlighted below.

Replace the highlighted question mark with GOOG. As some of you might be aware that GOOG is the symbol for Google Incorporated. Click on the green arrow to submit the request. You will see the response as follows.
Let us look at the response more closely. We get the following data back.
<Symbol>GOOG</Symbol>
<Last>533.33</Last>
<Date>6/5/2015</Date>
<Time>4:00pm</Time>
<Change>-3.37</Change>
<Open>536.35</Open>
<High>537.20</High>
<Low>532.52</Low>
<Volume>1388220</Volume>
<MktCap>363.95B</MktCap>
<PreviousClose>536.70</PreviousClose>
<PercentageChange>-0.63%</PercentageChange>
<AnnRange>486.23 - 598.01</AnnRange>
<Earns>21.16</Earns>
<P-E>25.21</P-E>
<Name>Google Inc.</Name >

So we have a working web service which takes the symbol of the stock and returns all the above values.


2) Consuming a web service in PeopleSoft
Let us navigate to PeopleTools > Integration Broker > Web Services > Consume Web Service
Click on the WSDL URL radio button and paste the URL 
http://www.webservicex.net/stockquote.asmx?wsdl.
Uncheck the Build Document Messages checkbox.Note: Another way is to open the wsdl in a new browser window and save the file as an XML file. Then used the File radio button and load from the XML file you just saved.
Click on the Next button.
In the step 2, review the WSDL by clicking the View WSDL hyperlink.

Click on the Next button.
This web service has 4 service ports indicating the four ways the web service can be accessed. Select the first, STOCKQUOTESOAP service port.

Next, you get to choose the only one service operation i.e. GetQuote.
Since it is a synchronous service, there is one request message and one response message. Click Next button to create these two messages. (The step 5 was skipped. That is ok).
We have renamed the internal message names for internal and external to be more meaningful.
The final step we will leave the receiver node as default WSDL_NODE.

Click the Finish button and review the results on the next page.
Click on the View Consumed Service to open the service and see the IB definitions that have been created.
For the node WSDL_NODE, we will setup the PRIMARYURL property for the connector HTTPTARGET connector as the following URLhttp://www.webservicex.net/stockquote.asmx
Save the page and ping the node to confirm that the setup is correct.
Perform the security administration to provide access to the service operations of the service STOCKQUOTESOAP.
Click on the GETQUOTE link for the service operation.
Click on the Service Operation Security link.
Give a permission list which is assigned to our user profile (in our case the user is VP1).

3) Creating a new Peoplesoft Page for using Web Service
Let us review the XML from the request and the response to determine the parameters to be sent and the data to be expected. We will submit the WSDL 
http://www.webservicex.net/stockquote.asmx in SOAPUI for symbol GOOG and get the XML as follows.

XML from Request
<soapenv:Envelope xmlns:soapenv=http://schemas.xmlsoap.org/soap/envelope/
xmlns:web="
http://www.webserviceX.NET/"><soapenv:Header/><soapenv:Body><web:GetQuote>
<!--Optional:-->
<web:symbol>GOOG</web:symbol>
</web:GetQuote></soapenv:Body></soapenv:Envelope>


XML from Response
<soap:Envelope xmlns:soap=http://schemas.xmlsoap.org/soap/envelope/
xmlns:xsi="
http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body><GetQuoteResponse xmlns="
http://www.webserviceX.NET/">
<GetQuoteResult><![CDATA[<StockQuotes><Stock>
<Symbol>GOOG</Symbol>
<Last>526.83</Last>
<Date>6/8/2015</Date>
<Time>4:00pm</Time>
<Change>-6.50</Change>
<Open>533.31</Open>
<High>534.12</High>
<Low>526.24</Low>
<Volume>1524139</Volume>
<MktCap>359.51B</MktCap>
<PreviousClose>533.33</PreviousClose>
<PercentageChange>-1.22%</PercentageChange>
<AnnRange>486.23 - 598.01</AnnRange>
<Earns>21.16</Earns>
<P-E>24.90</P-E>
<Name>Google Inc.</Name>
</Stock></StockQuotes>]]></GetQuoteResult></GetQuoteResponse></soap:Body></soap:Envelope>


Based on the above data columns, let us create a page in peoplesoft and a work record containing some of the above highlighted fields plus one for a button.
The work record looks like the following.

Let us create a simple page like the one below.
On the FieldChange event of Get Stock Quote button (field SEARCH_BUTTON), we will add the following peoplecode.
Local Message &wsdl_request, &wsdl_response;
Local SOAPDoc &wsdl_soapdoc;
Local XmlDoc &wsdl_soapxmldoc, &wsdl_responsexmldoc, &wsdl_responsexmldet;
Local array of XmlNode &wsdl_result;
Local number &Char_Pos1, &Char_Pos2;

try
   rem create soap document;
   &wsdl_soapdoc = CreateSOAPDoc();
   rem add envelope;
   &wsdl_soapdoc.AddEnvelope(0);
   &EnvelopeNode = &wsdl_soapdoc.EnvelopeNode;
   rem add namespace alias parameter;
   &EnvelopeNode.AddAttribute("xmlns:web", "
http://www.webserviceX.NET/");
   rem add header;
   &wsdl_soapdoc.AddHeader();
   rem add body;
   &wsdl_soapdoc.AddBody();
   rem add method and parameters;
   &wsdl_soapdoc.AddMethod("web:GetQuote", 1);
   &wsdl_soapdoc.AddParm("web:symbol", AJ_STOCK_QT_WRK.SYMBOLICID);
   rem get the xmldoc from the soap document;
   &wsdl_soapxmldoc = CreateXmlDoc();
   &wsdl_soapxmldoc = &wsdl_soapdoc.XmlDoc;
   rem assign xmldoc to request message;
   &wsdl_request = CreateMessage(Operation.GETQUOTE);
   &wsdl_request.SetXmlDoc(&wsdl_soapxmldoc);
  
   rem display the request message;
   WinMessage(&wsdl_request.GenXMLString(), 0);
   rem Send request and get response;
   &wsdl_response = %IntBroker.SyncRequest(&wsdl_request);
   rem get xmldoc from response message;
   &wsdl_responsexmldoc = &wsdl_response.GetXmlDoc();
   rem display the response message;
   WinMessage(&wsdl_responsexmldoc.GenXmlString(), 0);
  
   rem read the response XML tags;
   &wsdl_result = &wsdl_responsexmldoc.GetElementsByTagName("GetQuoteResult");
   If &wsdl_result.Len = 0 Then
      MessageBox(0, "", 0, 0, "GetElementsByTagName Node not found");
   Else
      WinMessage(&wsdl_result [1].NodeValue, 0);
      rem Extract the data elements and assign to fields on the record;
      &XML_Data_String = &wsdl_result [1].NodeValue;
     
      &field = "Name";
      &Char_Pos1 = Find("<" | &field | ">", &XML_Data_String);
      &Char_Pos2 = Find("</" | &field | ">", &XML_Data_String);
      AJ_STOCK_QT_WRK.DESCR = Substring(&XML_Data_String, &Char_Pos1 + Len(&field) + 2, &Char_Pos2 - &Char_Pos1 - Len(&field) - 2);
      &field = "Last";
      &Char_Pos1 = Find("<" | &field | ">", &XML_Data_String);
      &Char_Pos2 = Find("</" | &field | ">", &XML_Data_String);
      AJ_STOCK_QT_WRK.PRICE_CLOSE = Value(Substring(&XML_Data_String, &Char_Pos1 + Len(&field) + 2, &Char_Pos2 - &Char_Pos1 - Len(&field) - 2));
      &field = "Change";
      &Char_Pos1 = Find("<" | &field | ">", &XML_Data_String);
      &Char_Pos2 = Find("</" | &field | ">", &XML_Data_String);
      AJ_STOCK_QT_WRK.CHANGE_AMT = Value(Substring(&XML_Data_String, &Char_Pos1 + Len(&field) + 2, &Char_Pos2 - &Char_Pos1 - Len(&field) - 2));
      &field = "Open";
      &Char_Pos1 = Find("<" | &field | ">", &XML_Data_String);
      &Char_Pos2 = Find("</" | &field | ">", &XML_Data_String);
      AJ_STOCK_QT_WRK.OPEN_SUM = Value(Substring(&XML_Data_String, &Char_Pos1 + Len(&field) + 2, &Char_Pos2 - &Char_Pos1 - Len(&field) - 2));
      &field = "High";
      &Char_Pos1 = Find("<" | &field | ">", &XML_Data_String);
      &Char_Pos2 = Find("</" | &field | ">", &XML_Data_String);
      AJ_STOCK_QT_WRK.SDK_HIGH_TRADE = Value(Substring(&XML_Data_String, &Char_Pos1 + Len(&field) + 2, &Char_Pos2 - &Char_Pos1 - Len(&field) - 2));
      &field = "Low";
      &Char_Pos1 = Find("<" | &field | ">", &XML_Data_String);
      &Char_Pos2 = Find("</" | &field | ">", &XML_Data_String);
      AJ_STOCK_QT_WRK.SDK_LOW_TRADE = Value(Substring(&XML_Data_String, &Char_Pos1 + Len(&field) + 2, &Char_Pos2 - &Char_Pos1 - Len(&field) - 2));
      &field = "Volume";
      &Char_Pos1 = Find("<" | &field | ">", &XML_Data_String);
      &Char_Pos2 = Find("</" | &field | ">", &XML_Data_String);
      AJ_STOCK_QT_WRK.VS_SALES_VOLUME = Value(Substring(&XML_Data_String, &Char_Pos1 + Len(&field) + 2, &Char_Pos2 - &Char_Pos1 - Len(&field) - 2));
      &field = "PercentageChange";
      &Char_Pos1 = Find("<" | &field | ">", &XML_Data_String);
      &Char_Pos2 = Find("</" | &field | ">", &XML_Data_String);
      AJ_STOCK_QT_WRK.CHANGE_PCT = Value(Substring(&XML_Data_String, &Char_Pos1 + Len(&field) + 2, &Char_Pos2 - &Char_Pos1 - Len(&field) - 2));
   End-If;
  
catch Exception &e
   WinMessage(&e.ToString(), 0);
end-try;


4) Testing online page to get quote for a stock using consumed web service
Navigate to the new page created.

Enter a stock symbol, say GOOG for google and click on the Get Stock Quote button.
You see the request message.

Next you see the response message.
Next you see the details of the data received.
And finally you see the page with all fields populated.

That completes Consuming 3rd Party Web Services example.
Once you are comfortable with the activity, you could try
1) Have the layout on the page changed from single row to multiple rows in a grid.
2) Save the data with date for historical purposes.
Enjoy and share.

 

Comments