JonasHandler.java

00001 
00025 package org.objectweb.jonas.ws.axis;
00026 
00027 
00028 import javax.naming.Context;
00029 import javax.naming.InitialContext;
00030 import javax.naming.NamingException;
00031 
00032 import org.apache.axis.AxisFault;
00033 import org.apache.axis.Handler;
00034 import org.apache.axis.MessageContext;
00035 import org.apache.axis.handlers.BasicHandler;
00036 
00037 import org.objectweb.jonas_ejb.container.JServiceEndpointHome;
00038 
00039 import org.objectweb.jonas.common.Log;
00040 import org.objectweb.jonas.security.ws.SecurityContextHelper;
00041 
00042 import org.objectweb.util.monolog.api.BasicLevel;
00043 import org.objectweb.util.monolog.api.Logger;
00044 
00045 
00052 public class JonasHandler extends BasicHandler {
00053 
00057     private static Logger logger = Log.getLogger(Log.JONAS_WS_EJBPROVIDER_PREFIX);
00058 
00062     private static InitialContext cachedContext;
00063 
00067     private Context savedCtx = null;
00068 
00072     private JServiceEndpointHome sehome = null;
00073 
00078     public void onFault(MessageContext msgContext) {
00079         logger.log(BasicLevel.DEBUG, "*------* Fault");
00080         if (sehome != null) {
00081             logger.log(BasicLevel.DEBUG, "*--* Fault");
00082             sehome.resetCompCtx(savedCtx);
00083             if (savedCtx != null) {
00084                 logger.log(BasicLevel.ERROR, "Setting a non null context:" + savedCtx);
00085             }
00086             sehome = null;
00087         }
00088     }
00089 
00095     public void invoke(MessageContext msgContext) throws AxisFault {
00096 
00097         if (msgContext.getPastPivot()) {
00098             logger.log(BasicLevel.DEBUG, "*------* Response");
00099             // Response
00100             if (sehome != null) {
00101                 logger.log(BasicLevel.DEBUG, "*--* Response");
00102                 sehome.resetCompCtx(savedCtx);
00103                 if (savedCtx != null) {
00104                     logger.log(BasicLevel.ERROR, "Setting a non null context:" + savedCtx);
00105                 }
00106                 sehome = null;
00107             }
00108         } else {
00109             // Request
00110             logger.log(BasicLevel.DEBUG, "*------* Request");
00111 
00112             // Get the service class name
00113             Handler service = msgContext.getService();
00114             String clsName = (String) service.getOption(JOnASEJBProvider.OPTION_SEINTERFACENAME);
00115             if (clsName == null) {
00116                 // We are not in the case of jonas ejb call: do nothing.
00117                 return;
00118             }
00119             logger.log(BasicLevel.DEBUG, "*--* Request");
00120 
00121             // Get ServiceEndpointHome in JNDI
00122             String jndiName = (String) service.getOption(JOnASEJBProvider.OPTION_SEJNDINAME);
00123             if (jndiName == null) {
00124                 logger.log(BasicLevel.ERROR, "Service Endpoint JNDI name is null");
00125                 throw new AxisFault("Missing parameter OPTION_SEJNDINAME in service");
00126             }
00127             try {
00128                 InitialContext ic = getCachedContext();
00129                 sehome = (JServiceEndpointHome) ic.lookup(jndiName);
00130             } catch (NamingException ne) {
00131                 logger.log(BasicLevel.ERROR, "Cannot lookup ServiceEndpointHome");
00132                 throw new AxisFault("Cannot lookup ServiceEndpointHome: " + jndiName);
00133             }
00134             
00135             // add the security context
00136             String username = msgContext.getUsername();
00137             if (username != null) {
00138                 // Do not forget to initialize the security context
00139                 SecurityContextHelper.getInstance().login(username, msgContext.getPassword());
00140                 // Check the security and throw exception if user is not authorized
00141                 // to access the EJB before lauching handlers
00142                 sehome.checkSecurity(msgContext);
00143             }
00144             
00145             // Switch Context on the context of the target bean (java:comp/env)
00146             savedCtx = sehome.setCompCtx();
00147             if (savedCtx != null) {
00148                 logger.log(BasicLevel.ERROR, "Saving a non null context:" + savedCtx);
00149             }
00150 
00151         }
00152     }
00153 
00158     private InitialContext getCachedContext() throws javax.naming.NamingException {
00159         if (cachedContext == null) {
00160             cachedContext = new InitialContext();
00161         }
00162         return cachedContext;
00163     }
00164 }

Generated on Tue Feb 15 15:05:35 2005 for JOnAS by  doxygen 1.3.9.1