This section describes the coding needed for implementing a simple JAX-WS web service client which makes use of the Web service API delivered with the WebSphereŽ Business Process Choreographer. The sample is structured in two parts, a Basic sample and an Advanced sample.
In the Basic sample, the focus is on setting up the infrastructure, getting the Web Services Description Language file (WSDL file) and setting up security, as this interface is designed as a secured Web service interface. The actual Web service call in the Basic sample is then a very simple query without parameters: a query for all active process templates on the server.
In the Advanced sample, the focus is on the Java code needed to perform some more advanced Web service calls. This includes constructing an input message based on a nested business object, passing the parameters when starting a process. and receiving the resposne of the successful initiation. As prerequisite for running the advanced sample, the application containing the BPEL process advertiseProcess must be deployed on the server.
The following five source files are shipped with the sample:
admin
and password admin are hardcoded and passed with the API
call.In the following, we will take a look at the most interesting code
pieces inside the JSP files.
Reference the MySecurityHelper class and use shorthands instead of
the fully qualified class names
(here, MySecurityHelper instead of com.ibm.jaxws.sample.security.MySecurityHelper)
in the remainder of the JSP file. This helper calls is used to provide
the security context for the BFM API calls:
<%@page
import="com.ibm.jaxws.sample.security.MySecurityHelper"%>
<jsp:useBean
id="BFMService"
class="com.ibm.xmlns.prod.websphere.business_process.services._7_0.binding.BFMJAXWSService"
scope="session"></jsp:useBean>
Use the Java proxy to launch the query operation:
BFMJAXWSPortType bfm = BFMService.getBFMJAXWSPort();
ProcessTemplatesType processTemplatesType = bfm.queryProcessTemplates(
null, null, null, null );
//do security
String user = request.getParameter("username");
String password = request.getParameter("password");
MySecurityHelper.enhanceWithUsernameToken(bfm, user,
password);
List listTemplates = ptt.getProcessTemplate();
This JSP file contains the code to prepare the process template and to assemble an input message object used to start a process instance. and to fill this object with the supplied parameter values. Using this input message object, a request to start a long running process is submitted to the Web service API. This is an asynchronous call, which by definition does not immediately return the result of the business process. It does, however, immediately return a handle to this business process
Reference the mySerializer class and use shorthands instead of the fully qualified class names (here,mySerializer instead of com.ibm.mySerializer.mySerializer)
in the remainder of the JSP file. The Serializer is used for the BO to
XML transformation. You also reference the MySecurityHelper, as
mentioned for the invoke.jsp, and the process and process interface
classes, hier the WSApiModule process respectively application.
<%@page
import="com.ibm.jaxws.sample.security.MySecurityHelper"%>
<%@page import="com.ibm.mySerializer.mySerializer"%>
<%@page import="wsapimodule.*"%>
<%@page import="wsapimodule.advertiseprocessinterface.*"%>
<jsp:useBean id="BFMService" class="com.ibm.xmlns.prod.websphere.business_process.services._7_0.binding.BFMJAXWSService" scope="session"></jsp:useBean>
Use the Java proxy, extended by security provider, to use the process start API later on.BFMJAXWSPortType bfm = BFMService.getBFMJAXWSPort();
MySecurityHelper.enhanceWithUsernameToken(bfm, user, password);
// Process template settings
String myOperation = "operation1"; // Interface editor: we did
use the default
String myPortTypeName = "advertiseProcessInterface"; // see
Interface editor
String myInterfaceURI = "http://WSApiModule/"+myPortTypeName; //
see IF editor
String myNamespacePrefix = "mynsprefix"; // can be any value
String myProcessTemplateName = "advertiseProcess";
// Data received from HTML form
String myFName = (String) request.getParameter("fname"); //
first name
String myLName = (String) request.getParameter("lname"); // last
name
String mySName = (String) request.getParameter("sname"); //
street name
String myCName = (String) request.getParameter("cname"); // city
name
// assemble the process input message
BOAddress address = new BOAddress();
address.setStreet( mySName );
address.setCity( myCName );
BOCustomer customer = new BOCustomer();
customer.setFirstName( myFName );
customer.setLastName( myLName );
customer.setAddress( address );
Operation1 operation1 = new Operation1();
operation1.setCustomer( customer );
// prepare parameters for starting the process
UserDataType userdata = new UserDataType();
userdata.setAny(mySerializer.getElement("wsapimodule.advertiseprocessinterface",
operation1));

