You are on page 1of 48

Web Services and XML Publisher:

A Step-by-Step Guide to Using


Them Together

Alliance Conference
March 29, 2011
The Goal

z Consume an external, non-PeopleSoft


web service
z Present the data that comes back
from the web service in an XML
Publisher report that pops up in a
separate browser window
z Do all of this from the click of a
pushbutton on a PeopleSoft page
Agenda

z Test an external web service


z Create a PeopleSoft page to “consume” the
web service (send the request and capture the
response)
z Design an XML Publisher report to display the
data that is received from the web service
z Put PeopleCode behind a pushbutton to
request data from the web service and display
the data immediately via XML Publisher
Setup

The web service steps demonstrated


here require that you have Integration
Broker setup and working:
z Gateway
z IntegrationGateway.properties file
z Service Configuration page
Steps to Consume a Web Service

1. Test the WSDL with soapUI

2. Paste a valid WSDL URL into the PeopleSoft "Consume


Web Service" Wizard, and step through the wizard

3. Examine the Service Definition and Service Operations


that are generated
4. Apply Appropriate Service Operation Security to the
Service Operation(s)

5. Create a page, component, and content reference, and


write appropriate PeopleCode to initiate the request and
consume the response from the outside service
Web Services Description Language
WSDL

A WSDL is an XML document that


provides information about what the
service does, the methods that are
available, their parameters, and
parameter types. It describes how to
communicate with the service in order
to generate a request to, or decipher a
response from, the service.
soapUI

z Open Source
z Free
z Website: soapui.org
Testing a WSDL with soapUI

z Create a new project in soapUI


z Paste in your WSDL
z Use the automatically-generated
request to enter parameters and test
the request and verify the response
Testing a WSDL with soapUI
Example WSDL URL:
http://www.ignyte.com/webservices/ignyte.whatsshowing.webservice/moviefunctions.asmx?wsdl
Consuming a Web Service

z PeopleSoft provides a wizard to Consume


a Web Service
z PeopleTools > Integration Broker > Web
Services > Consume a Web Service
Consume Web Service Wizard
Example WSDL URL:
http://www.ignyte.com/webservices/ignyte.whatsshowing.webservice/moviefunctions.asmx?wsdl
Consume Web Service Wizard

The View WSDL hyperlink allows you to


view the WSDL in a browser window:
Examining a WSDL
Example WSDL URL:
http://www.ignyte.com/webservices/ignyte.whatsshowing.webservice/moviefunctions.asmx?wsdl

Here is the WSDL displayed in a browser:


Consume Web Service Wizard

If your selected service has more than


one port, you select one here:
Consume Web Service Wizard

Select one or more service operations


here:
Consume Web Service Wizard
Request and response messages are created. The
internal names of these messages can be changed to
more meaningful names.
Consume Web Service Wizard
The internal service name and default node
name are automatically inserted here.
Consume Web Service Wizard
Confirm Results

Click “View Consumed


Service” to view all the
created definitions.
The Service Definition
A link to the service operation appears at the bottom:
The Service Operation

Click on “Service
Operation
Security”
Service Operation Security

A Service Operation must be tied to at least


one permission list:
The Routing

Looking at the generated routing for the


service operation:
A Page for Testing the Web Service

In this example, all of the fields on the page are derived/work fields.
PeopleCode is placed in the FieldChange event of the pushbutton:
A Page for Testing the Web Service

In this example, all of the fields on the page are derived/work fields.
PeopleCode is placed in the FieldChange event of the pushbutton:
PeopleCode to Send the Request
Testing the Request and Response
The SOAP Response

z The data that comes back from the web


service includes a SOAP envelope
z Extract just the XML data from the
response, without the SOAP envelope
and header information
z Save that basic XML as a file (with the
.xml extension) to use as a sample XML
file to design your report template for
XML Publisher
Extracting the Relevant XML
The PeopleCode

• All of the PeopleCode discussed and


demonstrated here appears at the end of this
presentation.
• This pushbutton code invokes the web service,
parses the response and writes it to an XML
file, and sends that file to XML Publisher. The
XMLP report appears in a separate browser
window.
Steps to Create an XMLP Report based
on an XML File (rather than a Query)

