Version 5.0 - 06/08
Asynchronous Exchange
<< 1 2 3 4 5 6 >>
Introduction
Synch vs. Asynch Operations
Getting Set Up
Use Case & Implementation
Build & Test the Requester
Build & Test the Initiator
Build & Test the Responder
Using the SOAP ReplyTo Header
Adding Message Correlation

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 File / New / Project... from the main menu. The New Project wizard appears.
Select Java Project and click Next.
Enter a project name, e.g., InitiatorClient. Accept the defaults for this page and click Next.
At the bottom of the next page change InitiatorClient/bin to InitiatorClient/classes. Click Finish to create the new Java project.
If desired, answer Yes 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 New / Other... Select Web Services / Web Service Client in the wizard selection dialog that appears and click Next. The Web Service Client wizard appears.

In the Service definition 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 Client Project:... .
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 OK.

Next, slide the indicator to the left of the 'cartoon' down from Deploy to Assemble. The resulting configuration should look like this:

 

Slider to Assemble

Click Next. If you want to generate Java source files with specific package names, check the Define custom mapping... 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 Finish. 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 Window / Open Perspective / Other / Java 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 New / Class.
Enter a Name of InitiatorClient and check the box labeled public static void main... Then click FInish. 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.

public static void main(String[] args) {
  RequesterPTProxy proxy = new RequesterPTProxy();
  Document initiateRequest = new Document();

  initiateRequest.setValue("Initiated AME from thread '" +
      Thread.currentThread().getName() + "'" );

  try {
    Document initiateResponse = new Document();

    // Invoke the Requester's initiate operation and save
    // the response.
    //
    initiateResponse = proxy.initiate( initiateRequest );
    System.out.println( "Success! Requester returned: '" +
      initiateResponse.getValue() + "'" );
  }
  catch (Exception e) {
    System.out.println( "Tried to call Requester's initiate " +
      "operation, but an exception was thrown: " +
    e.getLocalizedMessage());
    e.printStackTrace();
  }

}

Add an the following Java import to after the Java package name:

import com.activevos.docs.schema.AME.AMETypes.Document;

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 Run As... / Java Application. The response message appears in the Console (ignore warnings about attachment support):

Success! Requester returned: 'Initiated AME from thread 'main' - Requester #x'

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.