JOnASEJBProvider.java

00001 
00025 package org.objectweb.jonas.ws.axis;
00026 
00027 import java.lang.reflect.Method;
00028 
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.i18n.Messages;
00036 import org.apache.axis.providers.java.RPCProvider;
00037 
00038 import org.objectweb.jonas_ejb.container.JServiceEndpoint;
00039 import org.objectweb.jonas_ejb.container.JServiceEndpointHome;
00040 
00041 import org.objectweb.jonas.common.Log;
00042 import org.objectweb.jonas.security.ws.SecurityContextHelper;
00043 
00044 import org.objectweb.util.monolog.api.BasicLevel;
00045 import org.objectweb.util.monolog.api.Logger;
00046 
00052 public class JOnASEJBProvider extends RPCProvider {
00053 
00057     private static Logger logger = null;
00058 
00062     public static final String OPTION_SEINTERFACENAME = "serviceEndpointInterfaceName";
00063 
00067     public static final String OPTION_SEJNDINAME = "serviceEndpointJndiName";
00068 
00072     private static InitialContext cachedContext;
00073 
00077     public JOnASEJBProvider() {
00078         super();
00079         logger = Log.getLogger(Log.JONAS_WS_EJBPROVIDER_PREFIX);
00080         logger.log(BasicLevel.DEBUG, "");
00081     }
00082 
00091     protected Object makeNewServiceObject(MessageContext msgContext, String seiName) throws Exception {
00092         logger.log(BasicLevel.DEBUG, seiName);
00093         if (seiName == null) {
00094             logger.log(BasicLevel.ERROR, "Service Endpoint Interface classname is null");
00095             // cannot find service-endpoint
00096             throw new AxisFault(Messages.getMessage("noOption00", OPTION_SEINTERFACENAME, msgContext.getService()
00097                     .getName()));
00098         }
00099 
00100         // Get ServiceEndpointHome in JNDI
00101         String jndiName = getStrOption(OPTION_SEJNDINAME, msgContext.getService());
00102         if (jndiName == null) {
00103             logger.log(BasicLevel.ERROR, "Service Endpoint JNDI name is null");
00104             throw new AxisFault("Missing parameter in service : " + OPTION_SEJNDINAME);
00105         }
00106         JServiceEndpointHome sehome = null;
00107         try {
00108             InitialContext ic = getCachedContext();
00109             sehome = (JServiceEndpointHome) ic.lookup(jndiName);
00110         } catch (NamingException ne) {
00111             logger.log(BasicLevel.ERROR, "Cannot lookup ServiceEndpointHome");
00112             throw new AxisFault("Cannot lookup ServiceEndpointHome: " + jndiName);
00113         }
00114         // Check that the object implements the SEI
00115         // TODO
00116 
00117         // Create a new ServiceEndpoint object
00118         JServiceEndpoint se = sehome.create();
00119 
00120         // Set the MessageContext that can be retrived by the bean
00121         se.setMessageContext(msgContext);
00122         return se;
00123     }
00124 
00129     protected Object invokeMethod(MessageContext msgContext, Method method, Object obj, Object[] argValues)
00130             throws Exception {
00131         logger.log(BasicLevel.DEBUG, "");
00132         String username = msgContext.getUsername();
00133         if (username != null) {
00134             // Do not forget to initialize the security context
00135             SecurityContextHelper.getInstance().login(username, msgContext.getPassword());
00136         }
00137         return super.invokeMethod(msgContext, method, obj, argValues);
00138     }
00139 
00145     protected String getServiceClassNameOptionName() {
00146         logger.log(BasicLevel.DEBUG, "");
00147         return OPTION_SEINTERFACENAME;
00148     }
00149 
00161     private String getStrOption(String optionName, Handler service) {
00162         String value = null;
00163         if (service != null) {
00164             value = (String) service.getOption(optionName);
00165         }
00166         if (value == null) {
00167             value = (String) getOption(optionName);
00168         }
00169         return value;
00170     }
00171 
00176     private InitialContext getCachedContext() throws javax.naming.NamingException {
00177         if (cachedContext == null) {
00178             cachedContext = new InitialContext();
00179         }
00180         return cachedContext;
00181     }
00182 
00183 }

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