1. Generate the XML sample data file (in this


scenario it is extracted from the SOAP response
received from the web service)
2. Define the Data Source
3. Create the Template (.rtf file)
4. Create the Report Definition
5. Run and test the XMLP Report
Define the Data Source

On the “Data Source” search page, select Add a


New Value:

Reporting Tools > XML Publisher > Data Source


Define the Data Source
When the Data Source page displays, upload
the xml file extracted from the web service
response. Save the Data Source definition.
Create the XMLP Template

• Open up Microsoft Word. The Template Builder (aka


“Design Helper”) facilitates the layout of the report.

• If you are using Word 2007, click on the “Add-Ins”


tab to see the menu items for the Template Builder:

• On the Template Builder menu, click on the Data


menu bar, and select “Load XML Data…”
• Load the XML file that you extracted from the SOAP
response.
Create the XMLP Template

z Save the template document as an RTF


file
z Add a title to the template
z Use the Design Helper Table Wizard to
insert one or more tables, groups, etc.
z Where there is hierarchical data, tables
can be nested
Create the XMLP Template

This template has nested tables:


Create the XMLP Template
Use the preview menu to look at the output in
PDF format
Create the Report Definition
Add a new report definition:
Reporting Tools > XML Publisher > Report Definition
Create the Report Definition
Create the Report Definition

Upload the RTF template:


Create the Report Definition

Output Tab – Format Options


Pushbutton PeopleCode

z Add more FieldChange PeopleCode to


your existing pushbutton.
z This code will associate the XML file
(response) with your report definition
and launch the report.
z The ViewOutput method is used if you
want the report to appear right away in
a separate browser window.
Pushbutton PeopleCode
Test the Finished Application

On the custom web page, the user enters the


parameters and clicks the pushbutton. The
external web service is invoked and the data
in the response is written to an XML file which
is passed to XML Publisher, and the resulting
report pops up in a separate browser window.
The Report Output
Contact Information

io Consulting - Booth 321

Tim Burns
tim.burns@io-consulting.com
http://training.io-consulting.com
(877) 656-6603
/* **********************************************
"Web Services and XML Publisher - A Step-by-Step Guide to Using Them Together"
This code goes with the corresponding presentation slides.
Alliance Conference - 2011 - Denver, CO. -- Session Number:29274, March 29, 2011
Tim Burns, io Consulting
http://training.io-consulting.com/training-technical.php
********************************************** */

/* The following code was placed in the FieldChange event of a pushbutton. In addition to the pushbutton, the page
has 3 other derived/work fields: ZIP, TRN_DISTANCE_XX, and RAWXML1. */

import PSXP_RPTDEFNMANAGER:*;

/********** Beginning of Adapted Code ***********************/


/********** Adapted from Larry Roux's code -- Begin -- **********
"Integrating with External Systems using Web Services"
Alliance Session 27112, March 2, 2010
Larry Roux, Syracuse University */

Local SOAPDoc &soapReq;


Local XmlNode &nodeEnv, &node_Wanted;
Local XmlDoc &xmldocRequest, &xmldocResponse, &xmldocNew;
Local Message &msgRequest, &msgResponse;

Local string &strXMLrqst, &strResponse, &strNodeWanted, &strGetTheatersNode, &strReadLine, &strOutDestFormat;


Local File &fileResponse, &fileIn, &fileOut;
Local PSXP_RPTDEFNMANAGER:ReportDefn &oReportDefn;

/******************* Request ***************************/

/* instantiate the SoapDoc object */


&soapReq = CreateSOAPDoc();

/* manually add SOAP XML envelope, header, body, method and parameters */
&soapReq.AddEnvelope(%SOAP_Custom);
&nodeEnv = &soapReq.EnvelopeNode;

&nodeEnv.AddAttribute("xmlns:SOAP-ENV", "http://schemas.xmlsoap.org/soap/envelope/");
&nodeEnv.AddAttribute("xmlns:what", "http://www.ignyte.com/whatsshowing");

