org.ow2.jonas.web.base
Class BaseWebContainerService

java.lang.Object
  extended by javax.management.NotificationBroadcasterSupport
      extended by org.ow2.jonas.lib.reconfig.ReconfigEmitter
          extended by org.ow2.jonas.lib.service.AbsServiceImpl
              extended by org.ow2.jonas.web.base.BaseWebContainerService
All Implemented Interfaces:
NotificationBroadcaster, NotificationEmitter, Service, BaseWebContainerServiceMBean, JWebContainerService
Direct Known Subclasses:
Jetty6Service, Tomcat6Service

public abstract class BaseWebContainerService
extends AbsServiceImpl
implements JWebContainerService, BaseWebContainerServiceMBean

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), S. Ali Tokmen (versioning)

Nested Class Summary
 class BaseWebContainerService.WebLoaderHolder
          Holds the ClassLoader used to retrieve the WebApp JNDI Context and the JOnAS Webapp ClasLoader.
 
Field Summary
protected static String INEAR_WORK_WEBAPPS_DIR_SUFFIX
          The name of the property used in work directory for EAR webapps (in ear case).
protected  JmxService jmxService
          JMX Service.
protected static String JONAS_BASE
          The name of the JONAS_BASE directory.
protected static String SINGLE_WORK_WEBAPPS_DIR_SUFFIX
          The name of the property used in work directory for single webapps (not ear case).
protected static String WORK_DIR
          The name of the working directory.
protected static String WORK_WEBAPPS_DIR
          The name of the working apps directory.
 
Fields inherited from class org.ow2.jonas.lib.reconfig.ReconfigEmitter
RECONFIG_TYPE, SAVE_RECONFIG_TYPE
 
Constructor Summary
BaseWebContainerService()
          Default constructor.
 
Method Summary
 void bindJaxwsService(IJAXWSService jaxwsService)
          Store the reference to the JAX-WS Service.
protected  URL checkWarDeployed(String fileName)
          Check if the specified file is already deployed in the JOnAS server and return the URL of this deployed war file.
protected  URL checkWarFile(String fileName)
          Check if the specified file name correspond to a file which is located relatively to where the JOnAS server is launched or in the $JONAS_BASE/web-apps.
 void deployWars(Context ctx)
          Deploy the given wars of an ear file with the specified parent classloader (ejb classloader or ear classloader).
