Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

org.jboss.web
Class AbstractWebContainer  view AbstractWebContainer download AbstractWebContainer.java

java.lang.Object
  extended byjavax.management.NotificationBroadcasterSupport
      extended byorg.jboss.system.ServiceMBeanSupport
          extended byorg.jboss.deployment.SubDeployerSupport
              extended byorg.jboss.web.AbstractWebContainer
All Implemented Interfaces:
javax.management.MBeanRegistration, javax.management.NotificationBroadcaster, org.jboss.system.Service, org.jboss.system.ServiceMBean, org.jboss.deployment.SubDeployer

public abstract class AbstractWebContainer
extends org.jboss.deployment.SubDeployerSupport

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() 55 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 linkSecurityDomain 55 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.

Version:
$Revision: 1.51.2.25 $

Nested Class Summary
private  class AbstractWebContainer.DescriptorParser
          An inner class that maps the WebDescriptorParser.parseWebAppDescriptors() onto the protected parseWebAppDescriptors() AbstractWebContainer method.
static interface AbstractWebContainer.WebDescriptorParser
           
 
Nested classes inherited from class org.jboss.deployment.SubDeployerSupport
org.jboss.deployment.SubDeployerSupport.ClassConfiguration
 
Field Summary
protected  java.util.HashMap deploymentMap
          A mapping of deployed warUrl strings to the WebApplication object
protected  boolean java2ClassLoadingCompliance
          The parent class loader first model flag
protected  boolean lenientEjbLink
          If true, ejb-links that don't resolve don't cause an error (fallback to jndi-name)
protected  boolean unpackWars
          A flag indicating if war archives should be unpacked
 
Fields inherited from class org.jboss.deployment.SubDeployerSupport
CONFIGURATION, mainDeployer, nativePrefix, nativeSuffix, tempDeployDir
 
Fields inherited from class org.jboss.system.ServiceMBeanSupport
log, server, serviceName
 
Fields inherited from class javax.management.NotificationBroadcasterSupport
 
Fields inherited from interface org.jboss.deployment.SubDeployer
CREATE_NOTIFICATION, DESTROY_NOTIFICATION, INIT_NOTIFICATION, START_NOTIFICATION, STOP_NOTIFICATION
 
Fields inherited from interface org.jboss.system.ServiceMBean
CREATE_EVENT, CREATED, DESTROY_EVENT, DESTROYED, FAILED, REGISTERED, STARTED, STARTING, states, STOPPED, STOPPING, UNREGISTERED
 
Constructor Summary
AbstractWebContainer()
           
 
Method Summary
 boolean accepts(org.jboss.deployment.DeploymentInfo sdi)
          The accepts method is called by MainDeployer to determine which deployer is suitable for a DeploymentInfo.
protected  void addEnvEntries(java.util.Iterator envEntries, javax.naming.Context envCtx)
           
private  void addURLs(java.util.Set urlSet, java.net.URL[] urls)
           
