1 25 package org.objectweb.jonas.ws.axis; 26 27 import java.lang.reflect.Method ; 28 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.i18n.Messages; 36 import org.apache.axis.providers.java.RPCProvider; 37 38 import org.objectweb.jonas_ejb.container.JServiceEndpoint; 39 import org.objectweb.jonas_ejb.container.JServiceEndpointHome; 40 41 import org.objectweb.jonas.common.Log; 42 import org.objectweb.jonas.security.ws.SecurityContextHelper; 43 44 import org.objectweb.util.monolog.api.BasicLevel; 45 import org.objectweb.util.monolog.api.Logger; 46 47 52 public class JOnASEJBProvider extends RPCProvider { 53 54 57 private static Logger logger = null; 58 59 62 public static final String OPTION_SEINTERFACENAME = "serviceEndpointInterfaceName"; 63 64 67 public static final String OPTION_SEJNDINAME = "serviceEndpointJndiName"; 68 69 72 private static InitialContext cachedContext; 73 74 77 public JOnASEJBProvider() { 78 super(); 79 logger = Log.getLogger(Log.JONAS_WS_EJBPROVIDER_PREFIX); 80 logger.log(BasicLevel.DEBUG, ""); 81 } 82 83 91 protected Object makeNewServiceObject(MessageContext msgContext, String seiName) throws Exception { 92 logger.log(BasicLevel.DEBUG, seiName); 93 if (seiName == null) { 94 logger.log(BasicLevel.ERROR, "Service Endpoint Interface classname is null"); 95 throw new AxisFault(Messages.getMessage("noOption00", OPTION_SEINTERFACENAME, msgContext.getService() 97 .getName())); 98 } 99 100 String jndiName = getStrOption(OPTION_SEJNDINAME, msgContext.getService()); 102 if (jndiName == null) { 103 logger.log(BasicLevel.ERROR, "Service Endpoint JNDI name is null"); 104 throw new AxisFault("Missing parameter in service : " + OPTION_SEJNDINAME); 105 } 106 JServiceEndpointHome sehome = null; 107 try { 108 InitialContext ic = getCachedContext(); 109 sehome = (JServiceEndpointHome) ic.lookup(jndiName); 110 } catch (NamingException ne) { 111 logger.log(BasicLevel.ERROR, "Cannot lookup ServiceEndpointHome"); 112 throw new AxisFault("Cannot lookup ServiceEndpointHome: " + jndiName); 113 } 114 117 JServiceEndpoint se = sehome.create(); 119 120 se.setMessageContext(msgContext); 122 return se; 123 } 124 125 129 protected Object invokeMethod(MessageContext msgContext, Method method, Object obj, Object [] argValues) 130 throws Exception { 131 logger.log(BasicLevel.DEBUG, ""); 132 String username = msgContext.getUsername(); 133 if (username != null) { 134 SecurityContextHelper.getInstance().login(username, msgContext.getPassword()); 136 } 137 return super.invokeMethod(msgContext, method, obj, argValues); 138 } 139 140 145 protected String getServiceClassNameOptionName() { 146 logger.log(BasicLevel.DEBUG, ""); 147 return OPTION_SEINTERFACENAME; 148 } 149 150 161 private String getStrOption(String optionName, Handler service) { 162 String value = null; 163 if (service != null) { 164 value = (String ) service.getOption(optionName); 165 } 166 if (value == null) { 167 value = (String ) getOption(optionName); 168 } 169 return value; 170 } 171 172 176 private InitialContext getCachedContext() throws javax.naming.NamingException { 177 if (cachedContext == null) { 178 cachedContext = new InitialContext (); 179 } 180 return cachedContext; 181 } 182 183 } | Popular Tags |