01: /*
02: * CoadunationLib: The coaduntion implementation library.
03: * Copyright (C) 2006 Rift IT Contracting
04: *
05: * This library is free software; you can redistribute it and/or
06: * modify it under the terms of the GNU Lesser General Public
07: * License as published by the Free Software Foundation; either
08: * version 2.1 of the License, or (at your option) any later version.
09: *
10: * This library is distributed in the hope that it will be useful,
11: * but WITHOUT ANY WARRANTY; without even the implied warranty of
12: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13: * Lesser General Public License for more details.
14: *
15: * You should have received a copy of the GNU Lesser General Public
16: * License along with this library; if not, write to the Free Software
17: * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18: *
19: * WebServiceInvoker.java
20: *
21: * The web service invoker inherits from the RPCProvider and is responsible for
22: * making the final call on the web service. Doing this makes it responsible for
23: * setting the thread context loader appropriatly so that the RMI stubs can be
24: * loaded from the appropriat jars.
25: */
26:
27: // The path to the package
28: package com.rift.coad.lib.webservice;
29:
30: // java imports
31: import java.lang.reflect.Method;
32:
33: // axis imports
34: import org.apache.axis.MessageContext;
35: import org.apache.axis.providers.java.RPCProvider;
36:
37: // coadunation imports
38: import com.rift.coad.lib.audit.AuditTrail;
39:
40: /**
41: * The web service invoker inherits from the RPCProvider and is responsible for
42: * making the final call on the web service. Doing this makes it responsible for
43: * setting the thread context loader appropriatly so that the RMI stubs can be
44: * loaded from the appropriat jars.
45: *
46: * @author Brett Chaldecott
47: */
48: public class WebServiceInvoker extends RPCProvider {
49:
50: // the reference to the class loader
51: private ClassLoader classLoader = null;
52:
53: /**
54: * Creates a new instance of WebServiceInvoker
55: */
56: public WebServiceInvoker(ClassLoader classLoader) {
57: this .classLoader = classLoader;
58: }
59:
60: /**
61: * This method encapsulates the method invocation.
62: *
63: * @return The object resulting from the call.
64: * @param msgContext The message context for this call.
65: * @param method The reference to the method to invoke.
66: * @param obj The target object to invoke the method on.
67: * @param argValues The method parameters.
68: * @exception Exception
69: */
70: protected Object invokeMethod(MessageContext msgContext,
71: Method method, Object obj, Object[] argValues)
72: throws Exception {
73: ClassLoader originalClassLoader = Thread.currentThread()
74: .getContextClassLoader();
75: AuditTrail auditTrail = AuditTrail.getAudit(obj.getClass());
76: try {
77: Thread.currentThread().setContextClassLoader(
78: this .classLoader);
79: Object result = method.invoke(obj, argValues);
80: auditTrail.logEvent(method.getName());
81: return result;
82: } catch (java.lang.reflect.InvocationTargetException ex) {
83: auditTrail.logEvent(method.getName(), ex
84: .getTargetException());
85: throw (Exception) ex.getTargetException();
86: } catch (Exception ex) {
87: auditTrail.logEvent(method.getName(), ex);
88: throw ex;
89: } finally {
90: Thread.currentThread().setContextClassLoader(
91: originalClassLoader);
92: }
93: }
94:
95: }
|