ActiveVOS Server User’s Guide

Example J2EE Web Service Endpoint

Here is an example of how the My Role partner link from the loan approval process is mapped to a Java service endpoint interface.

package com.MyPackage.example; 
import com.activee.wsio.receive;
import java.rmi.RemoteException;
import javax.ejb.CreateException;
import javax.naming.InitialContext;
import javax.rmi.PortableRemoteObject;
import javax.xml.namespace.QName;
import javax.xml.rpc.ServiceException;
import javax.xml.rpc.server.ServiceLifecycle;
import org.activebpel.wsio;
import org.activebpel.wsio.receive;
/** * Implementation of the loan approver endpoint
 */
public class AeLoanApproverEndpointImpl implements
 AeLoanApproverEndpoint, ServiceLifecycle
{

      
public String approve(String aFirstName, String aName, 
     Integer aAmount) throws RemoteException,
       AeLoanProcessFault
{
    AeMessageContext context = new AeMessageContext();
    context.setOperation("approve");
    context.setPartnerLinkName("approver");
    context.setProcessName(new QName("http://acme.com/
         loanprocessing", "loanApprover"));
    context.setPrincipal(“MyAuthorizedUser”);
    AeWebServiceMessageData data = new
      AeWebServiceMessageData(new QName("http://tempuri.org/
     services/loandefinitions", "creditInformationMessage"));
    data.setData("firstName", aFirstName);
    data.setData("name", aName);
    data.setData("amount", aAmount);

      
IAeWebServiceResponse response = null;
   try
   {
     response = getMessageQueueRemote().queueReceiveData
      (data, context);
   }
      catch (AeRequestException e)
      {
         e.printStackTrace();
         throw new AeLoanProcessFault();
      }
      
      if (response.isFaultResponse())
      {
         throw new AeLoanProcessFault();
      }
      
      IAeWebServiceMessageData responseData =
        response.getMessageData();
      return (String)
        responseData.getMessageData().get("accept");
   }
   /**
    * @see javax.xml.rpc.server.ServiceLifecycle#destroy()
    */
   public void destroy()
   {
   }
   /**
    * @see
 javax.xml.rpc.server.ServiceLifecycle#init(java.lang.Object)
    */
   public void init(Object arg0) throws ServiceException
   {
   }
   
   /**
    * @return Returns the home for the engine dispatch.
    */
   protected AeMessageQueueHome getMessageQueueHome()
   {
      try
      { 
         InitialContext initContext = new InitialContext();
         String JNDIName = "java:comp/env/
            ejb/AeMessageQueueBean";
         Object objref = initContext.lookup(JNDIName);
         AeMessageQueueHome home = 
            (AeMessageQueueHome)
            PortableRemoteObject.narrow(objref,
            AeMessageQueueHome.class);
         return home;
      }
      catch (Exception ex)
      {
         ex.printStackTrace();
         throw new RuntimeException("can't call home");
      }
   }
   /**
    * @return Returns the message queue remote.
    * @throws RemoteException
    */
   protected AeMessageQueueRemote getMessageQueueRemote()
    throws RemoteException
   {
      try
      {
         return getMessageQueueHome().create();
      }
      catch (CreateException ex)
      {
         ex.printStackTrace();
         throw new RemoteException("Unable to create ejb");
      }
   }
}

For information on implementing a service endpoint, see:

Note the following about this example: