Save This Page
Home » jboss-5.0.0.CR1-src » org » jboss » web » [javadoc | source]
org.jboss.web
abstract public class: AbstractWebContainer [javadoc | source]
java.lang.Object
   org.jboss.mx.util.JBossNotificationBroadcasterSupport
      org.jboss.system.ServiceMBeanSupport
         org.jboss.deployment.SubDeployerSupport
            org.jboss.web.AbstractWebContainer

All Implemented Interfaces:
    AbstractWebContainerMBean, SubDeployerExtMBean, SubDeployerExt, org.jboss.kernel.spi.dependency.KernelControllerContextAware, ServiceMBean, MBeanRegistration, NotificationEmitter

Direct Known Subclasses:
    JettyService, EmbeddedCatalinaService41, EmbeddedCatalinaServiceSX, EmbeddedTomcatService, Tomcat5

A template pattern class for web container integration into JBoss. This class should be subclasses by web container providers wishing to integrate their container into a JBoss server. It provides support for mapping the following web-app.xml/jboss-web.xml elements into the JBoss server JNDI namespace: - env-entry - resource-ref - resource-env-ref - ejb-ref - ejb-local-ref - security-domain Subclasses need to implement the performDeploy() and performUndeploy() methods to perform the container specific steps and return the web application info required by the AbstractWebContainer class. Integration with the JBossSX security framework is based on the establishment of a java:comp/env/security context as described in the Context) linkSecurityDomain comments. The security context provides access to the JBossSX security mgr interface implementations for use by subclass request interceptors. A outline of the steps for authenticating a user is: // Get the username & password from the request context... String username = f(request); String password = f(request); // Get the JBoss security manager from the ENC context InitialContext iniCtx = new InitialContext(); SecurityManager securityMgr = (SecurityManager) iniCtx.lookup("java:comp/env/security/securityMgr"); SimplePrincipal principal = new SimplePrincipal(username); if( securityMgr.isValid(principal, password) ) { // Indicate the user is allowed access to the web content... // Propagate the user info to JBoss for any calls into made by the servlet SecurityAssociation.setPrincipal(principal); SecurityAssociation.setCredential(password.toCharArray()); } else { // Deny access... } An outline of the steps for authorizing the user is: // Get the username & required roles from the request context... String username = f(request); String[] roles = f(request); // Get the JBoss security manager from the ENC context InitialContext iniCtx = new InitialContext(); RealmMapping securityMgr = (RealmMapping) iniCtx.lookup("java:comp/env/security/realmMapping"); SimplePrincipal principal = new SimplePrincipal(username); Set requiredRoles = new HashSet(Arrays.asList(roles)); if( securityMgr.doesUserHaveRole(principal, requiredRoles) ) { // Indicate the user has the required roles for the web content... } else { // Deny access... } The one thing to be aware of is the relationship between the thread context class loader and the JNDI ENC context. Any method that attempts to access the JNDI ENC context must have the ClassLoader in the WebApplication returned from the performDeploy as its thread context ClassLoader or else the lookup for java:comp/env will fail with a name not found exception, or worse, it will receive some other web application ENC context. If your adapting a web container that is trying be compatible with both 1.1 and 1.2 Java VMs this is something you need to pay special attention to. For example, I have seen problems a request interceptor that was handling the authentication/authorization callouts in tomcat3.2.1 not having the same thread context ClassLoader as was used to dispatch the http service request. For a complete example see the EmbeddedCatalinaServiceSX in the catalina module.
Nested Class Summary:
public static interface  AbstractWebContainer.WebDescriptorParser   
Field Summary
protected  HashMap deploymentMap    A mapping of deployed warUrl strings to the WebApplication object 
protected  boolean java2ClassLoadingCompliance    The parent class loader first model flag 
protected  boolean unpackWars    A flag indicating if war archives should be unpacked 
protected  boolean lenientEjbLink    If true, ejb-links that don't resolve don't cause an error (fallback to jndi-name) 
Fields inherited from org.jboss.deployment.SubDeployerSupport:
nativeSuffix,  nativePrefix,  mainDeployer,  tempDeployDir,  enhancedSuffixes,  suffixes,  relativeOrder,  CONFIGURATION
Fields inherited from org.jboss.system.ServiceMBeanSupport:
SERVICE_CONTROLLER_SIG,  log,  server,  serviceName
Constructor:
 public AbstractWebContainer() 
