Example usage for javax.ejb Handle getEJBObject

List of usage examples for javax.ejb Handle getEJBObject

Introduction

In this page you can find the example usage for javax.ejb Handle getEJBObject.

Prototype

public EJBObject getEJBObject() throws RemoteException;

Source Link

Document

Obtain the EJB object reference represented by this handle.

Usage

From source file:org.openamf.invoker.EJBServiceInvoker.java

public Object invokeService() throws ServiceInvocationException {
    Object serviceResult = null;//w  w w  . j  a  v a  2  s . c  o m
    try {
        Object ejb = null;

        if (persistService) {
            log.debug("Trying to get Handle from persistentObject");
            Handle handle = (Handle) getPersistentServiceObject();
            if (handle != null) {
                log.debug("Got Handle from persistentObject");
                ejb = handle.getEJBObject();
            }
        }

        if (ejb == null) {
            if (home == null) {
                log.warn("Home is NULL - unable to find EJB " + request.getServiceName());
                return null;
            }
            Method ejbCreateMethod = home.getClass().getMethod("create", new Class[0]);
            log.info("Calling Create Method: " + request.getServiceName());
            ejb = ejbCreateMethod.invoke(home, new Object[0]);
        }

        serviceResult = invokeServiceMethod(ejb, ejb.getClass(), request.getServiceMethodName(),
                request.getParameters());

        if (persistService) {
            if (ejb instanceof EJBObject) {
                log.debug("setting persistentObject = Handle");
                setPersistentServiceObject(((EJBObject) ejb).getHandle());
            }
        }

    } catch (InvocationTargetException e) {
        //use the cause since the exception is thrown when 
        //the service method throws an exception
        throw new ServiceInvocationException(request, e.getTargetException());
    } catch (Exception e) {
        throw new ServiceInvocationException(request, e);
    }
    return serviceResult;
}