KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > webservice > server > InvokerProviderEJB


1 /*
2  * JBoss, the OpenSource J2EE webOS
3  *
4  * Distributable under LGPL license.
5  * See terms of license at gnu.org.
6  */

7
8 // $Id: InvokerProviderEJB.java,v 1.11.4.4 2005/04/12 16:07:47 starksm Exp $
9
package org.jboss.webservice.server;
10
11 // $Id: InvokerProviderEJB.java,v 1.11.4.4 2005/04/12 16:07:47 starksm Exp $
12

13 import org.jboss.axis.AxisFault;
14 import org.jboss.axis.MessageContext;
15 import org.jboss.axis.handlers.soap.SOAPService;
16 import org.jboss.invocation.Invocation;
17 import org.jboss.invocation.InvocationKey;
18 import org.jboss.invocation.InvocationType;
19 import org.jboss.logging.Logger;
20 import org.jboss.metadata.ApplicationMetaData;
21 import org.jboss.metadata.BeanMetaData;
22 import org.jboss.security.SecurityAssociation;
23 import org.jboss.webservice.Constants;
24
25 import javax.management.MBeanException JavaDoc;
26 import javax.management.MalformedObjectNameException JavaDoc;
27 import javax.management.ObjectName JavaDoc;
28 import java.lang.reflect.Method JavaDoc;
29 import java.security.Principal JavaDoc;
30
31 /**
32  * An Axis RPC provider for EJB endpoints.
33  *
34  * @author Thomas.Diesler@jboss.org
35  * @since 15-April-2004
36  */

37 public class InvokerProviderEJB extends InvokerProvider
38 {
39    /** @since */
40    static final long serialVersionUID = 7848928202043133442L;
41    // provide logging
42
private Logger log = Logger.getLogger(InvokerProviderEJB.class);
43
44    private String JavaDoc jndiName;
45    private ObjectName JavaDoc containerName;
46
47    /**
48     * Get deployment meta info
49     */

50    public void initServiceDesc(SOAPService service, MessageContext msgContext) throws AxisFault
51    {
52       super.initServiceDesc(service, msgContext);
53
54       String JavaDoc ejbLink = portComponentInfo.getPortComponentMetaData().getEjbLink();
55       if (ejbLink == null)
56          throw new ServiceException("Cannot obtain ejb-link from port component");
57
58       ApplicationMetaData applMetaData = (ApplicationMetaData)portComponentInfo.getDeploymentInfo().metaData;
59       BeanMetaData beanMetaData = (BeanMetaData)applMetaData.getBeanByEjbName(ejbLink);
60       if (beanMetaData == null)
61          throw new ServiceException("Cannot obtain ejb meta data for: " + ejbLink);
62
63       // verify the service endpoint
64
String JavaDoc sei = portComponentInfo.getPortComponentMetaData().getServiceEndpointInterface();
65       String JavaDoc serviceEndpoint = beanMetaData.getServiceEndpoint();
66       if (sei.equals(serviceEndpoint) == false)
67          throw new ServiceException("The <" + sei + "> does not correspond to <" + serviceEndpoint + "> in ejb-jar.xml");
68
69       // get the bean's JNDI name
70
jndiName = beanMetaData.getContainerObjectNameJndiName();
71       if (jndiName == null)
72          throw new ServiceException("Cannot obtain JNDI name for: " + ejbLink);
73
74       try
75       {
76          containerName = new ObjectName JavaDoc("jboss.j2ee:jndiName=" + jndiName + ",service=EJB");
77       }
78       catch (MalformedObjectNameException JavaDoc e)
79       {
80          throw new ServiceException(e.toString());
81       }
82    }
83
84    /**
85     * Get the context CLassLoader for this service
86     */

87    protected ClassLoader JavaDoc getContextClassLoader()
88    {
89       return portComponentInfo.getDeploymentInfo().ucl;
90    }
91
92    /**
93     * The actual invocation is done through the container, not through this object.
94     */

95    protected Object JavaDoc makeNewServiceObject(MessageContext msgContext, String JavaDoc className) throws Exception JavaDoc
96    {
97       log.debug("makeNewServiceObject: class=" + className);
98       return null;
99    }
100
101    /**
102     * This method encapsulates the method invocation.
103     *
104     * @param msgContext MessageContext
105     * @param method the target method.
106     * @param obj the target object
107     * @param argValues the method arguments
108     */

109    protected Object JavaDoc invokeServiceEndpoint(MessageContext msgContext,
110                                           Method JavaDoc method, Object JavaDoc obj, Object JavaDoc[] argValues)
111            throws Exception JavaDoc
112    {
113       log.debug("Invoke EJB: " + method);
114
115       // these are provided by the ServerLoginHandler
116
Principal JavaDoc principal = SecurityAssociation.getPrincipal();
117       Object JavaDoc credential = SecurityAssociation.getCredential();
118
119       // set the handler chain in the message context
120
msgContext.setProperty(Constants.HANDLER_CHAIN, handlerChain);
121
122       // setup the invocation
123
Invocation inv = new Invocation(null, method, argValues, null, principal, credential);
124       inv.setValue(InvocationKey.SOAP_MESSAGE_CONTEXT, msgContext);
125       inv.setValue(InvocationKey.SOAP_MESSAGE, msgContext.getMessage());
126       inv.setType(InvocationType.SERVICE_ENDPOINT);
127
128       // invoke on the container
129
Object JavaDoc[] invArgs = {inv};
130       String JavaDoc[] sig = {Invocation.class.getName()};
131       Object JavaDoc ret = server.invoke(containerName, "invoke", invArgs, sig);
132       return ret;
133    }
134
135    /** Unwrap a potential MBeanException
136     */

137    protected void processException(Exception JavaDoc ex) throws AxisFault
138    {
139       Exception JavaDoc cause = ex;
140
141       // Unwrap the MBeanException
142
if (ex instanceof MBeanException JavaDoc && ex.getCause() instanceof Exception JavaDoc)
143          cause = (Exception JavaDoc)ex.getCause();
144
145       super.processException(cause);
146    }
147 }
148
Popular Tags