org.ow2.jonas.web.tomcat6
Class Tomcat6Service

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
                  extended by org.ow2.jonas.web.tomcat6.Tomcat6Service
All Implemented Interfaces:
NotificationBroadcaster, NotificationEmitter, Service, BaseWebContainerServiceMBean, JWebContainerService

public class Tomcat6Service
extends BaseWebContainerService
implements JWebContainerService

Implementation of the web container service for Tomcat 6. This service also adds virtual path support to Tomcat 6.

Author:
Florent BENOIT, S. Ali Tokmen

Nested Class Summary
 
Nested classes/interfaces inherited from class org.ow2.jonas.web.base.BaseWebContainerService
BaseWebContainerService.WebLoaderHolder
 
Field Summary
protected static String CONFIG_FILE
          Relative path of the configuration file.
 
Fields inherited from class org.ow2.jonas.web.base.BaseWebContainerService
INEAR_WORK_WEBAPPS_DIR_SUFFIX, jmxService, JONAS_BASE, SINGLE_WORK_WEBAPPS_DIR_SUFFIX, WORK_DIR, WORK_WEBAPPS_DIR
 
Fields inherited from class org.ow2.jonas.lib.reconfig.ReconfigEmitter
RECONFIG_TYPE, SAVE_RECONFIG_TYPE
 
Constructor Summary
Tomcat6Service(org.osgi.framework.BundleContext context)
          Default constructor.
 
Method Summary
protected  void checkStartedContext(org.apache.catalina.Context context, PermissionManager permissionManager)
          Check that the context that was started was right configured.
protected  org.apache.catalina.startup.ContextConfig createContextConfig()
           
 Realm createJOnASRealm(String name, boolean isJaccRealm)
          Creates a new JOnAS Realm (JACC or JAAS).
protected  org.apache.tomcat.util.digester.Digester createServerDigester()
          Create and configure the Digester that will be used for the xml parsing of the configuration file.
protected  void doRegisterWar(Context ctx)
          Deploy a specific WAR file specified in the context.
 void doStart()
          Start the Catalina service in a new thread.
protected  void doStop()
          Stop the Catalina service.
protected  void doUnRegisterWar(Context ctx)
          Undeploy a specific WAR file specified in the context.
 org.apache.catalina.Host findHost(String hostName)
          Find the specified host.
protected  File getConfigFile()
          Return a File object representing the server.xml configuration file.
protected  List<JOnASStandardContext> getConfiguredMatchingJonasContexts(String contextRoot, File fpackedWar, String destDir)
          Check if there is a previous JOnASStandardContext which match the current context If true, deploy our context into the configured context.
protected  List<org.apache.catalina.Context> getContexts()
          Gets all the contexts of the current Tomcat server.
 String getDefaultHost()
          Return the Default host name of the web container.
 String getDefaultHttpPort()
          Return the Default HTTP port number of the web container.
 String getDefaultHttpsPort()
          Return the Default HTTPS port number of the web container (can be null if multiple HTTPS connector has been set).
protected  List<org.apache.catalina.core.StandardEngine> getEngines()
          Gets all the engines of the current Tomcat server.
protected  org.apache.catalina.Service getFirstService()
           
protected  int getPort(String scheme)
          Finds the first connector supporting the given URL scheme and return its listening port.
 IResourceCheckerManager getResourceCheckerManager()
           
protected  SecurityService getSecurityService()
           
 org.apache.catalina.Server getServer()
           
protected  TransactionService getTransactionService()
           
protected  void initCatalinaEnvironment()
          Init the environment of catalina set catalina.home, catalina.base and unset the tomcat naming.
 boolean isInternalContainerStarted()
          Checks if the internal web container has been started.
 boolean isTomcatStarted()
          The server is started ?
 void registerWar(String fileName)
          Register a WAR by delegating the operation to the registerWar() method.
 void removeContext(org.apache.catalina.Context context)
          Remove the specified Context from the set of defined Contexts for its associated Host.
 void setResourceCheckerManager(IResourceCheckerManager resourceCheckerManager)
          Sets the resource checker manager.
 void setSecurityService(SecurityService securityService)
           
 void setServer(org.apache.catalina.Server server)
          Set the server instance we are configuring.
 void setTransactionService(TransactionService transactionService)
           
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 startInternalWebContainer()
          Starts the specific code for the web container implementation.
 void unRegisterWar(String fileName)
          Unregister a WAR by delegating the operation to the unRegisterWar() method.
 void unsetResourceCheckerManager()
          Unset the resource checker manager.
protected  void updateServerInfos()
          Update info of the serverName and serverVersion.
 
