View Javadoc

1   /*
2    * $Id: EjbConnector.java 19191 2010-08-25 21:05:23Z tcarlson $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
5    *
6    * The software in this package is published under the terms of the CPAL v1.0
7    * license, a copy of which has been included with this distribution in the
8    * LICENSE.txt file.
9    */
10  
11  package org.mule.transport.ejb;
12  
13  import org.mule.api.MuleContext;
14  import org.mule.api.endpoint.ImmutableEndpoint;
15  import org.mule.transport.rmi.RmiConnector;
16  import org.mule.util.ClassUtils;
17  
18  import java.lang.reflect.Method;
19  import java.net.UnknownHostException;
20  import java.rmi.Remote;
21  import java.rmi.RemoteException;
22  
23  import javax.ejb.EJBObject;
24  
25  /**
26   * Provides Connection configurstion for EJB endpoints
27   */
28  
29  public class EjbConnector extends RmiConnector
30  {
31      public static final String EJB = "ejb";
32  
33      // Errorcodes
34      public static final int EJB_SERVICECLASS_INVOCATION_FAILED = 2;
35  
36      public EjbConnector(MuleContext context)
37      {
38          super(context);
39      }
40      
41      public String getProtocol()
42      {
43          return EJB;
44      }
45  
46      public Remote getRemoteObject(ImmutableEndpoint endpoint) throws RemoteException, UnknownHostException
47      {
48          EJBObject remoteObj;
49  
50          try
51          {
52              Object ref = getRemoteRef(endpoint);
53  
54              Method method = ClassUtils.getMethod(ref.getClass(), "create", null);
55  
56              remoteObj = (EJBObject)method.invoke(ref);
57          }
58          catch (Exception e)
59          {
60              throw new RemoteException("Remote EJBObject lookup failed for '" + endpoint.getEndpointURI(), e);
61          }
62  
63          return remoteObj;
64      }
65  }