1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.geronimo.ews.ws4j2ee.wsutils;
18
19 import org.apache.axis.AxisFault;
20 import org.apache.axis.MessageContext;
21 import org.apache.axis.handlers.soap.SOAPService;
22 import org.apache.axis.providers.java.RPCProvider;
23 import org.apache.axis.utils.ClassUtils;
24
25 import java.io.InputStream;
26 import java.lang.reflect.Method;
27
28 /***
29 * register the MessageContext in the jax-rpc runtime of the JSR109
30 *
31 * @author Srinath Perera(hemapani@opensource.lk)
32 */
33 public class EWSProvider extends RPCProvider {
34 public static final String OPTION_EJB_NAME = "beanName";
35 public static final String OPTION_JNDI_LOOKUP_NAME = "beanJndiName";
36 public static final String OPTION_HOMEINTERFACE_NAME = "homeInterfaceName";
37 public static final String OPTION_REMOTEINTERFACE_NAME = "remoteInterfaceName";
38 public static final String OPTION_LOCALHOMEINTERFACE_NAME = "localHomeInterfaceName";
39 public static final String OPTION_LOCALINTERFACE_NAME = "localInterfaceName";
40 public static final String OPTION_USE_EJB = "j2eeStyle";
41
42 private String ejblookupName;
43 private String localhome;
44 private String home;
45 private String remote;
46 private String local;
47
48 private boolean ejbbased = false;
49
50 protected Object makeNewServiceObject(MessageContext msgContext,
51 String clsName)
52 throws Exception {
53 SOAPService service = msgContext.getService();
54 String j2eeStyle = (String) service.getOption(OPTION_USE_EJB);
55 if("ejb".equals(j2eeStyle) ){
56 java.util.Properties env = new java.util.Properties();
57 InputStream jndiIn = ClassUtils.getResourceAsStream(getClass(), "jndi.properties");
58 if (jndiIn != null) {
59 env.load(jndiIn);
60 } else {
61 throw new AxisFault("Do not find the JNDI properties file in the class path");
62 }
63 javax.naming.Context initial = new javax.naming.InitialContext(env);
64 ejblookupName = (String) service.getOption(OPTION_JNDI_LOOKUP_NAME);
65 remote = (String) service.getOption(OPTION_REMOTEINTERFACE_NAME);
66 home = (String) service.getOption(OPTION_HOMEINTERFACE_NAME);
67 local = (String) service.getOption(OPTION_LOCALINTERFACE_NAME);
68 localhome = (String) service.getOption(OPTION_LOCALHOMEINTERFACE_NAME);
69 if (remote != null && home != null && ejblookupName != null) {
70 Object objref = initial.lookup(ejblookupName);
71 Class homeClass = ClassUtils.forName(home);
72 Object homeObj = javax.rmi.PortableRemoteObject.narrow(objref, homeClass);
73 Method method = homeClass.getMethod("create", new Class[]{});
74 return method.invoke(homeObj, new Object[]{});
75 } else if (local != null && localhome != null && ejblookupName != null) {
76 Object homeObj = initial.lookup("java:comp/" + ejblookupName);
77 Class homeClass = ClassUtils.forName(localhome);
78 Method method = homeClass.getMethod("create", new Class[]{});
79 return method.invoke(homeObj, new Object[]{});
80 }
81 throw new AxisFault("Wrong configuration remote="+ remote + "home =" + home + "ejblookupName" + ejblookupName );
82 } else {
83 return super.makeNewServiceObject(msgContext, clsName);
84 }
85 }
86
87 protected Object invokeMethod(MessageContext msgContext,
88 Method method,
89 Object obj,
90 Object[] argValues)
91 throws Exception {
92 Method invokeMethod = obj.getClass().getMethod(method.getName(), method.getParameterTypes());
93 return invokeMethod.invoke(obj, argValues);
94 }
95 }