org.objectweb.jonas.web
Class AbsJWebContainerServiceImpl

java.lang.Object
  extended byjavax.management.NotificationBroadcasterSupport
      extended byorg.objectweb.jonas.management.ReconfigDispatcher
          extended byorg.objectweb.jonas.service.AbsServiceImpl
              extended byorg.objectweb.jonas.web.AbsJWebContainerServiceImpl
All Implemented Interfaces:
AbsJWebContainerServiceImplMBean, JWebContainerService, javax.management.NotificationBroadcaster, javax.management.NotificationEmitter, ReconfigDispatcherMBean, Service
Direct Known Subclasses:
CatalinaJWebContainerServiceImpl, JettyJWebContainerServiceImpl

public abstract class AbsJWebContainerServiceImpl
extends AbsServiceImpl
implements JWebContainerService, AbsJWebContainerServiceImplMBean

This abstract class provides an implementation for a dynamic JWebContainerService service.

Author:
Florent Benoit, Ludovic Bert (J2EE 1.3), Nicolas Van Caneghem (exploded ear), Michel-Ange Anton (contributor)

Nested Class Summary
 class AbsJWebContainerServiceImpl.WebLoaderHolder
          Holds the ClassLoader used to retrieve the WebApp JNDI Context and the JOnAS Webapp ClasLoader
 
Field Summary
static java.lang.String AUTOLOADDIR
          Web service configuration properties : Autdeployed the files in these directories
static java.lang.String CLASS
          Web service configuration properties : Implementation of the web container
static java.lang.String DESCRIPTORS
          Web service configuration properties : Files deployed
protected static java.lang.String INEAR_WORK_WEBAPPS_DIR_SUFFIX
          The name of the property used in work directory for EAR webapps (in ear case).
protected static java.lang.String JONAS_BASE
          The name of the JONAS_BASE directory.
static java.lang.String PARSINGWITHVALIDATION
          Web service configuration properties : Xml parsing with validation
protected static java.lang.String SINGLE_WORK_WEBAPPS_DIR_SUFFIX
          The name of the property used in work directory for single webapps (not ear case).
protected static java.lang.String WEBAPPS_DIR
          The name of the webapps directory.
protected static java.lang.String WORK_DIR
          The name of the working directory.
protected static java.lang.String WORK_WEBAPPS_DIR
          The name of the working apps directory.
 
Fields inherited from class org.objectweb.jonas.management.ReconfigDispatcher
RECONFIG_TYPE, SAVE_RECONFIG_TYPE
 
Constructor Summary
AbsJWebContainerServiceImpl()
           
 
Method Summary
 void deployWars(javax.naming.Context ctx)
          Deploy the given wars of an ear file with the specified parent classloader (ejb classloader or ear classloader).
protected  void doInit(javax.naming.Context ctx)
          Initialize the service.
protected abstract  void doRegisterWar(javax.naming.Context ctx)
          Create the environment and delegate the operation to the implementation of the web container.
protected  void doStart()
          Start the service.
protected  void doStop()
          Stop the service.
protected abstract  void doUnRegisterWar(javax.naming.Context ctx)
          Delegate the unregistration to the implementation of the web container.
 java.util.List getAutoloadDirectories()
          Return the list of "autoload" directories for web applications.
 java.net.URLClassLoader getClassLoader(java.net.URL warURL, java.lang.String earAppName, java.lang.ClassLoader parentLoader)
          Return the class loader of the given warURL.
 java.lang.ClassLoader getContextLinkedClassLoader(java.net.URL warURL)
           
 java.lang.Integer getCurrentNumberOfWars()
           
abstract  java.lang.String getDefaultHost()
          Return the Default host name of the web container.
abstract  java.lang.String getDefaultHttpPort()
          Return the Default HTTP port number of the web container (can be null if multiple HTTP connector has been set).
abstract  java.lang.String getDefaultHttpsPort()
          Return the Default HTTPS port number of the web container (can be null if multiple HTTPS connector has been set).
 java.util.List getDeployableWars()
          Return the list of installed web applications ready to deploy.
 java.util.List getDeployedWars()
          Return the list of all loaded web applications.
 java.util.List getInstalledWars()
          Return the list of installed web applications.
protected static org.objectweb.util.monolog.api.Logger getLogger()
           
protected  javax.management.MBeanServer getMbeanServer()
           
protected  ContainerNaming getNaming()
           
 java.lang.String getServerName()
          Gets the name of the server which is the web container
 java.lang.String getServerVersion()
          Gets the version of the server which is the web container
