Asynchronous Message Exchange, cont.
Build & Test the Initiator
As mentioned previously, the Initiator component of our composite application is implemented in Java, as will be the case in many J2EE environments. It could just as easily be implemented in PHP, Ruby or any other web-services-capable language.
ActiveVOS ships with plug-ins and wizards for Java and Web Service development, so we can create a functional web service client in about 5 minutes provided that we have a valid WSDL file, which in this case we do.
Generating a Web Service Client from WSDL
To begin, we'll need an empty Java project into which our client application can be generated, so let's create that first, then we'll generate the application based on information from our deployed Requester service.
| Select from the main menu. The New Project wizard appears. | |
| Select and click . | |
| Enter a project name, e.g., InitiatorClient. Accept the defaults for this page and click . | |
| At the bottom of the next page change InitiatorClient/bin to InitiatorClient/classes. Click to create the new Java project. | |
| If desired, answer to associate the project with the Java perspective (but don't switch to that perspective when the project is created). | |
Right-click on the AsynchMessageExchange project root (in Project Explorer) and use the pop-up, cascading menu to select Select in the wizard selection dialog that appears and click . The Web Service Client wizard appears. |
|
| In the field, once again copy and paste the Requester's deployed WSDL URL Again, that URL is typically as follows: | |
http://localhost:8080/active-bpel/services/RequesterService?wsdl |
|
| To the right of the sequence 'cartoon' in the center of the dialog, under Configuration, click on ... . | |
| In the Specify Client Project Settings dialog that appears, select the new Java project you just created - e.g., InitiatorClient - from the drop-down list at the top. Click . | |
Next, slide the indicator to the left of the 'cartoon' down from Deploy to Assemble. The resulting configuration should look like this:
|
|
| Click . If you want to generate Java source files with specific package names, check the checkbox and see the WTP documentation for details. If not, leave the box unchecked - the default settings will use the WSDL target namespace definitions to create Java package names. | |
| Click . After about 5-10 seconds, your Java client source files should be generated. Expand and examine the contents of your InitiatorClient Project to view the generated Java source files. | |
Implementing the Initiator
Once the web service client support files are generated, all we need to do is create a class that uses them to invoke the Requester process' initiate operation. The generated artifacts include a Java class called RequesterPTProxy.java. This is the class that will act as our proxy to do the invocation. If you're not familiar with the details of Java-based web service invocation, now would be a good time to review the Java class hierarchy that supports RequesterPTProxy.
To use RequesterPTProxy, we create a new Java class - InitiatorClient - and add the few lines of code needed to send the web service request and receive the response.
| Switch to the Eclipse Java Perspective by selecting from the main menu. | |
| Expand the InitiatorClient project in the Package Explorer and navigate to the package where you want your new class to be created (i.e. src/com.activevos.docs.wsdl.AME.Requester). Right-click on that folder and select . | |
| Enter a of InitiatorClient and check the box labeled Then click . A new Java file appears in the editor. | |
| Add the following Java code to the main() method stub provided by the class generator. This will create instances of RequesterPTProxy and Document, and use them to invoke the initiate operation on the RequesterService. The response is displayed via stdout. | |
|
|
|
Add an the following Java import to after the Java package name:
|
|
|
|
Save InitiatorClient.java (verify that there are no errors). Ensure that the embedded server is still running and then right-click on InitiatorClient.java in the Package Explorer. Select . The response message appears in the Console (ignore warnings about attachment support):
Where x is the numeric ID of the Requester process instance that responded. If you get an error message, you'll need to go back and review the preceding steps.
If you like, you can verify the error handling section by shutting down the Server (momentarily switch back to the ActiveVOS Perspective to do this) and re-running InitiatorClient. This will force a "Connection refused: connect" exception, with accompanying stack trace. |
|
When you've successfully tested the Requester process using Initiator (i.e., InitiatorClient.java), you're ready to move on to the next step: implementing an asynchronous service using BPEL.
Copyright © 2004–2008 Active Endpoints, Inc.