<String piid = bfm.sendMessage(myProcessTemplateName, new QName(myInterfaceURI, myPortTypeName), myOperation, userdata, null);
The remainder of the startprocess.jsp file contains the code to handle the response whether the process as started successfully together with some basic exception handling. It also renders the parameterized URL for calling the viewprocess.jsp page.Reference the mySerializer class and use shorthands instead of the
fully qualified class names
(here, mySerializer instead of com.ibm.mySerializer.mySerializer)
in the remainder of the JSP file. This class includes the Deserializer
used for the demarshalling of the xml representation of the output
message into a business obejct.
<%@page
import="com.ibm.jaxws.sample.security.MySecurityHelper"%>
<%@page import="com.ibm.mySerializer.mySerializer"%>
<%@page import="wsapimodule.*"%>
<%@page import="wsapimodule.advertiseprocessinterface.*"%>
<jsp:useBean id="BFMService" class="com.ibm.xmlns.prod.websphere.business_process.services._7_0.binding.BFMJAXWSService" scope="session"></jsp:useBean>
Use the Java proxy, extended by security provider, to use BFM APIs.BFMJAXWSPortType bfm = BFMService.getBFMJAXWSPort();
MySecurityHelper.enhanceWithUsernameToken(bfm, user, password);
// Initialize the variables which we will display on
this page
String myPIID = request.getParameter("PIID"); // passed in URL
as "...?PIID=_PI:..."
String myInternalPIID = myPIID; // will be refreshed
later
String myExecutionState = null;
String myInput = "";
String myOutput = "(not available yet)";
String myOutputVarForDisplay = "";
boolean doRefresh = false;
boolean piidExists;
getProcessInstance operation and obtain the
current execution state.// get the process instance
ProcessInstanceType myProcessInstance =
bfm.getProcessInstance( myPIID
);
// get internal PIID which is required for retrieving the messages
myInternalPIID = myProcessInstance.getPiid();
// get the execution state
myExecutionState =
myProcessInstance.getExecutionState();
getProcessInstance operation, that unique name is
accepted as valid PIID value. However, in other operations that take a
PIID as input (for example, getInputMessageForProcessInstance)
the internal PIID is required.Extract the ExecutionState from the process instance object into a Java String. In case the process is still running, set a boolean variable which conditionally includes an auto-refresh directive to the HTML header:
abc
// get
the execution state
myExecutionState =
myProcessInstance.getExecutionState();
if
(myExecutionState.equals("STATE_RUNNING")) {
// still in
running state, try again in a moment
doRefresh = true;
} else if
(myExecutionState.equals("STATE_FINISHED")) {
// done, get the
output message
UserDataType
userdata_Output = bfm.getOutputMessageForProcessInstance(
myInternalPIID );
Operation1Response myGetOutputMessage = (Operation1Response)
userdata_Output.getAny();
getProcessInstance
operation:
abc
a b c
Provide the PIID which was extracted from the HTTP request, then
launch the getProcessInstance operation:
That is why the PIID is queried again from the system and stored in
the variable myInternalPIID and used in other operations
that rely on a PIID:
abc
a b c
After running the operation getInputMessageForProcessInstance,
extract the content from the response:
abc
a b c
Look for an element with XML tag "firstName"; to allow checking for null pointers, store the result of the item(0) method in a variable. If all checks for null pointers are passed successfully, concatenate the actual value to the Java variable which will be used for rendering later:
abc
a b c
Extract the ExecutionState from the process instance object into a Java String. In case the process is still running, set a boolean variable which conditionally includes an auto-refresh directive to the HTML header:
abc
a b c
When the value "STATE_FINISHED" is found as ExecutionState, the
output message is extracted in the same way as the input message has
been extracted earlier. In addition to the value, the name of the
output variable is retrieved by the getNodeName() method.
This way, the viewprocess.jsp can be used for monitoring arbitrary
long-running process instances and display the first element of the
output message.
Keep in mind though that for running process instances frequent polling
will happen, which may add some extra load to your system.
The remainder of the viewprocess.jsp file contains the code to render the process instance data as an HTML table.
Reference the MySecurityHelper class and use shorthands instead of
the fully qualified class names
(here, MySecurityHelper instead of com.ibm.jaxws.sample.security.MySecurityHelper)
in the remainder of the JSP file. This helper calls is used to provide
the security context for the BFM API calls:
<%@page
import="com.ibm.jaxws.sample.security.MySecurityHelper"%>
<jsp:useBean
id="BFMService"
class="com.ibm.xmlns.prod.websphere.business_process.services._7_0.binding.BFMJAXWSService"
scope="session"></jsp:useBean>
Use the Java proxy to launch the query operation:
BFMJAXWSPortType bfm = BFMService.getBFMJAXWSPort();
ProcessTemplatesType processTemplatesType = bfm.queryProcessTemplates(
null, null, null, null );
Reference the MySecurityHelper class and use shorthands instead of
the fully qualified class names
(here, MySecurityHelper instead of com.ibm.jaxws.sample.security.MySecurityHelper)
in the remainder of the JSP file. This helper calls is used to provide
the security context for the BFM API calls:
<%@page
import="com.ibm.jaxws.sample.security.MySecurityHelper"%>
<jsp:useBean
id="BFMService"
class="com.ibm.xmlns.prod.websphere.business_process.services._7_0.binding.BFMJAXWSService"
scope="session"></jsp:useBean>
Use the Java proxy to launch the query operation:
BFMJAXWSPortType bfm = BFMService.getBFMJAXWSPort();
ProcessTemplatesType processTemplatesType = bfm.queryProcessTemplates(
null, null, null, null );