1 17 package org.objectweb.jonas_ejb.container; 18 19 import java.rmi.RemoteException ; 20 import java.util.HashMap ; 21 import java.util.Iterator ; 22 import java.util.Map ; 23 24 import javax.ejb.EJBException ; 25 import javax.naming.Context ; 26 import javax.naming.NamingException ; 27 import javax.naming.Reference ; 28 import javax.naming.StringRefAddr ; 29 import javax.xml.namespace.QName ; 30 import javax.xml.soap.SOAPBody ; 31 import javax.xml.soap.SOAPElement ; 32 import javax.xml.soap.SOAPEnvelope ; 33 import javax.xml.soap.SOAPException ; 34 35 import org.apache.axis.AxisFault; 36 import org.apache.axis.MessageContext; 37 38 import org.objectweb.jonas_ejb.deployment.api.MethodDesc; 39 import org.objectweb.jonas_ejb.deployment.api.SessionStatelessDesc; 40 import org.objectweb.jonas_ejb.lib.BeanNaming; 41 import org.objectweb.jonas_ejb.lib.EJBInvocation; 42 43 import org.objectweb.jonas.common.Log; 44 45 import org.objectweb.util.monolog.api.BasicLevel; 46 import org.objectweb.util.monolog.api.Logger; 47 48 52 public abstract class JServiceEndpointHome { 53 54 57 protected static Logger logger = Log.getLogger(Log.JONAS_WS_EJBPROVIDER_PREFIX); 58 protected static Logger lognaming = Log.getLogger(Log.JONAS_NAMING_PREFIX); 59 60 protected SessionStatelessDesc dd; 61 62 protected JFactory bf; 63 64 protected static Map sehomeList = new HashMap (); 66 67 72 public JServiceEndpointHome(SessionStatelessDesc dd, JStatelessFactory bf) { 73 if (logger.isLoggable(BasicLevel.DEBUG)) { 74 logger.log(BasicLevel.DEBUG, ""); 75 } 76 this.dd = dd; 77 this.bf = bf; 78 } 79 80 84 protected void register() throws NamingException { 85 if (logger.isLoggable(BasicLevel.DEBUG)) { 86 logger.log(BasicLevel.DEBUG, ""); 87 } 88 String name = dd.getJndiServiceEndpointName(); 89 90 sehomeList.put(name, this); 92 93 Reference ref = new Reference ("org.objectweb.jonas_ejb.container.JServiceEndpointHome", 94 "org.objectweb.jonas_ejb.container.HomeFactory", null); 95 ref.add(new StringRefAddr ("bean.name", name)); 96 bf.getInitialContext().rebind(name, ref); 97 } 98 99 102 protected void unregister() throws NamingException { 103 if (logger.isLoggable(BasicLevel.DEBUG)) { 104 logger.log(BasicLevel.DEBUG, ""); 105 } 106 String name = dd.getJndiServiceEndpointName(); 107 bf.getInitialContext().unbind(name); 109 sehomeList.remove(name); 111 } 112 113 119 public static JServiceEndpointHome getSEHome(String beanName) { 120 if (logger.isLoggable(BasicLevel.DEBUG)) { 121 logger.log(BasicLevel.DEBUG, ""); 122 } 123 JServiceEndpointHome seh = (JServiceEndpointHome) sehomeList.get(beanName); 124 return seh; 125 } 126 127 130 public JServiceEndpoint create() throws RemoteException { 131 if (TraceEjb.isDebugIc()) { 132 TraceEjb.interp.log(BasicLevel.DEBUG, ""); 133 } 134 RequestCtx rctx = bf.preInvoke(MethodDesc.TX_NOT_SET); 135 bf.checkSecurity(null); 136 JStatelessSwitch bs = null; 137 try { 138 bs = (JStatelessSwitch) ((JStatelessFactory) bf).createEJB(); 139 } catch (javax.ejb.AccessLocalException e) { 140 throw new EJBException ("Security Exception thrown by an enterprise Bean", e); 141 } catch (EJBException e) { 142 rctx.sysExc = e; 143 throw e; 144 } catch (RuntimeException e) { 145 rctx.sysExc = e; 146 throw new EJBException ("RuntimeException thrown by an enterprise Bean", e); 147 } catch (Error e) { 148 rctx.sysExc = e; 149 throw new EJBException ("Error thrown by an enterprise Bean" + e); 150 } catch (RemoteException e) { 151 rctx.sysExc = e; 152 throw new EJBException ("Remote Exception raised:", e); 153 } finally { 154 bf.postInvoke(rctx); 155 } 156 return bs.getServiceEndpoint(); 157 } 158 159 163 public Context setCompCtx() { 164 if (lognaming.isLoggable(BasicLevel.DEBUG)) { 165 lognaming.log(BasicLevel.DEBUG, ""); 166 } 167 return bf.setComponentContext(); 168 } 169 170 174 public void resetCompCtx(Context ctx) { 175 if (lognaming.isLoggable(BasicLevel.DEBUG)) { 176 lognaming.log(BasicLevel.DEBUG, "reset ctx:" + ctx); 177 } 178 bf.resetComponentContext(ctx); 179 } 180 181 184 public void checkSecurity(MessageContext msgContext) { 185 186 EJBInvocation ejb = new EJBInvocation(); 187 String qname = null; 188 QName q = null; 189 try { 190 SOAPEnvelope env = msgContext.getMessage().getSOAPPart().getEnvelope(); 191 SOAPBody body = env.getBody(); 192 Iterator it = body.getChildElements(); 193 SOAPElement operation = (SOAPElement ) it.next(); 194 qname = operation.getElementName().toString(); 195 196 q = new QName (qname); 197 ejb.methodPermissionSignature = BeanNaming.getSignature(bf.getEJBName(), msgContext.getOperationByQName(q).getMethod()); 198 } catch (AxisFault e ) { 199 if (lognaming.isLoggable(BasicLevel.WARN)) 202 lognaming.log(BasicLevel.WARN, "can't retreive the operation from message...can not check the security"); 203 return; 204 } catch (SOAPException e) { 205 if (lognaming.isLoggable(BasicLevel.WARN)) 208 lognaming.log(BasicLevel.WARN, "can't retreive the operation from message...can not check the security"); 209 return; 210 } 211 212 bf.checkSecurity(ejb); 213 } 214 217 public abstract JServiceEndpoint createServiceEndpointObject() throws RemoteException ; 218 219 220 } 221 222 | Popular Tags |