1 7 8 10 package org.jboss.net.axis.server; 11 12 import org.jboss.axis.AxisFault; 13 import org.jboss.axis.MessageContext; 14 import org.jboss.axis.description.OperationDesc; 15 import org.jboss.axis.description.ServiceDesc; 16 import org.jboss.axis.handlers.soap.SOAPService; 17 import org.jboss.axis.message.SOAPEnvelopeAxisImpl; 18 19 import javax.naming.NamingException ; 20 import javax.servlet.http.HttpSessionBindingEvent ; 21 import javax.servlet.http.HttpSessionBindingListener ; 22 import javax.xml.rpc.server.ServiceLifecycle ; 23 import java.lang.reflect.Method ; 24 import java.util.ArrayList ; 25 import java.util.Iterator ; 26 27 58 59 public class EJBProvider extends org.jboss.axis.providers.java.EJBProvider 60 { 61 62 66 67 protected Class remoteClass; 68 69 70 protected Object ejbHome; 71 72 73 protected Method ejbCreateMethod; 74 75 79 80 public EJBProvider() 81 { 82 } 83 84 88 92 93 protected synchronized Object getEJBHome(String jndiName) 94 throws NamingException 95 { 96 if (ejbHome == null) 97 { 98 ejbHome = this.getCachedContext().lookup(jndiName); 100 } 101 return ejbHome; 102 } 103 104 108 109 protected synchronized Method getEJBCreateMethod(String jndiName) 110 throws NamingException , NoSuchMethodException 111 { 112 if (ejbCreateMethod == null) 113 { 114 Object ejbHome = getEJBHome(jndiName); 115 ejbCreateMethod = 116 ejbHome.getClass().getMethod("create", empty_class_array); 117 } 118 119 return ejbCreateMethod; 120 } 121 122 129 protected Object makeNewServiceObject(MessageContext msgContext, 130 String clsName) 131 throws Exception 132 { 133 134 Object ejbHome = getEJBHome(clsName); 136 Method createMethod = getEJBCreateMethod(clsName); 139 return new EJBServiceLifeCycle(createMethod.invoke(ejbHome, empty_object_array)); 141 } 142 143 148 149 protected synchronized Class getServiceClass(String beanJndiName, 150 SOAPService service, 151 MessageContext msgContext) 152 throws AxisFault 153 { 154 if (remoteClass == null) 155 { 156 157 try 158 { 159 remoteClass = getEJBCreateMethod(beanJndiName).getReturnType(); 160 } 161 catch (NamingException e) 162 { 163 throw new AxisFault("Could not find home in JNDI", e); 164 } 165 catch (NoSuchMethodException e) 166 { 167 throw new AxisFault("Could not find create method at home ;-)", e); 168 } 169 } 170 171 return remoteClass; 172 } 173 174 178 183 184 public void generateWSDL(MessageContext msgContext) throws AxisFault 185 { 186 187 if (msgContext != null) 189 { 190 191 boolean isSoapAction = 192 msgContext.getProperty(Constants.ACTION_HANDLER_PRESENT_PROPERTY) 193 == Boolean.TRUE; 194 195 for (Iterator alloperations = 197 msgContext 198 .getService() 199 .getServiceDescription() 200 .getOperations() 201 .iterator(); 202 alloperations.hasNext(); 203 ) 204 { 205 OperationDesc opDesc = (OperationDesc)alloperations.next(); 206 opDesc.setSoapAction(isSoapAction ? msgContext.getService().getName() : null); 208 } 209 } 210 211 super.generateWSDL(msgContext); 212 } 213 214 218 public void processMessage(MessageContext msgContext, 219 SOAPEnvelopeAxisImpl reqEnv, 220 SOAPEnvelopeAxisImpl resEnv, 221 Object obj) 222 throws Exception 223 { 224 super.processMessage(msgContext, 225 reqEnv, 226 resEnv, 227 ((EJBServiceLifeCycle)obj).serviceObject); 228 } 229 230 234 public void initServiceDesc(SOAPService service, MessageContext msgContext) 235 throws AxisFault 236 { 237 241 ServiceDesc serviceDescription = service.getServiceDescription(); 242 ArrayList stopClasses = serviceDescription.getStopClasses(); 243 if (stopClasses == null) 244 stopClasses = new ArrayList (); 245 stopClasses.add("javax.ejb.EJBObject"); 246 stopClasses.add("javax.ejb.EJBLocalObject"); 247 serviceDescription.setStopClasses(stopClasses); 248 249 super.initServiceDesc(service, msgContext); 250 } 251 252 256 260 261 protected static class EJBServiceLifeCycle 262 implements ServiceLifecycle , HttpSessionBindingListener 263 { 264 265 269 270 protected Object serviceObject; 271 272 276 277 protected EJBServiceLifeCycle(Object serviceObject) 278 { 279 this.serviceObject = serviceObject; 280 } 281 282 286 290 public void destroy() 291 { 292 try 293 { 294 if (serviceObject instanceof javax.ejb.EJBObject ) 295 { 296 try 297 { 298 ((javax.ejb.EJBObject )serviceObject).remove(); 299 } 300 catch (java.rmi.RemoteException e) 301 { 302 } 303 } 304 else 305 { 306 ((javax.ejb.EJBLocalObject )serviceObject).remove(); 307 } 308 } 309 catch (javax.ejb.RemoveException e) 310 { 311 } 312 catch (Exception e) 313 { 314 } 322 } 323 324 328 public void init(Object arg0) 329 { 330 } 331 332 335 public void valueBound(HttpSessionBindingEvent arg0) 336 { 337 init(arg0); 338 } 339 340 343 public void valueUnbound(HttpSessionBindingEvent arg0) 344 { 345 destroy(); 346 } 347 348 } 350 } | Popular Tags |