protected  java.net.URL getUnpackDir(java.net.URL warURL, java.lang.String earAppName)
          Return the URL where warURL has been unpacked.
 War getWar(java.net.URL url)
          Get the war identified by its URL (.war).
 java.util.Set getWarNames()
          This method is added temporarily.
 java.lang.String getWebappsDirectory()
          Return the WebApps directory.
 boolean isWarLoaded(java.lang.String fileName)
          Test if the specified filename is already deployed or not
 void registerWarMBean(java.lang.String fileName)
          Register a WAR by delegating the operation to the registerWar() method.
 void removeCache(java.lang.ClassLoader earClassLoader)
          Make a cleanup of the cache of deployment descriptor.
protected  void setServerName(java.lang.String serverName)
           
protected  void setServerVersion(java.lang.String serverVersion)
           
 void unDeployWars(java.net.URL[] urls)
          Undeploy the given wars of an ear file with the specified parent classloader (ejb classloader or ear classloader).
 void unRegisterWarMBean(java.lang.String fileName)
          Unregister a WAR by delegating the operation to the unRegisterWar() method.
protected abstract  void updateServerInfos()
          Update info of the serverName and serverVersion
 
Methods inherited from class org.objectweb.jonas.service.AbsServiceImpl
getDomainName, getJonasServerName, getName, init, isStarted, setName, start, stop
 
Methods inherited from class org.objectweb.jonas.management.ReconfigDispatcher
addNotificationListener, getFilter, getHandback, getListener, getNotificationInfo, initLogger, removeNotificationListener, sendReconfigNotification, sendSaveNotification
 
Methods inherited from class javax.management.NotificationBroadcasterSupport
handleNotification, 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.objectweb.jonas.service.Service
getName, init, isStarted, setName, start, stop
 

Field Detail

JONAS_BASE

protected static final java.lang.String JONAS_BASE
The name of the JONAS_BASE directory.


WEBAPPS_DIR

protected static final java.lang.String WEBAPPS_DIR
The name of the webapps directory.


WORK_DIR

protected static final java.lang.String WORK_DIR
The name of the working directory.


WORK_WEBAPPS_DIR

protected static final java.lang.String WORK_WEBAPPS_DIR
The name of the working apps directory.


SINGLE_WORK_WEBAPPS_DIR_SUFFIX

protected static final java.lang.String SINGLE_WORK_WEBAPPS_DIR_SUFFIX
The name of the property used in work directory for single webapps (not ear case).

See Also:
Constant Field Values

INEAR_WORK_WEBAPPS_DIR_SUFFIX

protected static final java.lang.String INEAR_WORK_WEBAPPS_DIR_SUFFIX
The name of the property used in work directory for EAR webapps (in ear case).

See Also:
Constant Field Values

DESCRIPTORS

public static final java.lang.String DESCRIPTORS
Web service configuration properties : Files deployed

See Also:
Constant Field Values

AUTOLOADDIR

public static final java.lang.String AUTOLOADDIR
Web service configuration properties : Autdeployed the files in these directories

See Also:
Constant Field Values

PARSINGWITHVALIDATION

public static final java.lang.String PARSINGWITHVALIDATION
Web service configuration properties : Xml parsing with validation

See Also:
Constant Field Values

CLASS

public static final java.lang.String CLASS
Web service configuration properties : Implementation of the web container

See Also:
Constant Field Values
Constructor Detail

AbsJWebContainerServiceImpl

public AbsJWebContainerServiceImpl()
Method Detail

doInit

protected void doInit(javax.naming.Context ctx)
               throws ServiceException
Initialize the service.

Specified by:
doInit in class AbsServiceImpl
Parameters:
ctx - the configuration context of the service.
Throws:
ServiceException - if the initialization failed.

doStart

protected void doStart()
                throws ServiceException
Start the service.

Specified by:
doStart in class AbsServiceImpl
Throws:
ServiceException - if the startup failed.

doStop

protected void doStop()
               throws ServiceException
Stop the service.

Specified by:
doStop in class AbsServiceImpl
Throws:
ServiceException - if the stop failed.

doRegisterWar

protected abstract void doRegisterWar(javax.naming.Context ctx)
                               throws JWebContainerServiceException
Create the environment and delegate the operation to the implementation of the web container.

Parameters:
ctx - the context which contains the configuration in order to deploy a WAR.
Throws:
JWebContainerServiceException - if the registration of the WAR failed.