protected abstract  void doRegisterWar(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(Context ctx)
          Delegate the unregistration to the implementation of the web container.
protected  ClassLoader getAppsClassLoader()
           
 WebappClassLoader getClassLoader(URL warURL, org.ow2.util.ee.deploy.api.deployable.EARDeployable earDeployable, ClassLoader parentLoader)
          Return the class loader of the given warURL.
protected  JComponentContextFactory getContextFactory()
           
 ClassLoader getContextLinkedClassLoader(URL warURL)
           
protected  String getContextRoot(String contextRoot, URLClassLoader earClassLoader, URL warURL, WebContainerDeploymentDesc webDD)
          Gets the context root for a WAR.
 Integer getCurrentNumberOfWars()
           
abstract  String getDefaultHost()
          Return the Default host name of the web container.
abstract  String getDefaultHttpPort()
          Return the Default HTTP port number of the web container (can be null if multiple HTTP connector has been set).
abstract  String getDefaultHttpsPort()
          Return the Default HTTPS port number of the web container (can be null if multiple HTTPS connector has been set).
 List<String> getDeployedWars()
          Return the list of all loaded web applications.
protected  IJAXRPCService getJAXRPCService()
           
protected  IJAXWSService getJAXWSService()
           
protected static org.objectweb.util.monolog.api.Logger getLogger()
           
protected  JNamingManager getNaming()
           
 int getOnDemandRedirectPort()
           
 int getRandomPort()
           
 String getServerName()
          Gets the name of the server which is the web container.
 String getServerVersion()
          Gets the version of the server which is the web container.
protected  URL getUnpackedURL(URL warURL, org.ow2.util.ee.deploy.api.deployable.EARDeployable earDeployable)
          Return the URL where warURL has been unpacked.
 VersioningService getVersioningService()
           
protected  List getWar(String pContext)
          Get a list of wars identified by their Context.
 War getWar(URL url)
          Get the war identified by its URL (.war).
protected  Hashtable getWarBindings()
           
protected  List getWarDeployed()
           
protected  Hashtable getWarLoaders()
           
protected  void initWorkingDirectory()
          Create working directory for applications.
abstract  boolean isInternalContainerStarted()
          Checks if the internal web container has been started.
 boolean isOnDemandFeatureEnabled()
           
 boolean isVersioningEnabled()
           
 boolean isWarDeployedByWorkName(String unpackName)
          Test if the specified unpack name is already deployed or not.
 boolean isWarLoaded(String fileName)
          Test if the specified filename is already deployed or not.
protected  void registerWar(Context ctx)
          Create the environment and delegate the operation to the implementation of the web container.
 void registerWar(String fileName)
          Register a WAR by delegating the operation to the registerWar() method.
protected  void registerWarMBean(War war, String domainName, String fileName)
          Register War MBean.
protected  void registerWebServiceMBean(Object service, String domainName)
          Register WEB Container Service MBean.
 void removeCache(ClassLoader earClassLoader)
          Make a cleanup of the cache of deployment descriptor.
 void setContextFactory(JComponentContextFactory contextFactory)
           
 void setDeployerManager(org.ow2.util.ee.deploy.api.deployer.IDeployerManager deployerManager)
           
 void setEjb3Service(IEasyBeansService service)
           
 void setJAXRPCService(IJAXRPCService jaxrpcService)
           
 void setJmxService(JmxService jmxService)
           
 void setNaming(JNamingManager naming)
           
 void setOnDemandFeature(boolean onDemandFeatureEnabled)
          Enable or not the on demand feature.
 void setOnDemandRedirectPort(int onDemandRedirectPort)
          Sets the redirect port number
 void setParsingwithvalidation(boolean validate)
           
protected  void setServerName(String serverName)
           
protected  void setServerVersion(String serverVersion)
           
 void setVersioningService(VersioningService versioningService)
           
 void setWarDeployableMetadataFactory(org.ow2.util.ee.metadata.war.api.IWarDeployableMetadataFactory warDeployableMetadataFactory)
           
protected  void setWebEnvironment(Context ctxParam, org.ow2.easybeans.deployment.api.EZBInjectionHolder ezbInjectionHolder, ClassLoader webAppClassLoader)
          Set the environment of the web container inside the given context.
 void setWorkCleanerService(WorkCleanerService workCleanerService)
          Method called when the workCleanerService is bound to the component.
abstract  void startInternalWebContainer()
          Starts the specific code for the web container implementation.
 void unbindJaxwsService(IJAXWSService jaxwsService)
          Release the reference to the JAWS Service.
 void unDeployWars(URL[] urls)
          Undeploy the given wars of an ear file with the specified parent classloader (ejb classloader or ear classloader).
protected  void unRegisterWar(Context ctx)
          Delegate the unregistration to the implementation of the web container and delete the environment associated to the WAR file.
 void unRegisterWar(String fileName)
          Unregister a WAR by delegating the operation to the unRegisterWar() method.
protected  void unregisterWarMBean(String domainName, String fileName)
          Unegister War MBean.
protected  void unregisterWebServiceMBean(String domainName)
          Unregister WEB Container Service MBean.
 void unsetEjb3Service()
          Unbind the IEasyBeansService.
 void unsetVersioningService()
          Sets the versioning service to null.
protected abstract  void updateServerInfos()
          Update info of the serverName and serverVersion.
 
Methods inherited from class org.ow2.jonas.lib.service.AbsServiceImpl
convertToList, doInit, getDomainName, getJonasServerName, getName, getServerProperties, init, isStarted, setName, setServerProperties, start, stop, throwRequirementException, toString
 
Methods inherited from class org.ow2.jonas.lib.reconfig.ReconfigEmitter
initLogger, sendReconfigNotification, sendSaveNotification
 
Methods inherited from class javax.management.NotificationBroadcasterSupport
addNotificationListener, getNotificationInfo, handleNotification, removeNotificationListener, removeNotificationListener, sendNotification
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.ow2.jonas.service.Service
getName, init, isStarted, setName, start, stop
 

Field Detail

JONAS_BASE

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


WORK_DIR

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


WORK_WEBAPPS_DIR

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


SINGLE_WORK_WEBAPPS_DIR_SUFFIX

protected static final 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 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

jmxService

protected JmxService jmxService
JMX Service.

Constructor Detail

BaseWebContainerService

public BaseWebContainerService()
Default constructor.

Method Detail

setParsingwithvalidation

public void setParsingwithvalidation(boolean validate)
Parameters:
validate - must we parse web.xml files with validation ?

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(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(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.

startInternalWebContainer

public abstract void startInternalWebContainer()
                                        throws JWebContainerServiceException
Starts the specific code for the web container implementation. This allows to start the internal container on demand (if there is an access on the http proxy port for example)

Throws:
JWebContainerServiceException - if container is not started

isInternalContainerStarted

public abstract boolean isInternalContainerStarted()
Checks if the internal web container has been started.

Returns:
true if it is already started

getUnpackedURL

protected URL getUnpackedURL(URL warURL,
                             org.ow2.util.ee.deploy.api.deployable.EARDeployable earDeployable)
                      throws JWebContainerServiceException
Return the URL where warURL has been unpacked.

Parameters:
warURL - the URL of the war
earDeployable - the EAR deployable (could be null)
Returns:
the URL where warURL has been unpacked.
Throws:
JWebContainerServiceException - when it is impossible to retrieve the unpacked URL.

getClassLoader

public WebappClassLoader getClassLoader(URL warURL,
                                        org.ow2.util.ee.deploy.api.deployable.EARDeployable earDeployable,
                                        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
earDeployable - If the WAR is in an EAR application
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 ClassLoader getContextLinkedClassLoader(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

registerWar

protected void registerWar(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.

getContextRoot

protected String getContextRoot(String contextRoot,
                                URLClassLoader earClassLoader,
                                URL warURL,
                                WebContainerDeploymentDesc webDD)
Gets the context root for a WAR.

Parameters:
contextRoot - Current context root, null if none.
earClassLoader - EAR classloader for the WAR, null if none.
warURL - War file's URL.
webDD - Deployment descriptor of the WAR file.
Returns:
Context root, checked (always begin with one slash).

registerWar

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

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

setWebEnvironment

protected void setWebEnvironment(Context ctxParam,
                                 org.ow2.easybeans.deployment.api.EZBInjectionHolder ezbInjectionHolder,
                                 ClassLoader webAppClassLoader)
                          throws JWebContainerServiceException
Set the environment of the web container inside the given context.

Parameters:
ctxParam - the java:comp/env/ environment where is stored the values of the web container environment.
ezbInjectionHolder - the easybeans injection handler.
webAppClassLoader - the classloader of the web application.
Throws:
JWebContainerServiceException - if the populating of the environment failed.

unRegisterWar

protected void unRegisterWar(Context ctx)
                      throws JWebContainerServiceException
Delegate the unregistration to the implementation of the web container and delete the environment associated to the WAR file.

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

unRegisterWar

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

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

deployWars

public void deployWars(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(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(URL url)
Get the war identified by its URL (.war).

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

getWar

protected List getWar(String pContext)
Get a list of wars identified by their Context.

Parameters:
pContext - the context of the war to get.
Returns:
the list of wars indentified by their Context, or an empty list if no wars are found.

removeCache

public void removeCache(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.

checkWarFile

protected URL checkWarFile(String fileName)
                    throws JWebContainerServiceException
Check if the specified file name correspond to a file which is located relatively to where the JOnAS server is launched or in the $JONAS_BASE/web-apps.

Parameters:
fileName - the file to check if it exists.
Returns:
the URL of the file found (either relatively to the JOnAS server or to the $JONAS_BASE/web-apps).
Throws:
JWebContainerServiceException - if the specified file does't exists.

checkWarDeployed

protected URL checkWarDeployed(String fileName)
                        throws JWebContainerServiceException
Check if the specified file is already deployed in the JOnAS server and return the URL of this deployed war file.

Parameters:
fileName - the name of the WAR file to check.
Returns:
the URL of the deployed war file.
Throws:
JWebContainerServiceException - if the file name doesn't correspond to a deployed war.

getCurrentNumberOfWars

public Integer getCurrentNumberOfWars()
Specified by:
getCurrentNumberOfWars in interface BaseWebContainerServiceMBean
Returns:
current number of wars deployed in the JOnAS server

isWarLoaded

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

Specified by:
isWarLoaded in interface BaseWebContainerServiceMBean
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 List<String> getDeployedWars()
Return the list of all loaded web applications.

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

getServerName

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

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

getServerVersion

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

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

isWarDeployedByWorkName

public boolean isWarDeployedByWorkName(String unpackName)
Test if the specified unpack name is already deployed or not. This method is defined in the JWebContainerService interface.

Specified by:
isWarDeployedByWorkName in interface JWebContainerService
Parameters:
unpackName - the name of the ear file.
Returns:
true if the ear is deployed, else false.

updateServerInfos

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


getDefaultHost

public abstract 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 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 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 JNamingManager getNaming()
Returns:
Returns the naming.

setServerName

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

setServerVersion

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

getContextFactory

protected JComponentContextFactory getContextFactory()
Returns:
the JComponentContextFactory.

registerWebServiceMBean

protected void registerWebServiceMBean(Object service,
                                       String domainName)
Register WEB Container Service MBean.

Parameters:
service - web container service to manage
domainName - domain name

unregisterWebServiceMBean

protected void unregisterWebServiceMBean(String domainName)
Unregister WEB Container Service MBean.

Parameters:
domainName - domain name

registerWarMBean

protected void registerWarMBean(War war,
                                String domainName,
                                String fileName)
Register War MBean.

Parameters:
war - War instance to manage
domainName - domain name
fileName - the war file name

unregisterWarMBean

protected void unregisterWarMBean(String domainName,
                                  String fileName)
Unegister War MBean.

Parameters:
domainName - domain name
fileName - the war file name

setJmxService

public void setJmxService(JmxService jmxService)
Parameters:
jmxService - the jmxService to set

setJAXRPCService

public void setJAXRPCService(IJAXRPCService jaxrpcService)
Parameters:
jaxrpcService - the jaxrpcService to set

setNaming

public void setNaming(JNamingManager naming)
Parameters:
naming - the naming to set

setContextFactory

public void setContextFactory(JComponentContextFactory contextFactory)
Parameters:
contextFactory - the contextFactory to set

setDeployerManager

public void setDeployerManager(org.ow2.util.ee.deploy.api.deployer.IDeployerManager deployerManager)
Parameters:
deployerManager - the IDeployerManager to use.

initWorkingDirectory

protected void initWorkingDirectory()
Create working directory for applications.


setWorkCleanerService

public void setWorkCleanerService(WorkCleanerService workCleanerService)
Method called when the workCleanerService is bound to the component.

Parameters:
workCleanerService - the workCleanerService reference

getWarLoaders

protected Hashtable getWarLoaders()
Returns:
Associates an URL of an unpacked WAR file to its classloader.

getWarBindings

protected Hashtable getWarBindings()
Returns:
Associates an URL of a deployed WAR file to its classloader.

getWarDeployed

protected List getWarDeployed()
Returns:
List of the war deployed by the Web container Service.

getJAXRPCService

protected IJAXRPCService getJAXRPCService()
Returns:
Reference to the JAX-RPC service.

getAppsClassLoader

protected ClassLoader getAppsClassLoader()
Returns:
Application Classloader.

setVersioningService

public void setVersioningService(VersioningService versioningService)
Parameters:
versioningService - The versioning service to set.

unsetVersioningService

public void unsetVersioningService()
Sets the versioning service to null.


getVersioningService

public VersioningService getVersioningService()
Returns:
The versioning service.

isVersioningEnabled

public boolean isVersioningEnabled()
Returns:
Whether versioning is enabled.

setWarDeployableMetadataFactory

public void setWarDeployableMetadataFactory(org.ow2.util.ee.metadata.war.api.IWarDeployableMetadataFactory warDeployableMetadataFactory)
Parameters:
warDeployableMetadataFactory - the deployable metadata factory service

bindJaxwsService

public void bindJaxwsService(IJAXWSService jaxwsService)
Store the reference to the JAX-WS Service.

Parameters:
jaxwsService - jaxws Service

getJAXWSService

protected IJAXWSService getJAXWSService()
Returns:
the jaxws service

unbindJaxwsService

public void unbindJaxwsService(IJAXWSService jaxwsService)
Release the reference to the JAWS Service.

Parameters:
jaxwsService - jaxws Service

setEjb3Service

public void setEjb3Service(IEasyBeansService service)
Parameters:
service - the EJB3 Service to be injected.

unsetEjb3Service

public void unsetEjb3Service()
Unbind the IEasyBeansService.


setOnDemandFeature

public void setOnDemandFeature(boolean onDemandFeatureEnabled)
Enable or not the on demand feature.

Parameters:
onDemandFeatureEnabled - boolean true/false

setOnDemandRedirectPort

public void setOnDemandRedirectPort(int onDemandRedirectPort)
Sets the redirect port number

Parameters:
onDemandRedirectPort - the given port used for OnDemand proxy

isOnDemandFeatureEnabled

public boolean isOnDemandFeatureEnabled()
Returns:
true if the on demand feature is enabled and in development mode.

getOnDemandRedirectPort

public int getOnDemandRedirectPort()

getRandomPort

public int getRandomPort()


Copyright © 2010 OW2 Consortium. All Rights Reserved.