Pageflow and Form Guide
CHAPTER 11
This chapter explains how to create a pageflow that invokes an RPC-style Web Service. It includes these topics:
exteNd Director provides the Web Service Pageflow Wizard to help you create pageflows that execute Web Services. This wizard uses a Web Service activity to invoke the service.
The Web Service activity only provides support for document-style WSDL files. However, you can create a pageflow that invokes an RPC-style Web Service by using a Java activity.
Example Here's an example of a pageflow that executes an RPC-style Web Service:
Here's what the input page would look like at runtime:
Here's what the output page would look like at runtime
To use an RPC-style Web Service in a pageflow, you need to:
Generate a Web Service consumer (a program that accesses a Web Service)
Write a Java activity class that acts as a client to the Web Service
Create a pageflow that includes the Java activity and the activities required to present the user interface
To generate a Web Service consumer, you need to run the Web Service Wizard. When you run the wizard, you provide a WSDL file as input. In this case, the WSDL file describes a Web Service that uses RPC-style bindings.
Specifying the project, package, and directory for the consumer To ensure the generated classes can be found at runtime, you need to provide the following settings when you're running the wizard:
For complete details on how to generate a consumer, see the chapter on generating Web Service consumers in Utility Tools.
After running the wizard, you can test the Web Service consumer by running the Web Service Client Runner. However, before you can do this, you need to:
Editing the xxxClient.java file Before using the generated xxxClient.java file, you:
Must edit the process() method to call one or more methods of the target Web Service.
May need to edit the getRemote() method to specify the correct location (binding) for accessing the target Web Service.
Adding the archives required by the Web Services SDK to your project
For a complete list of the archives required, see the chapter on generating Web Service consumers in Utility Tools.
A Java activity is a system activity that executes a Java class within the context of a pageflow. A Java activity allows you to write custom business logic that executes automatically without user intervention.
You can create a Java activity using the Java Activity Wizard, code the resulting Java class template, and add the activity in the Pageflow Modeler.
To invoke a Web Service from a Java activity, you need to include some Java code to:
This logic is generated for you when you run the Web Service Wizard. You can simply copy this logic from the generated xxxClient.java file to the invoke() method on your Java activity, as shown below:
import com.sssw.wf.api.*; import javax.naming.*; import net.xmethods.sd.*; public class TemperatureJavaActivity implements EbiJavaActivity public TemperatureJavaActivity() { } public void invoke(EbiContext context) { System.out.println("TemperatureJavaActivity"); try { InitialContext ctx = new InitialContext(); String lookup = "xmlrpc:soap:net.xmethods.sd.TemperatureService"; TemperatureService service = (TemperatureService)ctx.lookup(lookup); TemperaturePortType remote = (TemperaturePortType)service.getTemperaturePort(); // get the ZIP from the portlet session String zip = (String)context.getEbiWhiteboard().getScopedValue( "ZIP" ); float f = remote.getTemp(zip); context.getEbiWhiteboard().setScopedValue("TEMP", String.valueOf( f ) ); } catch (Exception e) { throw new RuntimeException (e); } ... }
Note that this Java activity also uses the scoped path API to get the zip code (ZIP) and set the temperature (TEMP) on the Session object.
Using a helper class to invoke the service The exteNd Director API provides a helper class you can use to invoke a Web Service. This class is called WebServiceActivityHelper. It is located in the com.novell.afw.portal.portlet.pf package. The code example below shows the use of this helper class:
import com.sssw.wf.api.*; import com.novell.afw.portal.portlet.pf.*; public class TemperatureJavaActivity implements EbiJavaActivity { public TemperatureJavaActivity() { } public void invoke(EbiContext context) { System.out.println("TemperatureJavaActivity"); try { WebServiceActivityHelper wsHelper = new WebServiceActivityHelper(); net.xmethods.sd.TemperaturePortType remote = (net.xmethods.sd.TemperaturePortType) wsHelper.getRemote( net.xmethods.sd.TemperatureService.class, net.xmethods.sd.TemperaturePortType.class); // get the ZIP from the portlet session String zip = (String)context.getEbiWhiteboard().getScopedValue( "ZIP" ); float f = remote.getTemp(zip); context.getEbiWhiteboard().setScopedValue( "TEMP", String.valueOf( f ) ); } catch (Exception e) { throw new RuntimeException (e); } ... }
Typically, you'll want to create an input page as well as an output page for a pageflow that invokes a Web Service. The input page allows the user to enter values for parameters that should be passed to the service. The output page displays the data returned by the service.
Here's some HTML for a sample input page:
<form name="form1" method="post" action="wsrp_rewrite?wsrp-urlType=blockingAction/wsrp_rewrite"> <br/> <span class="portlet-form-field-label"> Zip </span> <input class="portlet-form-field" type="name" name="zip" value="02630" size="20"> <br/><br/> <input type="submit" name="verb" value="Continue"> </form>
Here's some HTML for a sample output page:
<form name="form1" method="post" action="wsrp_rewrite?wsrp-urlType=blockingAction/wsrp_rewrite"> <br/> <span class="portlet-form-field-label"> Zip Temperature : scopedpath?Session/TEMP/scopedpath </span> <br/><br/> <input type="submit" name="verb" value="Continue"> </form>
In this example, the data returned (the temperature) is retrieved by means of a scoped path expression:
scopedpath?Session/TEMP/scopedpath
Here's what the pageflow would look like:
Here are the scoped paths for the flow:
Specifying a Copy After operation for the input page
The HTML input page would specify a Copy After operation that copies the zip code entered by the user into a variable on the Session scope:
Copyright © 2004 Novell, Inc. All rights reserved. Copyright © 1997, 1998, 1999, 2000, 2001, 2002, 2003 SilverStream Software, LLC. All rights reserved. more ...