doUnRegisterWar

protected abstract void doUnRegisterWar(javax.naming.Context ctx)
                                 throws JWebContainerServiceException
Delegate the unregistration to the implementation of the web container.

Parameters:
ctx - the context which contains the configuration in order to undeploy a WAR.
Throws:
JWebContainerServiceException - if the unregistration failed.

getUnpackDir

protected java.net.URL getUnpackDir(java.net.URL warURL,
                                    java.lang.String earAppName)
                             throws JWebContainerServiceException
Return the URL where warURL has been unpacked.

Parameters:
warURL - the URL of the war
earAppName - EAR Application name (can be null if not in EAR case)
Returns:
the URL where warURL has been unpacked.
Throws:
JWebContainerServiceException - when it is impossible to retrieve the unpacked URL.

getClassLoader

public java.net.URLClassLoader getClassLoader(java.net.URL warURL,
                                              java.lang.String earAppName,
                                              java.lang.ClassLoader parentLoader)
                                       throws JWebContainerServiceException
Return the class loader of the given warURL. Unpack the associated war and build the loader if it's not in the cache.

Specified by:
getClassLoader in interface JWebContainerService
Parameters:
warURL - the url of the war we want to get the loader
earAppName - the name of the ear application containing the war. May be null in non ear case.
parentLoader - the ejb class loader of the ear. May be null in non ear case.
Returns:
the class loader of the given warURL.
Throws:
JWebContainerServiceException - if the process failed.

getContextLinkedClassLoader

public java.lang.ClassLoader getContextLinkedClassLoader(java.net.URL warURL)
Specified by:
getContextLinkedClassLoader in interface JWebContainerService
Parameters:
warURL - the URL of the webapp
Returns:
Returns the ClassLoader used to link a JNDI environnment to a webapp

registerWarMBean

public void registerWarMBean(java.lang.String fileName)
                      throws java.rmi.RemoteException,
                             JWebContainerServiceException
Register a WAR by delegating the operation to the registerWar() method. This is used for JMX management.

Specified by:
registerWarMBean in interface JWebContainerService
Parameters:
fileName - the name of the war to deploy.
Throws:
java.rmi.RemoteException - if rmi call failed.
JWebContainerServiceException - if the registration failed.

unRegisterWarMBean

public void unRegisterWarMBean(java.lang.String fileName)
                        throws java.rmi.RemoteException,
                               JWebContainerServiceException
Unregister a WAR by delegating the operation to the unRegisterWar() method. This is used for JMX management.

Specified by:
unRegisterWarMBean in interface JWebContainerService
Parameters:
fileName - the name of the war to undeploy.
Throws:
java.rmi.RemoteException - if rmi call failed.
JWebContainerServiceException - if the unregistration failed.

deployWars

public void deployWars(javax.naming.Context ctx)
                throws JWebContainerServiceException
Deploy the given wars of an ear file with the specified parent classloader (ejb classloader or ear classloader). (This method is only used for the ear applications, not for the web applications).

Specified by:
deployWars in interface JWebContainerService
Parameters:
ctx - the context containing the configuration to deploy the wars.
This context contains the following parameters :
- urls the list of the urls of the wars to deploy.
- earURL the URL of the ear application file.
- parentClassLoader the parent classLoader of the wars.
- earClassLoader the ear classLoader of the j2ee app.
- altDDs the optional URI of deployment descriptor.
- contextRoots the optional context root of the wars.
Throws:
JWebContainerServiceException - if an error occurs during the deployment.

unDeployWars

public void unDeployWars(java.net.URL[] urls)
Undeploy the given wars of an ear file with the specified parent classloader (ejb classloader or ear classloader). (This method is only used for the ear applications, not for the war applications).

Specified by:
unDeployWars in interface JWebContainerService
Parameters:
urls - the list of the urls of the wars to undeploy.

getWar

public War getWar(java.net.URL url)
Get the war identified by its URL (.war).

Specified by:
getWar in interface JWebContainerService
Parameters:
url - the URL of the war to get.
Returns:
the war indentified by its URL, or null if the war is not found.

removeCache

public void removeCache(java.lang.ClassLoader earClassLoader)
Make a cleanup of the cache of deployment descriptor. This method must be invoked after the ear deployment by the EAR service.

Specified by:
removeCache in interface JWebContainerService
Parameters:
earClassLoader - the ClassLoader of the ear application to remove from the cache.

