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