protected  java.net.URL[] getClassLoaderURLs(java.lang.ClassLoader cl)
          Use reflection to access a URL[] getURLs method so that non-URLClassLoader class loaders that support this method can provide info.
 java.lang.String[] getCompileClasspath(java.lang.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.
 org.w3c.dom.Element getConfig()
          An accessor for any configuration element set via setConfig.
 WebApplication getDeployedApp(java.lang.String warUrl)
          Get the WebApplication object for a deployed war.
 java.util.Iterator getDeployedApplications()
          Returns the applications deployed by the web container subclasses.
 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.
 boolean getLenientEjbLink()
          Get the flag indicating if ejb-link errors should be ignored in favour of trying the jndi-name in jboss-web.xml
 java.lang.String[] getStandardCompileClasspath(java.lang.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.
 boolean getUnpackWars()
          Set the flag indicating if war archives should be unpacked.
 void init(org.jboss.deployment.DeploymentInfo di)
          Sub-classes should override this method to provide custom 'init' logic.
 boolean isDeployed(java.lang.String warUrl)
          See if a war is deployed.
protected  void linkEjbLocalRefs(java.util.Iterator ejbRefs, javax.naming.Context envCtx, org.jboss.deployment.DeploymentInfo di)
           
protected  void linkEjbRefs(java.util.Iterator ejbRefs, javax.naming.Context envCtx, org.jboss.deployment.DeploymentInfo di)
           
protected  void linkResourceEnvRefs(java.util.Iterator resourceEnvRefs, javax.naming.Context envCtx)
           
protected  void linkResourceRefs(java.util.Iterator resourceRefs, javax.naming.Context envCtx)
           
protected  void linkSecurityDomain(java.lang.String securityDomain, javax.naming.Context envCtx)
          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.
protected  void parseMetaData(java.lang.String ctxPath, java.net.URL warURL, java.lang.String warName, org.jboss.metadata.WebMetaData metaData)
          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.
protected  void parseWebAppDescriptors(org.jboss.deployment.DeploymentInfo di, java.lang.ClassLoader loader, org.jboss.metadata.WebMetaData metaData)
          This method is invoked from within subclass performDeploy() method implementations when they invoke WebDescriptorParser.parseWebAppDescriptors().
protected abstract  void performDeploy(WebApplication webApp, java.lang.String warUrl, AbstractWebContainer.WebDescriptorParser webAppParser)
          This method is called by the deploy() method template and must be overriden by subclasses to perform the web container specific deployment steps.
protected abstract  void performUndeploy(java.lang.String warUrl)
          Called as part of the undeploy() method template to ask the subclass for perform the web container specific undeployment steps.
protected  void processNestedDeployments(org.jboss.deployment.DeploymentInfo di)
          WARs do not have nested deployments
 void setConfig(org.w3c.dom.Element config)
          This method is invoked to import an arbitrary XML configuration tree.
 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.
 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
 void setUnpackWars(boolean flag)
          Get the flag indicating if war archives should be unpacked.
 void start(org.jboss.deployment.DeploymentInfo di)
          A template pattern implementation of the deploy() method.
 void stop(org.jboss.deployment.DeploymentInfo di)
          A template pattern implementation of the undeploy() method.
 
Methods inherited from class org.jboss.deployment.SubDeployerSupport
addDeployableFiles, addDeployableJar, create, createService, deployUrl, destroy, destroyService, isDeployable, startService, stopService
 
Methods inherited from class org.jboss.system.ServiceMBeanSupport
create, destroy, getLog, getName, getNextNotificationSequenceNumber, getObjectName, getServer, getServiceName, getState, getStateString, postDeregister, postRegister, preDeregister, preRegister, start, stop
 
Methods inherited from class javax.management.NotificationBroadcasterSupport
addNotificationListener, getListenerMap, getNotificationInfo, removeNotificationListener, sendNotification
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.jboss.deployment.SubDeployer
getServiceName
 

Field Detail

deploymentMap

protected java.util.HashMap deploymentMap
A mapping of deployed warUrl strings to the WebApplication object


java2ClassLoadingCompliance

protected boolean java2ClassLoadingCompliance
The parent class loader first model flag


unpackWars

protected boolean unpackWars
A flag indicating if war archives should be unpacked


lenientEjbLink

protected boolean lenientEjbLink
If true, ejb-links that don't resolve don't cause an error (fallback to jndi-name)

Constructor Detail

AbstractWebContainer

public AbstractWebContainer()
Method Detail

getJava2ClassLoadingCompliance

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.


setJava2ClassLoadingCompliance

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.


getUnpackWars

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.


setUnpackWars

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.


getLenientEjbLink

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


setLenientEjbLink

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


accepts

public boolean accepts(org.jboss.deployment.DeploymentInfo sdi)
Description copied from interface: org.jboss.deployment.SubDeployer
The accepts method is called by MainDeployer to determine which deployer is suitable for a DeploymentInfo.


init

public void init(org.jboss.deployment.DeploymentInfo di)
          throws org.jboss.deployment.DeploymentException
Description copied from class: org.jboss.deployment.SubDeployerSupport
Sub-classes should override this method to provide custom 'init' logic.

This method calls the processNestedDeployments(di) method and then issues a JMX notification of type SubDeployer.INIT_NOTIFICATION. This behaviour can overridden by concrete sub-classes. If further initialization needs to be done, and you wish to preserve the functionality, be sure to call super.init(di) at the end of your implementation.


processNestedDeployments

protected void processNestedDeployments(org.jboss.deployment.DeploymentInfo di)
WARs do not have nested deployments


start

public void start(org.jboss.deployment.DeploymentInfo di)
           throws org.jboss.deployment.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.


performDeploy

protected abstract void performDeploy(WebApplication webApp,
                                      java.lang.String warUrl,
                                      AbstractWebContainer.WebDescriptorParser webAppParser)
                               throws java.lang.Exception
This method is called by the deploy() method template and must be overriden by subclasses to perform the web container specific deployment steps.


stop

public void stop(org.jboss.deployment.DeploymentInfo di)
          throws org.jboss.deployment.DeploymentException
A template pattern implementation of the undeploy() method. This method calls the performUndeploy() 55 method to perform the container specific undeployment steps and unregisters the the warUrl from the deployment map.


performUndeploy

protected abstract void performUndeploy(java.lang.String warUrl)
                                 throws java.lang.Exception
Called as part of the undeploy() method template to ask the subclass for perform the web container specific undeployment steps.


isDeployed

public boolean isDeployed(java.lang.String warUrl)
See if a war is deployed.


getDeployedApp

public WebApplication getDeployedApp(java.lang.String warUrl)
Get the WebApplication object for a deployed war.


getDeployedApplications

public java.util.Iterator getDeployedApplications()
Returns the applications deployed by the web container subclasses.


getConfig

public org.w3c.dom.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.


setConfig

public void setConfig(org.w3c.dom.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.


parseWebAppDescriptors

protected void parseWebAppDescriptors(org.jboss.deployment.DeploymentInfo di,
                                      java.lang.ClassLoader loader,
                                      org.jboss.metadata.WebMetaData metaData)
                               throws java.lang.Exception
This method is invoked from within subclass performDeploy() method implementations when they invoke WebDescriptorParser.parseWebAppDescriptors().


addEnvEntries

protected void addEnvEntries(java.util.Iterator envEntries,
                             javax.naming.Context envCtx)
                      throws java.lang.ClassNotFoundException,
                             javax.naming.NamingException

linkResourceEnvRefs

protected void linkResourceEnvRefs(java.util.Iterator resourceEnvRefs,
                                   javax.naming.Context envCtx)
                            throws javax.naming.NamingException

linkResourceRefs

protected void linkResourceRefs(java.util.Iterator resourceRefs,
                                javax.naming.Context envCtx)
                         throws javax.naming.NamingException

linkEjbRefs

protected void linkEjbRefs(java.util.Iterator ejbRefs,
                           javax.naming.Context envCtx,
                           org.jboss.deployment.DeploymentInfo di)
                    throws javax.naming.NamingException

linkEjbLocalRefs

protected void linkEjbLocalRefs(java.util.Iterator ejbRefs,
                                javax.naming.Context envCtx,
                                org.jboss.deployment.DeploymentInfo di)
                         throws javax.naming.NamingException

linkSecurityDomain

protected void linkSecurityDomain(java.lang.String securityDomain,
                                  javax.naming.Context envCtx)
                           throws javax.naming.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.


getStandardCompileClasspath

public java.lang.String[] getStandardCompileClasspath(java.lang.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.


getCompileClasspath

public java.lang.String[] getCompileClasspath(java.lang.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.


addURLs

private void addURLs(java.util.Set urlSet,
                     java.net.URL[] urls)

getClassLoaderURLs

protected java.net.URL[] getClassLoaderURLs(java.lang.ClassLoader cl)
Use reflection to access a URL[] getURLs method so that non-URLClassLoader class loaders that support this method can provide info.


parseMetaData

protected void parseMetaData(java.lang.String ctxPath,
                             java.net.URL warURL,
                             java.lang.String warName,
                             org.jboss.metadata.WebMetaData metaData)
                      throws org.jboss.deployment.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.