Upload
timburns
View
467
Download
2
Embed Size (px)
DESCRIPTION
Consume an external, non-PeopleSoft web service. Present the data that comes back from the web service in an XML Publisher report that pops up in a separate browser window. Do all of this from the click of a pushbutton on a PeopleSoft page.
Citation preview
Alliance ConferenceMarch 29, 2011
Web Services and XML Publisher:A Step-by-Step Guide to Using
Them Together
The GoalThe Goal
Consume an external, non-PeopleSoft web service
Present the data that comes back from the web service in an XML Publisher report that pops up in a separate browser window
Do all of this from the click of a pushbutton on a PeopleSoft page
Test an external web service
Create a PeopleSoft page to “consume” the web service (send the request and capture the response)
Design an XML Publisher report to display the data that is received from the web service
Put PeopleCode behind a pushbutton to request data from the web service and display the data immediately via XML Publisher
AgendaAgenda
The web service steps demonstrated here require that you have Integration Broker setup and working:
SetupSetup
Gateway
IntegrationGateway.properties file
Service Configuration page
Steps to Consume a Web ServiceSteps 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 LanguageWeb Services Description LanguageWSDLWSDL
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.
soapUIsoapUI
Open Source
Free
Website: soapui.org
Testing a WSDL withTesting a WSDL with soapUIsoapUI
Create a new project in soapUI
Paste in your WSDL
Use the automatically-generated request to enter parameters and test the request and verify the response
Testing a WSDL withTesting a WSDL with soapUIsoapUI
Example WSDL URL:
http://www.ignyte.com/webservices/ignyte.whatsshowing.webservice/moviefunctions.asmx?wsdl
Consuming a Web ServiceConsuming a Web Service
PeopleSoft provides a wizard to Consume a Web Service
PeopleTools > Integration Broker > Web Services > Consume a Web Service
Consume Web Service WizardConsume Web Service Wizard
Example WSDL URL:
http://www.ignyte.com/webservices/ignyte.whatsshowing.webservice/moviefunctions.asmx?wsdl
The View WSDL hyperlink allows you to view the WSDL in a browser window:
Consume Web Service WizardConsume Web Service Wizard
Examining a WSDLExamining a WSDL
Example WSDL URL:
http://www.ignyte.com/webservices/ignyte.whatsshowing.webservice/moviefunctions.asmx?wsdl
Here is the WSDL displayed in a browser:
If your selected service has more than one port, you select one here:
Consume Web Service WizardConsume Web Service Wizard
Select one or more service operations here:
Consume Web Service WizardConsume 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 WizardConsume Web Service Wizard
The internal service name and default node name are automatically inserted here.
Consume Web Service WizardConsume Web Service Wizard
Consume Web Service WizardConsume Web Service WizardConfirm ResultsConfirm Results
Click “View Consumed Service” to view all the created definitions.
The Service DefinitionThe Service Definition
A link to the service operation appears at the bottom:
The Service OperationThe Service Operation
Click on “Service Operation Security”
Service Operation SecurityService Operation Security
A Service Operation must be tied to at least one permission list:
The RoutingThe Routing
Looking at the generated routing for the service operation:
A Page for Testing the Web ServiceA 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:
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 ServiceA Page for Testing the Web Service
PeopleCode to Send the RequestPeopleCode to Send the Request
Testing the Request and Response Testing the Request and Response
The SOAP ResponseThe SOAP Response
The data that comes back from the web service includes a SOAP envelope
Extract just the XML data from the response, without the SOAP envelope and header information
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 XMLExtracting the Relevant XML
The PeopleCodeThe 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 Steps to Create an XMLP Report based on an XML File (rather than a Query)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 SourceDefine the Data Source
Reporting Tools > XML Publisher > Data Source
On the “Data Source” search page, select Add a New Value:
Define the Data SourceDefine 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 TemplateCreate 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 TemplateCreate the XMLP Template
Save the template document as an RTF file
Add a title to the template
Use the Design Helper Table Wizard to insert one or more tables, groups, etc.
Where there is hierarchical data, tables can be nested
Create the XMLP TemplateCreate the XMLP Template
This template has nested tables:
Create the XMLP TemplateCreate the XMLP Template
Use the preview menu to look at the output in PDF format
Create the Report DefinitionCreate the Report Definition
Reporting Tools > XML Publisher > Report Definition
Add a new report definition:
Create the Report DefinitionCreate the Report Definition
Create the Report DefinitionCreate the Report Definition
Upload the RTF template:
Create the Report DefinitionCreate the Report Definition
Output Tab – Format Options
Pushbutton PeopleCodePushbutton PeopleCode
Add more FieldChange PeopleCode to your existing pushbutton.
This code will associate the XML file (response) with your report definition and launch the report.
The ViewOutput method is used if you want the report to appear right away in a separate browser window.
Pushbutton PeopleCodePushbutton PeopleCode
Test the Finished ApplicationTest 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 OutputThe Report Output
Contact InformationContact Information
io Consulting - Booth 321
Tim Burns
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();