1 25 package org.objectweb.jonas.ws.axis; 26 27 28 import javax.naming.Context ; 29 import javax.naming.InitialContext ; 30 import javax.naming.NamingException ; 31 32 import org.apache.axis.AxisFault; 33 import org.apache.axis.Handler; 34 import org.apache.axis.MessageContext; 35 import org.apache.axis.handlers.BasicHandler; 36 37 import org.objectweb.jonas_ejb.container.JServiceEndpointHome; 38 39 import org.objectweb.jonas.common.Log; 40 import org.objectweb.jonas.security.ws.SecurityContextHelper; 41 42 import org.objectweb.util.monolog.api.BasicLevel; 43 import org.objectweb.util.monolog.api.Logger; 44 45 46 52 public class JonasHandler extends BasicHandler { 53 54 57 private static Logger logger = Log.getLogger(Log.JONAS_WS_EJBPROVIDER_PREFIX); 58 59 62 private static InitialContext cachedContext; 63 64 67 private Context savedCtx = null; 68 69 72 private JServiceEndpointHome sehome = null; 73 74 78 public void onFault(MessageContext msgContext) { 79 logger.log(BasicLevel.DEBUG, "*------* Fault"); 80 if (sehome != null) { 81 logger.log(BasicLevel.DEBUG, "*--* Fault"); 82 sehome.resetCompCtx(savedCtx); 83 if (savedCtx != null) { 84 logger.log(BasicLevel.ERROR, "Setting a non null context:" + savedCtx); 85 } 86 sehome = null; 87 } 88 } 89 90 95 public void invoke(MessageContext msgContext) throws AxisFault { 96 97 if (msgContext.getPastPivot()) { 98 logger.log(BasicLevel.DEBUG, "*------* Response"); 99 if (sehome != null) { 101 logger.log(BasicLevel.DEBUG, "*--* Response"); 102 sehome.resetCompCtx(savedCtx); 103 if (savedCtx != null) { 104 logger.log(BasicLevel.ERROR, "Setting a non null context:" + savedCtx); 105 } 106 sehome = null; 107 } 108 } else { 109 logger.log(BasicLevel.DEBUG, "*------* Request"); 111 112 Handler service = msgContext.getService(); 114 String clsName = (String ) service.getOption(JOnASEJBProvider.OPTION_SEINTERFACENAME); 115 if (clsName == null) { 116 return; 118 } 119 logger.log(BasicLevel.DEBUG, "*--* Request"); 120 121 String jndiName = (String ) service.getOption(JOnASEJBProvider.OPTION_SEJNDINAME); 123 if (jndiName == null) { 124 logger.log(BasicLevel.ERROR, "Service Endpoint JNDI name is null"); 125 throw new AxisFault("Missing parameter OPTION_SEJNDINAME in service"); 126 } 127 try { 128 InitialContext ic = getCachedContext(); 129 sehome = (JServiceEndpointHome) ic.lookup(jndiName); 130 } catch (NamingException ne) { 131 logger.log(BasicLevel.ERROR, "Cannot lookup ServiceEndpointHome"); 132 throw new AxisFault("Cannot lookup ServiceEndpointHome: " + jndiName); 133 } 134 135 String username = msgContext.getUsername(); 137 if (username != null) { 138 SecurityContextHelper.getInstance().login(username, msgContext.getPassword()); 140 sehome.checkSecurity(msgContext); 143 } 144 145 savedCtx = sehome.setCompCtx(); 147 if (savedCtx != null) { 148 logger.log(BasicLevel.ERROR, "Saving a non null context:" + savedCtx); 149 } 150 151 } 152 } 153 154 158 private InitialContext getCachedContext() throws javax.naming.NamingException { 159 if (cachedContext == null) { 160 cachedContext = new InitialContext (); 161 } 162 return cachedContext; 163 } 164 } 165 | Popular Tags |