Method from org.jboss.web.AbstractWebContainer Summary:
accepts,   addEnvEntries,   getClassLoaderURLs,   getCompileClasspath,   getConfig,   getDeployedApp,   getDeployedApplications,   getJava2ClassLoadingCompliance,   getLenientEjbLink,   getStandardCompileClasspath,   getUnpackWars,   init,   isDeployed,   linkEjbLocalRefs,   linkEjbRefs,   linkResourceEnvRefs,   linkResourceRefs,   linkSecurityDomain,   parseMetaData,   parseWebAppDescriptors,   performDeploy,   performUndeploy,   processNestedDeployments,   setConfig,   setJava2ClassLoadingCompliance,   setLenientEjbLink,   setUnpackWars,   start,   stop
Methods from org.jboss.deployment.SubDeployerSupport:
accepts,   addDeployableFiles,   addDeployableJar,   create,   createService,   deployUrl,   destroy,   destroyService,   emitNotification,   getEnhancedSuffixes,   getRelativeOrder,   getSuffixes,   init,   isDeployable,   processNestedDeployments,   setEnhancedSuffixes,   setRelativeOrder,   setSuffixes,   start,   startService,   stop,   stopService
Methods from org.jboss.system.ServiceMBeanSupport:
create,   createService,   destroy,   destroyService,   getDeploymentInfo,   getLog,   getName,   getNextNotificationSequenceNumber,   getObjectName,   getServer,   getServiceName,   getState,   getStateString,   jbossInternalCreate,   jbossInternalDescription,   jbossInternalDestroy,   jbossInternalLifecycle,   jbossInternalStart,   jbossInternalStop,   pojoChange,   pojoCreate,   pojoDestroy,   pojoStart,   pojoStop,   postDeregister,   postRegister,   preDeregister,   preRegister,   setKernelControllerContext,   start,   startService,   stop,   stopService,   unsetKernelControllerContext
Methods from org.jboss.mx.util.JBossNotificationBroadcasterSupport:
addNotificationListener,   getNotificationInfo,   handleNotification,   nextNotificationSequenceNumber,   removeNotificationListener,   removeNotificationListener,   sendNotification
Methods from java.lang.Object:
equals,   getClass,   hashCode,   notify,   notifyAll,   toString,   wait,   wait,   wait
Method from org.jboss.web.AbstractWebContainer Detail:
 public boolean accepts(DeploymentInfo sdi) 
 protected  void addEnvEntries(Iterator envEntries,
    Context envCtx) throws NamingException, ClassNotFoundException 
 protected URL[] getClassLoaderURLs(ClassLoader cl) 
    Use reflection to access a URL[] getURLs method so that non-URLClassLoader class loaders that support this method can provide info.
 public String[] getCompileClasspath(ClassLoader loader) 
    A utility method that walks up the ClassLoader chain starting at the given loader and queries each ClassLoader for a 'URL[] getURLs()' method from which a complete classpath of URL strings is built.
 public Element getConfig() 
    An accessor for any configuration element set via setConfig. This method always returns null and must be overriden by subclasses to return a valid value.
 public WebApplication getDeployedApp(String warUrl) 
    Get the WebApplication object for a deployed war.
 public Iterator getDeployedApplications() 
    Returns the applications deployed by the web container subclasses.
 public boolean getJava2ClassLoadingCompliance() 
    Get the flag indicating if the normal Java2 parent first class loading model should be used over the servlet 2.3 web container first model.
 public boolean getLenientEjbLink() 
    Get the flag indicating if ejb-link errors should be ignored in favour of trying the jndi-name in jboss-web.xml
 public String[] getStandardCompileClasspath(ClassLoader loader) 
    A utility method that searches the given loader for the resources: "javax/servlet/resources/web-app_2_3.dtd", "org/apache/jasper/resources/jsp12.dtd", and "javax/ejb/EJBHome.class" and returns an array of URL strings. Any jar: urls are reduced to the underlying portion of the 'jar:!/{entry}' construct.
 public boolean getUnpackWars() 
    Set the flag indicating if war archives should be unpacked. This may need to be set to false as long extraction paths under deploy can show up as deployment failures on some platforms.
 public synchronized  void init(DeploymentInfo di) throws DeploymentException 
 public boolean isDeployed(String warUrl) 
    See if a war is deployed.
 protected  void linkEjbLocalRefs(Iterator ejbRefs,
    Context envCtx,
    DeploymentInfo di) throws NamingException 
 protected  void linkEjbRefs(Iterator ejbRefs,
    Context envCtx,
    DeploymentInfo di) throws NamingException 
 protected  void linkResourceEnvRefs(Iterator resourceEnvRefs,
    Context envCtx) throws NamingException 
 protected  void linkResourceRefs(Iterator resourceRefs,
    Context envCtx) throws NamingException 
 protected  void linkSecurityDomain(String securityDomain,
    Context envCtx) throws NamingException 
    This creates a java:comp/env/security context that contains a securityMgr binding pointing to an AuthenticationManager implementation and a realmMapping binding pointing to a RealmMapping implementation. If the jboss-web.xml descriptor contained a security-domain element then the bindings are LinkRefs to the jndi name specified by the security-domain element. If there was no security-domain element then the bindings are to NullSecurityManager instance which simply allows all access.
 protected  void parseMetaData(String ctxPath,
    URL warURL,
    String warName,
    WebMetaData metaData) throws DeploymentException 
    This method creates a context-root string from either the WEB-INF/jboss-web.xml context-root element is one exists, or the filename portion of the warURL. It is called if the DeploymentInfo webContext value is null which indicates a standalone war deployment. A war name of ROOT.war is handled as a special case of a war that should be installed as the default web context.
 protected  void parseWebAppDescriptors(DeploymentInfo di,
    ClassLoader loader,
    WebMetaData metaData) throws Exception 
    This method is invoked from within subclass performDeploy() method implementations when they invoke WebDescriptorParser.parseWebAppDescriptors().
 abstract protected  void performDeploy(WebApplication webApp,
    String warUrl,
    AbstractWebContainer.WebDescriptorParser webAppParser) throws Exception
    This method is called by the deploy() method template and must be overriden by subclasses to perform the web container specific deployment steps.
 abstract protected  void performUndeploy(String warUrl) throws Exception
    Called as part of the undeploy() method template to ask the subclass for perform the web container specific undeployment steps.
 protected  void processNestedDeployments(DeploymentInfo di) 
    WARs do not have nested deployments
 public  void setConfig(Element config) 
    This method is invoked to import an arbitrary XML configuration tree. Subclasses should override this method if they support such a configuration capability. This implementation does nothing.
 public  void setJava2ClassLoadingCompliance(boolean flag) 
    Set the flag indicating if the normal Java2 parent first class loading model should be used over the servlet 2.3 web container first model.
 public  void setLenientEjbLink(boolean flag) 
    Set the flag indicating if ejb-link errors should be ignored in favour of trying the jndi-name in jboss-web.xml
 public  void setUnpackWars(boolean flag) 
    Get the flag indicating if war archives should be unpacked. This may need to be set to false as long extraction paths under deploy can show up as deployment failures on some platforms.
 public synchronized  void start(DeploymentInfo di) throws DeploymentException 
    A template pattern implementation of the deploy() method. This method calls the performDeploy() method to perform the container specific deployment steps and registers the returned WebApplication in the deployment map. The steps performed are: ClassLoader appClassLoader = thread.getContextClassLoader(); URLClassLoader warLoader = URLClassLoader.newInstance(empty, appClassLoader); thread.setContextClassLoader(warLoader); WebDescriptorParser webAppParser = ...; WebMetaData metaData = di.metaData; parseMetaData(ctxPath, warUrl, metaData); WebApplication warInfo = new WebApplication(metaData); performDeploy(warInfo, warUrl, webAppParser); deploymentMap.put(warUrl, warInfo); thread.setContextClassLoader(appClassLoader); The subclass performDeploy() implementation needs to invoke webAppParser.parseWebAppDescriptors(loader, warInfo) to have the JNDI java:comp/env namespace setup before any web app component can access this namespace. Also, an MBean for each servlet deployed should be created and its JMX ObjectName placed into the DeploymentInfo.mbeans list so that the JSR77 layer can create the approriate model view. The servlet MBean needs to provide access to the min, max and total time in milliseconds. Expose this information via MinServiceTime, MaxServiceTime and TotalServiceTime attributes to integrate seemlessly with the JSR77 factory layer.
 public synchronized  void stop(DeploymentInfo di) throws DeploymentException 
    A template pattern implementation of the undeploy() method. This method calls the performUndeploy() method to perform the container specific undeployment steps and unregisters the the warUrl from the deployment map.