Methods inherited from class org.ow2.jonas.web.base.BaseWebContainerService
bindJaxwsService, checkWarDeployed, checkWarFile, deployWars, getAppsClassLoader, getClassLoader, getContextFactory, getContextLinkedClassLoader, getContextRoot, getCurrentNumberOfWars, getDeployedWars, getJAXRPCService, getJAXWSService, getLogger, getNaming, getOnDemandRedirectPort, getRandomPort, getServerName, getServerVersion, getUnpackedURL, getVersioningService, getWar, getWar, getWarBindings, getWarDeployed, getWarLoaders, initWorkingDirectory, isOnDemandFeatureEnabled, isVersioningEnabled, isWarDeployedByWorkName, isWarLoaded, registerWar, registerWarMBean, registerWebServiceMBean, removeCache, setContextFactory, setDeployerManager, setEjb3Service, setJAXRPCService, setJmxService, setNaming, setOnDemandFeature, setOnDemandRedirectPort, setParsingwithvalidation, setServerName, setServerVersion, setVersioningService, setWarDeployableMetadataFactory, setWorkCleanerService, unbindJaxwsService, unDeployWars, unRegisterWar, unregisterWarMBean, unregisterWebServiceMBean, unsetEjb3Service, unsetVersioningService
 
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.web.JWebContainerService
deployWars, getClassLoader, getContextLinkedClassLoader, isWarDeployedByWorkName, isWarLoaded, removeCache, unDeployWars
 
Methods inherited from interface org.ow2.jonas.service.Service
getName, init, isStarted, setName, start, stop
 

Field Detail

CONFIG_FILE

protected static final String CONFIG_FILE
Relative path of the configuration file.

Constructor Detail

Tomcat6Service

public Tomcat6Service(org.osgi.framework.BundleContext context)
Default constructor.

Method Detail

initCatalinaEnvironment

protected void initCatalinaEnvironment()
                                throws ServiceException
Init the environment of catalina set catalina.home, catalina.base and unset the tomcat naming.

Throws:
ServiceException - if catalina home is not set

doStart

public void doStart()
             throws ServiceException
Start the Catalina service in a new thread.

Overrides:
doStart in class BaseWebContainerService
Throws:
ServiceException - if the startup failed.

startInternalWebContainer

public 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)

Specified by:
startInternalWebContainer in class BaseWebContainerService
Throws:
JWebContainerServiceException - if container is not started

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.

Overrides:
setWebEnvironment in class BaseWebContainerService
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.

isInternalContainerStarted

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

Specified by:
isInternalContainerStarted in class BaseWebContainerService
Returns:
true if it is already started

doStop

protected void doStop()
               throws ServiceException
Stop the Catalina service.

Overrides:
doStop in class BaseWebContainerService
Throws:
ServiceException - if the stop failed.

doRegisterWar

protected void doRegisterWar(Context ctx)
                      throws JWebContainerServiceException
Deploy a specific WAR file specified in the context.

Specified by:
doRegisterWar in class BaseWebContainerService
Parameters:
ctx - the context which contains the configuration in order to deploy the WAR.
Throws:
JWebContainerServiceException - if the registration of the WAR failed.

createContextConfig

protected org.apache.catalina.startup.ContextConfig createContextConfig()
Returns:
a new ContextConfig for JOnAS.

createJOnASRealm

public Realm createJOnASRealm(String name,
                              boolean isJaccRealm)
Creates a new JOnAS Realm (JACC or JAAS).

Parameters:
name - resource name or entry name (depends if a JACC or JAAS realm is required)
isJaccRealm - true if a JACC realm is required, false for a JAAS realm.
Returns:
a configured Realm.

getConfiguredMatchingJonasContexts

protected List<JOnASStandardContext> getConfiguredMatchingJonasContexts(String contextRoot,
                                                                        File fpackedWar,
                                                                        String destDir)
Check if there is a previous JOnASStandardContext which match the current context If true, deploy our context into the configured context.

Parameters:
contextRoot - name of the context that we want to find preconfigured contexts
fpackedWar - file of the original war file
destDir - name of the unpacked directory of the war file
Returns:
true if a context was found and used

checkStartedContext

protected void checkStartedContext(org.apache.catalina.Context context,
                                   PermissionManager permissionManager)
                            throws JWebContainerServiceException
Check that the context that was started was right configured.

Parameters:
context - context to check
permissionManager - the permission manager used for JACC
Throws:
JWebContainerServiceException - if the context was not right configured

getEngines

protected List<org.apache.catalina.core.StandardEngine> getEngines()
                                                            throws JWebContainerServiceException
Gets all the engines of the current Tomcat server.

Returns:
all the engines of the current Tomcat server
Throws:
JWebContainerServiceException - if engines can not be retrieved