&soapReq.AddMethod("what:GetTheatersAndMovies", 1);
&soapReq.AddParm("what:zipCode", TRN_DERIVED_XX.ZIP);
&soapReq.AddParm("what:radius", String(TRN_DERIVED_XX.TRN_DISTANCE_XX));
&strXMLrqst = &soapReq.GenXmlString();

/* This instantiates the XML object */


&xmldocRequest = CreateXmlDoc(&strXMLrqst);

/* This creates the message based on the IB Service Operation */


&msgRequest = CreateMessage(Operation.GETTHEATERSANDMOVIES, %IntBroker_Request);
&msgRequest.SetXmlDoc(&xmldocRequest);

/* Send the request and put any reply into the variable &msgResponse */
&msgResponse = %IntBroker.SyncRequest(&msgRequest);

/********** Adapted from Larry Roux's code -- End -- **********/


/********** End of Adapted Code ***************************/
/* Optional: For testing/debugging, display the outbound request in a derived/work field on a page in the same
component */
REM &RequestStr = &msgRequest.GenXMLString();
REM TRN_DERIVED_XX.RAWXML2 = &RequestStr;

/* Optional: Display the result that came back (the unformatted SOAP response), using a derived/work field */
&strResponse = &msgResponse.GenXMLString();
TRN_DERIVED_XX.RAWXML1 = &strResponse;

&xmldocResponse = &msgResponse.GetXmlDoc();

/* Opening a text file to which I will write the node that I want (and it's child nodes) */
&fileResponse = GetFile("c:\temp\fileResponse.txt", "W", %FilePath_Absolute);

/* Identifying the node that I want from the SOAP response, so that I can use the FindNode method and eliminate the
SOAP envelope. I adapted the following statement from a posting by David Sexton on the IT Toolbox website:
http://it.toolbox.com/blogs/extending-apps/findnode-in-peoplecode-34321 */
&strNodeWanted = "soap:Body//*[local-name()=" | """" | "GetTheatersAndMoviesResult" | """" | "]";

&node_Wanted = &xmldocResponse.DocumentElement.FindNode(&strNodeWanted);

/* I am creating a new XmlDoc and copying the desired node from the SOAP response to this new XmlDoc object.
I then write this out to a text file */
&xmldocNew = CreateXmlDoc("<?xml version='1.0'?><root/>");
&xmldocNew.DocumentElement.CopyNode(&node_Wanted);
&strGetTheatersNode = &xmldocNew.GenFormattedXmlString();
&fileResponse.WriteString(&strGetTheatersNode);
&fileResponse.Close();

/* At this point, the resulting text file (&fileResponse) still contains text that I do not want. I want to clean up the XML
file a little more before I send it to XML Publisher. */

/* Read/Write from one flat file to another, eliminating unwanted elements and attributes */
&fileIn = GetFile("c:\temp\fileResponse.txt", "R", %FilePath_Absolute);
&fileOut = GetFile("c:\temp\out.xml", "W", %FilePath_Absolute);

While &fileIn.ReadLine(&strReadLine)
If &strReadLine <> "<root>" And /* Removing this element from the final XML file */
&strReadLine <> "</root>" Then
If Find("xmlns", &strReadLine, 29) > 0 Then /* Removing the "xmlns" attribute from the final XML file */
&fileOut.WriteLine("<GetTheatersAndMoviesResult>");
Else
&fileOut.WriteLine(&strReadLine);
End-If;
End-If;
End-While;
&fileIn.Close();
&fileOut.Close();

/* Now I have a simple and clean XML file that I can easily use with my XML Publisher template */
/********** Sending the XML File to XML Publisher *************/

/* Specify the Report Definition */


&oReportDefn = create PSXP_RPTDEFNMANAGER:ReportDefn("MOVIES");
&oReportDefn.Get();

/* Establish the Data Source (XML File) for the Report */


&oReportDefn.SetRuntimeDataXMLFile("c:\temp\out.xml");

/* Generate the Report */


&strOutDestFormat = &oReportDefn.GetDefaultOutputFormat();
/* The first parameter of the ProcessReport method specifies the template ID (from the report definition) */
&oReportDefn.ProcessReport("MOVIES_1", "", %Date, &strOutDestFormat);

CommitWork();

/* Display the Report in a separate browser window */


&oReportDefn.DisplayOutput();

You might also like