KickJava   Java API By Example, From Geeks To Geeks.

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


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: InvokerProviderJSE.java,v 1.11.4.2 2005/04/12 16:07:48 starksm Exp $
9
package org.jboss.webservice.server;
10
11 // $Id: InvokerProviderJSE.java,v 1.11.4.2 2005/04/12 16:07:48 starksm Exp $
12

13 import org.jboss.axis.MessageContext;
14 import org.jboss.axis.providers.java.RPCInvocation;
15 import org.jboss.axis.providers.java.RPCProvider;
16 import org.jboss.logging.Logger;
17 import org.jboss.metadata.WebMetaData;
18 import org.jboss.webservice.Constants;
19
20 import java.lang.reflect.Method JavaDoc;
21 import java.util.HashMap JavaDoc;
22 import java.util.Map JavaDoc;
23
24 /**
25  * An Axis RPC provider for WEB endpoints.
26  *
27  * @author Thomas.Diesler@jboss.org
28  * @since 15-April-2004
29  */

30 public class InvokerProviderJSE extends InvokerProvider
31 {
32    /** @since 4.0.2 */
33    static final long serialVersionUID = 17292705231485822L;
34    // provide logging
35
private Logger log = Logger.getLogger(InvokerProviderJSE.class);
36
37    // maps the SEI Method to the endpoint bean Method
38
private Map JavaDoc methodMap = new HashMap JavaDoc();
39
40    /**
41     * Create an instance of the service endpoint bean
42     */

43    protected Object JavaDoc makeNewServiceObject(MessageContext msgContext, String JavaDoc className) throws Exception JavaDoc
44    {
45       log.debug("makeNewServiceObject: class=" + className);
46
47       String JavaDoc serviceEndpointBean = portComponentInfo.getPortComponentMetaData().getServiceEndpointBean();
48       if (serviceEndpointBean == null)
49          throw new ServiceException("Service endpoint bean class not set");
50
51       // set the context class loader in the msgContext
52
ClassLoader JavaDoc ctxLoader = getContextClassLoader();
53       msgContext.setClassLoader(ctxLoader);
54
55       Object JavaDoc obj = super.makeNewServiceObject(msgContext, serviceEndpointBean);
56       return obj;
57    }
58
59    /**
60     * Before and after we call the service endpoint bean, we process the handler chains.
61     * <p/>
62     * The handler chain implemantation may replace the RPCInvocation object in the message context
63     * if it finds the the handlers have modyfied the SOAPEnvelope.
64     * <p/>
65     * When you change the implementation here, make sure you do the same in the ServiceEndpointInterceptor
66     */

67    protected Object JavaDoc invokeTarget(RPCInvocation invocation) throws Exception JavaDoc
68    {
69       MessageContext msgContext = invocation.getMessageContext();
70
71       try
72       {
73          // Call the request handler chain
74
if (handlerChain.handleRequest(msgContext) == false)
75          {
76             log.warn("FIXME: handlerChain.handleRequest() returned false");
77             return null;
78          }
79
80          // The handler chain might have replaced the invocation object
81
invocation = (RPCInvocation)msgContext.getProperty(RPCProvider.RPC_INVOCATION);
82       }
83       catch (Exception JavaDoc e)
84       {
85          log.error("Error processing request handler chain", e);
86          throw e;
87       }
88
89       Object JavaDoc retObj = null;
90       try
91       {
92          // back to the RPCInvoker, that will call the service endpoint
93
retObj = super.invokeTarget(invocation);
94       }
95       catch (Exception JavaDoc e)
96       {
97          msgContext.setProperty(Constants.LAST_FAULT, e);
98          log.error("Error from service endpoint, processing fault handler chain", e);
99
100          // Call the fault handler chain
101
if (handlerChain.handleFault(msgContext) == false)
102          {
103             log.warn("FIXME: handlerChain.handleFault() returned false");
104             return null;
105          }
106
107          // Throw the exception from the service endpoint to axis
108
throw e;
109       }
110
111       try
112       {
113          // Prepare the response envelope for the response handlers
114
invocation.prepareResponseEnvelope(retObj);
115
116          // Call the response handler chain
117
if (handlerChain.handleResponse(msgContext) == false)
118          {
119             log.warn("FIXME: handlerChain.handleResponse() returned false");
120             return null;
121          }
122       }
123       catch (Exception JavaDoc e)
124       {
125          log.error("Error processing response handler chain", e);
126          throw e;
127       }
128
129       return retObj;
130    }
131
132    /**
133     * This method encapsulates the method invocation.
134     *
135     * @param msgContext MessageContext
136     * @param method the target method.
137     * @param obj the target object
138     * @param argValues the method arguments
139     */

140    protected Object JavaDoc invokeServiceEndpoint(MessageContext msgContext, Method JavaDoc method, Object JavaDoc obj, Object JavaDoc[] argValues)
141            throws Exception JavaDoc
142    {
143       log.debug("Invoke JSE: " + method);
144
145       // map the SEI method to the bean method
146
Method JavaDoc beanMethod = (Method JavaDoc)methodMap.get(method);
147       if (beanMethod == null)
148       {
149          beanMethod = obj.getClass().getMethod(method.getName(), method.getParameterTypes());
150          methodMap.put(method, beanMethod);
151       }
152
153       // invoke the bean method
154
Object JavaDoc retObj = beanMethod.invoke(obj, argValues);
155       return retObj;
156    }
157
158    /**
159     * Get the context CLassLoader for this service
160     */

161    protected ClassLoader JavaDoc getContextClassLoader()
162    {
163       WebMetaData metaData = (WebMetaData)portComponentInfo.getDeploymentInfo().metaData;
164       return metaData.getContextLoader();
165    }
166 }
167
Popular Tags