1 23 package com.sun.ejb.containers; 24 25 import javax.ejb.EJBException ; 26 import javax.ejb.AccessLocalException ; 27 28 import java.lang.reflect.InvocationHandler ; 29 import java.lang.reflect.InvocationTargetException ; 30 import java.lang.reflect.Proxy ; 31 import java.lang.reflect.Method ; 32 33 import java.util.Map ; 34 import com.sun.ejb.Invocation; 35 import com.sun.enterprise.Switch; 36 import com.sun.ejb.ComponentContext; 37 import com.sun.ejb.InvocationInfo; 38 import com.sun.enterprise.InvocationManager; 39 import com.sun.ejb.Container; 40 import com.sun.enterprise.deployment.EjbDescriptor; 41 import com.sun.enterprise.deployment.WebServiceEndpoint; 42 43 import com.sun.ejb.containers.util.InvocationHandlerUtil; 44 45 53 54 public final class WebServiceInvocationHandler extends EJBLocalRemoteObject 55 implements InvocationHandler { 56 57 private WebServiceEndpoint endpoint_; 58 private Class ejbClass_; 59 private Class serviceEndpointIntfClass_; 60 private InvocationManager invManager_; 61 private boolean hasHandlers_; 62 private Map invocationInfoMap_; 63 64 public WebServiceInvocationHandler(Class ejbClass, 65 WebServiceEndpoint endpoint, 66 Class serviceEndpointIntfClass, 67 Map invocationInfoMap) { 68 ejbClass_ = ejbClass; 69 serviceEndpointIntfClass_ = serviceEndpointIntfClass; 70 endpoint_ = endpoint; 71 hasHandlers_ = endpoint.hasHandlers(); 72 Switch theSwitch = Switch.getSwitch(); 73 invManager_ = theSwitch.getInvocationManager(); 74 invocationInfoMap_ = invocationInfoMap; 75 } 76 77 public Object invoke(Object proxy, Method method, Object [] args) 78 throws Throwable { 79 try { 80 container.onEnteringContainer(); 81 84 Class methodClass = method.getDeclaringClass(); 85 if( methodClass == java.lang.Object .class ) { 86 return InvocationHandlerUtil. 87 invokeJavaObjectMethod(this, method, args); 88 } 89 90 Object returnValue = null; 91 Invocation inv = null; 92 93 try { 94 inv = (Invocation) invManager_.getCurrentInvocation(); 96 97 inv.ejbObject = this; 98 99 if (endpoint_.getServiceEndpointInterface().equals(ejbClass_.getName())) { 103 method = ejbClass_.getMethod(method.getName(), method.getParameterTypes()); 105 } 106 inv.method = method; 107 inv.clientInterface = serviceEndpointIntfClass_; 108 109 inv.invocationInfo = (InvocationInfo) 110 invocationInfoMap_.get(inv.method); 111 112 if( inv.invocationInfo == null ) { 113 throw new EJBException 114 ("Web service Invocation Info lookup failed for " + 115 "method " + inv.method); 116 } 117 118 inv.transactionAttribute = inv.invocationInfo.txAttr; 119 120 if( hasHandlers_ ) { 121 } else { 123 StatelessSessionContainer container = 124 (StatelessSessionContainer) getContainer(); 125 126 boolean authorized = container.authorize(inv); 127 if( !authorized ) { 128 throw new AccessLocalException ("Client not authorized " + 129 "to access " + inv.method); 130 } 131 } 132 133 ComponentContext ctx = container.getContext(inv); 134 inv.context = ctx; 135 inv.ejb = ctx.getEJB(); 136 inv.instance = inv.ejb; 137 138 container.preInvokeTx(inv); 139 140 Method beanClassMethod = ejbClass_.getMethod 144 (method.getName(), method.getParameterTypes()); 145 inv.beanMethod = beanClassMethod; 146 inv.methodParams = args; 147 returnValue = container.intercept(inv); 148 } catch(NoSuchMethodException nsme) { 149 inv.exception = nsme; 150 } catch(InvocationTargetException ite) { 151 inv.exception = ite.getCause(); 152 } catch(Throwable c) { 153 inv.exception = c; 154 } finally { 155 } 157 if (inv.exception != null) { 158 if(inv.exception instanceof java.lang.RuntimeException ) { 159 throw (java.lang.RuntimeException )inv.exception; 160 } else if (inv.exception instanceof Exception ) { 161 throw inv.exception; 162 } else { 163 EJBException ejbEx = new EJBException (); 164 ejbEx.initCause(inv.exception); 165 throw ejbEx; 166 } 167 } 168 return returnValue; 169 } finally { 170 container.onLeavingContainer(); 171 } 172 } 173 174 } 175 | Popular Tags |