getCurrentNumberOfWars

public java.lang.Integer getCurrentNumberOfWars()
Specified by:
getCurrentNumberOfWars in interface AbsJWebContainerServiceImplMBean
Returns:
current number of wars deployed in the JOnAS server

getInstalledWars

public java.util.List getInstalledWars()
                                throws java.lang.Exception
Return the list of installed web applications. The WAR files or the directories with expanded web application are searched in JONAS_BASE/webapps and all webapps directories 'autoload'.

Specified by:
getInstalledWars in interface AbsJWebContainerServiceImplMBean
Returns:
The list of WAR files or the directories with expanded web application found
Throws:
java.lang.Exception - if the list can't be retrieved

getWarNames

public java.util.Set getWarNames()
This method is added temporarily. It will disapear when Wars will have their associated MBeans (when Wars will become manageable)

Specified by:
getWarNames in interface AbsJWebContainerServiceImplMBean
Returns:
the names of the wars currently deployed in the JOnAS server

isWarLoaded

public boolean isWarLoaded(java.lang.String fileName)
Test if the specified filename is already deployed or not

Specified by:
isWarLoaded in interface JWebContainerService
Parameters:
fileName - the name of the war file.
Returns:
true if the war is deployed, else false.

getDeployedWars

public java.util.List getDeployedWars()
Return the list of all loaded web applications.

Specified by:
getDeployedWars in interface AbsJWebContainerServiceImplMBean
Returns:
The list of deployed web applications

getDeployableWars

public java.util.List getDeployableWars()
                                 throws java.lang.Exception
Return the list of installed web applications ready to deploy.

Specified by:
getDeployableWars in interface AbsJWebContainerServiceImplMBean
Returns:
The list of deployable web applications
Throws:
java.lang.Exception - if the list can't be retrieved

getAutoloadDirectories

public java.util.List getAutoloadDirectories()
Return the list of "autoload" directories for web applications.

Specified by:
getAutoloadDirectories in interface AbsJWebContainerServiceImplMBean
Returns:
The list of all "autoload" directories

getWebappsDirectory

public java.lang.String getWebappsDirectory()
Return the WebApps directory.

Specified by:
getWebappsDirectory in interface JWebContainerService
Returns:
The WebApps directory

getServerName

public java.lang.String getServerName()
Gets the name of the server which is the web container

Specified by:
getServerName in interface AbsJWebContainerServiceImplMBean
Returns:
the name of the server which is the web container

getServerVersion

public java.lang.String getServerVersion()
Gets the version of the server which is the web container

Specified by:
getServerVersion in interface AbsJWebContainerServiceImplMBean
Returns:
the version of the server which is the web container

updateServerInfos

protected abstract void updateServerInfos()
Update info of the serverName and serverVersion


getDefaultHost

public abstract java.lang.String getDefaultHost()
                                         throws JWebContainerServiceException
Return the Default host name of the web container.

Specified by:
getDefaultHost in interface JWebContainerService
Returns:
the Default host name of the web container.
Throws:
JWebContainerServiceException - when it is impossible to get the Default Host.

getDefaultHttpPort

public abstract java.lang.String getDefaultHttpPort()
                                             throws JWebContainerServiceException
Return the Default HTTP port number of the web container (can be null if multiple HTTP connector has been set).

Specified by:
getDefaultHttpPort in interface JWebContainerService
Returns:
the Default HTTP port number of the web container.
Throws:
JWebContainerServiceException - when it is impossible to get the Default Http port.

getDefaultHttpsPort

public abstract java.lang.String getDefaultHttpsPort()
                                              throws JWebContainerServiceException
Return the Default HTTPS port number of the web container (can be null if multiple HTTPS connector has been set).

Specified by:
getDefaultHttpsPort in interface JWebContainerService
Returns:
the Default HTTPS port number of the web container.
Throws:
JWebContainerServiceException - when it is impossible to get the Default Https port.

getLogger

protected static org.objectweb.util.monolog.api.Logger getLogger()
Returns:
Returns the logger.

getNaming

protected ContainerNaming getNaming()
Returns:
Returns the naming.

getMbeanServer

protected javax.management.MBeanServer getMbeanServer()
Returns:
Returns the mbeanServer.

setServerName

protected void setServerName(java.lang.String serverName)
Parameters:
serverName - The serverName to set.

setServerVersion

protected void setServerVersion(java.lang.String serverVersion)
Parameters:
serverVersion - The serverVersion to set.