getContexts

protected List<org.apache.catalina.Context> getContexts()
                                                 throws JWebContainerServiceException
Gets all the contexts of the current Tomcat server.

Returns:
all the contexts of the current Tomcat server
Throws:
JWebContainerServiceException - if contexts can not be retrieved

doUnRegisterWar

protected void doUnRegisterWar(Context ctx)
                        throws JWebContainerServiceException
Undeploy a specific WAR file specified in the context.

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

removeContext

public void removeContext(org.apache.catalina.Context context)
                   throws JWebContainerServiceException
Remove the specified Context from the set of defined Contexts for its associated Host. If this is the last Context for this Host, the Host will also be removed.

Parameters:
context - The Context to be removed
Throws:
JWebContainerServiceException - if the context can not be removed

isTomcatStarted

public boolean isTomcatStarted()
The server is started ?

Returns:
boolean true if the catalina container is running.

setServer

public void setServer(org.apache.catalina.Server server)
Set the server instance we are configuring.

Parameters:
server - The new server

getServer

public org.apache.catalina.Server getServer()
Returns:
the server instance

getConfigFile

protected File getConfigFile()
                      throws FileNotFoundException
Return a File object representing the server.xml configuration file.

Returns:
a File object representing the server.xml configuration file.
Throws:
FileNotFoundException - if the configuration file is not found.

findHost

public org.apache.catalina.Host findHost(String hostName)
                                  throws JWebContainerServiceException
Find the specified host.

Parameters:
hostName - the name of the host to find.
Returns:
the host found.
Throws:
JWebContainerServiceException - if the specified host cannot be found.

createServerDigester

protected org.apache.tomcat.util.digester.Digester createServerDigester()
Create and configure the Digester that will be used for the xml parsing of the configuration file.

Returns:
Digester the digester containing the rules for the xml parsing of the server.xml.

updateServerInfos

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

Specified by:
updateServerInfos in class BaseWebContainerService

getDefaultHost

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

Specified by:
getDefaultHost in interface JWebContainerService
Specified by:
getDefaultHost in class BaseWebContainerService
Returns:
the Default host name of the web container.
Throws:
JWebContainerServiceException - when default host cannot be resolved (multiple services).

getDefaultHttpPort

public String getDefaultHttpPort()
                          throws JWebContainerServiceException
Return the Default HTTP port number of the web container. Returns the first connector port if more than one are defined.

Specified by:
getDefaultHttpPort in interface JWebContainerService
Specified by:
getDefaultHttpPort in class BaseWebContainerService
Returns:
the Default HTTP port number of the web container.
Throws:
JWebContainerServiceException - when default HTTP port cannot be resolved or none are defined.

getDefaultHttpsPort

public 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
Specified by:
getDefaultHttpsPort in class BaseWebContainerService
Returns:
the Default HTTPS port number of the web container.
Throws:
JWebContainerServiceException - when default HTTPS port cannot be resolved (0 occurences).

getPort

protected int getPort(String scheme)
               throws JWebContainerServiceException
Finds the first connector supporting the given URL scheme and return its listening port.

Parameters:
scheme - URL schema (http/https)
Returns:
Port number for a given scheme.
Throws:
JWebContainerServiceException - if no connectors were found

getFirstService

protected org.apache.catalina.Service getFirstService()
Returns:
Returns the first found Service

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
Overrides:
registerWar in class BaseWebContainerService
Parameters:
fileName - the name of the war to deploy.
Throws:
RemoteException - if rmi call failed.
JWebContainerServiceException - if the registration 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
Overrides:
unRegisterWar in class BaseWebContainerService
Parameters:
fileName - the name of the war to undeploy.
Throws:
RemoteException - if rmi call failed.
JWebContainerServiceException - if the unregistration failed.

setSecurityService

public void setSecurityService(SecurityService securityService)
Parameters:
securityService - Security service to set.

getSecurityService

protected SecurityService getSecurityService()
Returns:
Security service.

setTransactionService

public void setTransactionService(TransactionService transactionService)
Parameters:
transactionService - TX service to set.

getTransactionService

protected TransactionService getTransactionService()
Returns:
TX service.

getResourceCheckerManager

public IResourceCheckerManager getResourceCheckerManager()
Returns:
the resource checker manager

setResourceCheckerManager

public void setResourceCheckerManager(IResourceCheckerManager resourceCheckerManager)
Sets the resource checker manager.

Parameters:
resourceCheckerManager - the given instance

unsetResourceCheckerManager

public void unsetResourceCheckerManager()
Unset the resource checker manager.



Copyright © 2010 OW2 Consortium. All Rights Reserved.