Package psiprobe
Class AbstractTomcatContainer
- java.lang.Object
-
- psiprobe.AbstractTomcatContainer
-
- All Implemented Interfaces:
TomcatContainer
public abstract class AbstractTomcatContainer extends Object implements TomcatContainer
Abstraction layer to implement some functionality, which is common between different container adapters.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
AbstractTomcatContainer.FilterMapType
The Enum FilterMapType.
-
Field Summary
Fields Modifier and Type Field Description protected org.apache.catalina.connector.Connector[]
connectors
The connectors.protected ObjectName
deployerOName
The deployer o name.protected org.apache.catalina.Host
host
The host.protected org.slf4j.Logger
logger
The logger.protected MBeanServer
mbeanServer
The mbean server.private static String
NO_JSP_SERVLET
The Constant NO_JSP_SERVLET.
-
Constructor Summary
Constructors Constructor Description AbstractTomcatContainer()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected void
addFilterMapping(String filterName, String dispatcherMap, String filterClass, String[] types, List<FilterMapping> results, AbstractTomcatContainer.FilterMapType filterMapType)
Adds the filter mapping.void
bindToContext(org.apache.catalina.Context context)
Binds a naming context to the current thread's classloader.private void
changeContextBinding(org.apache.catalina.Context context, boolean bind)
Change context binding.protected void
checkChanges(String name)
Check changes.protected void
compileItem(String jspName, org.apache.jasper.Options opt, org.apache.catalina.Context ctx, org.apache.jasper.compiler.JspRuntimeContext jrctx, Summary summary, URLClassLoader classLoader, int level, boolean compile)
Lists and optionally compiles a directory recursively.protected abstract org.apache.jasper.JspCompilationContext
createJspCompilationContext(String name, org.apache.jasper.Options opt, javax.servlet.ServletContext sctx, org.apache.jasper.compiler.JspRuntimeContext jrctx, ClassLoader classLoader)
Creates the jsp compilation context.protected abstract org.apache.catalina.Valve
createValve()
Creates the valve.void
discardWorkDir(org.apache.catalina.Context context)
Deletes the "work" directory of the given context.List<org.apache.catalina.connector.Connector>
findConnectors()
Find connectors.org.apache.catalina.Context
findContext(String name)
Finds a context based on its path.protected org.apache.catalina.Context
findContextInternal(String name)
Find context internal.List<org.apache.catalina.Context>
findContexts()
Find contexts.String
formatContextFilename(String contextName)
Formats a context name so that it can be used as a step for the context descriptor .xml or deployed .war file.String
formatContextName(String name)
Formats a context name to a path that the container will recognize.File
getAppBase()
This method always returns absolute path, no matter what Tomcat is up to.boolean
getAvailable(org.apache.catalina.Context context)
Gets the available.String
getConfigBase()
Gets the config base.File
getConfigFile(org.apache.catalina.Context context)
Returns the context descriptor filename for the given context.String
getHostName()
Gets the host name.String
getName()
Gets the name.protected abstract Object
getNamingToken(org.apache.catalina.Context context)
Returns the security token required to bind to a naming context.String
getServletFileNameForJsp(org.apache.catalina.Context context, String jspName)
Returns the JSP servlet filename for the given JSP file.boolean
installContext(String contextName)
Deploys a context, assuming an context descriptor file exists on the server already.private void
installContextInternal(String name)
Install context internal.void
installWar(String name, URL url)
Installs .war file at the given context name.void
listContextJsps(org.apache.catalina.Context context, Summary summary, boolean compile)
Lists and optionally compiles all JSPs for the given context.void
recompileJsps(org.apache.catalina.Context context, Summary summary, List<String> names)
Compiles a list of JSPs.protected void
registerGlobalResourceAccess(org.apache.tomcat.util.descriptor.web.ContextResourceLink resourceLink)
Register access to global resources.void
remove(String name)
Undeploys a context.private void
removeInternal(String name)
Removes the internal.void
setWrapper(org.apache.catalina.Wrapper wrapper)
Sets the wrapper.void
start(String name)
Starts the context with the given name.void
stop(String name)
Stops the context with the given name.void
unbindFromContext(org.apache.catalina.Context context)
Unbinds a naming context from the current thread's classloader.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface psiprobe.TomcatContainer
addContextResource, addContextResourceLink, canBoundTo, getApplicationFilterMaps, getApplicationFilters, getApplicationInitParams, getResourceAttributes, getResourceStream, resourceExists
-
-
-
-
Field Detail
-
logger
protected final org.slf4j.Logger logger
The logger.
-
NO_JSP_SERVLET
private static final String NO_JSP_SERVLET
The Constant NO_JSP_SERVLET.- See Also:
- Constant Field Values
-
host
protected org.apache.catalina.Host host
The host.
-
connectors
protected org.apache.catalina.connector.Connector[] connectors
The connectors.
-
deployerOName
protected ObjectName deployerOName
The deployer o name.
-
mbeanServer
protected MBeanServer mbeanServer
The mbean server.
-
-
Method Detail
-
setWrapper
public void setWrapper(org.apache.catalina.Wrapper wrapper)
Description copied from interface:TomcatContainer
Sets the wrapper.- Specified by:
setWrapper
in interfaceTomcatContainer
- Parameters:
wrapper
- the new wrapper
-
getAppBase
public File getAppBase()
Description copied from interface:TomcatContainer
This method always returns absolute path, no matter what Tomcat is up to.- Specified by:
getAppBase
in interfaceTomcatContainer
- Returns:
- absolute path to applications base (normally "webapps")
-
getConfigBase
public String getConfigBase()
Description copied from interface:TomcatContainer
Gets the config base.- Specified by:
getConfigBase
in interfaceTomcatContainer
- Returns:
- the config base
-
getHostName
public String getHostName()
Description copied from interface:TomcatContainer
Gets the host name.- Specified by:
getHostName
in interfaceTomcatContainer
- Returns:
- the host name
-
getName
public String getName()
Description copied from interface:TomcatContainer
Gets the name.- Specified by:
getName
in interfaceTomcatContainer
- Returns:
- the name
-
findContexts
public List<org.apache.catalina.Context> findContexts()
Description copied from interface:TomcatContainer
Find contexts.- Specified by:
findContexts
in interfaceTomcatContainer
- Returns:
- all contexts
-
findConnectors
public List<org.apache.catalina.connector.Connector> findConnectors()
Description copied from interface:TomcatContainer
Find connectors.- Specified by:
findConnectors
in interfaceTomcatContainer
- Returns:
- all connectors
-
installContext
public boolean installContext(String contextName) throws Exception
Description copied from interface:TomcatContainer
Deploys a context, assuming an context descriptor file exists on the server already.- Specified by:
installContext
in interfaceTomcatContainer
- Parameters:
contextName
- the context path, which should match the filename- Returns:
true
if deployment was successful- Throws:
Exception
- if deployment fails spectacularly
-
stop
public void stop(String name) throws Exception
Description copied from interface:TomcatContainer
Stops the context with the given name.- Specified by:
stop
in interfaceTomcatContainer
- Parameters:
name
- the name of the context to stop- Throws:
Exception
- if stopping the context fails spectacularly
-
start
public void start(String name) throws Exception
Description copied from interface:TomcatContainer
Starts the context with the given name.- Specified by:
start
in interfaceTomcatContainer
- Parameters:
name
- the name of the context to start- Throws:
Exception
- if starting the context fails spectacularly
-
remove
public void remove(String name) throws Exception
Description copied from interface:TomcatContainer
Undeploys a context.- Specified by:
remove
in interfaceTomcatContainer
- Parameters:
name
- the context path- Throws:
Exception
- if undeployment fails spectacularly
-
removeInternal
private void removeInternal(String name) throws Exception
Removes the internal.- Parameters:
name
- the name- Throws:
Exception
- the exception
-
installWar
public void installWar(String name, URL url) throws Exception
Description copied from interface:TomcatContainer
Installs .war file at the given context name.- Specified by:
installWar
in interfaceTomcatContainer
- Parameters:
name
- the name of the contexturl
- pointer to .war file to be deployed- Throws:
Exception
- if installing the .war fails spectacularly
-
installContextInternal
private void installContextInternal(String name) throws Exception
Install context internal.- Parameters:
name
- the name- Throws:
Exception
- the exception
-
findContext
public org.apache.catalina.Context findContext(String name)
Description copied from interface:TomcatContainer
Finds a context based on its path.- Specified by:
findContext
in interfaceTomcatContainer
- Parameters:
name
- the context path- Returns:
- the context deployed to that path
-
formatContextName
public String formatContextName(String name)
Description copied from interface:TomcatContainer
Formats a context name to a path that the container will recognize. Usually this means prepending a/
character, although there is special behavior for the root context.- Specified by:
formatContextName
in interfaceTomcatContainer
- Parameters:
name
- the context name- Returns:
- the context name formatted as the container expects
-
formatContextFilename
public String formatContextFilename(String contextName)
Description copied from interface:TomcatContainer
Formats a context name so that it can be used as a step for the context descriptor .xml or deployed .war file. Usually this means stripping a leading/
character, although there is special behavior for the root context.- Specified by:
formatContextFilename
in interfaceTomcatContainer
- Parameters:
contextName
- the context name- Returns:
- the filename stem for this context
-
discardWorkDir
public void discardWorkDir(org.apache.catalina.Context context)
Description copied from interface:TomcatContainer
Deletes the "work" directory of the given context.- Specified by:
discardWorkDir
in interfaceTomcatContainer
- Parameters:
context
- the context
-
getServletFileNameForJsp
public String getServletFileNameForJsp(org.apache.catalina.Context context, String jspName)
Description copied from interface:TomcatContainer
Returns the JSP servlet filename for the given JSP file.- Specified by:
getServletFileNameForJsp
in interfaceTomcatContainer
- Parameters:
context
- the contextjspName
- the JSP filename- Returns:
- the name of the JSP servlet
-
recompileJsps
public void recompileJsps(org.apache.catalina.Context context, Summary summary, List<String> names)
Description copied from interface:TomcatContainer
Compiles a list of JSPs. Names of JSP files are expected to be relative to the webapp root. The method updates summary with compilation details.- Specified by:
recompileJsps
in interfaceTomcatContainer
- Parameters:
context
- the contextsummary
- the summary in which the output is storednames
- the list of JSPs to compile
-
listContextJsps
public void listContextJsps(org.apache.catalina.Context context, Summary summary, boolean compile)
Description copied from interface:TomcatContainer
Lists and optionally compiles all JSPs for the given context. Compilation details are added to the summary.- Specified by:
listContextJsps
in interfaceTomcatContainer
- Parameters:
context
- the contextsummary
- the summary in which the output is storedcompile
- whether to compile all of the JSPs or not
-
getAvailable
public boolean getAvailable(org.apache.catalina.Context context)
Description copied from interface:TomcatContainer
Gets the available.- Specified by:
getAvailable
in interfaceTomcatContainer
- Parameters:
context
- the context- Returns:
- the available
-
getConfigFile
public File getConfigFile(org.apache.catalina.Context context)
Description copied from interface:TomcatContainer
Returns the context descriptor filename for the given context.- Specified by:
getConfigFile
in interfaceTomcatContainer
- Parameters:
context
- the context- Returns:
- the context descriptor filename, or
null
-
bindToContext
public void bindToContext(org.apache.catalina.Context context) throws NamingException
Description copied from interface:TomcatContainer
Binds a naming context to the current thread's classloader.- Specified by:
bindToContext
in interfaceTomcatContainer
- Parameters:
context
- the catalina context- Throws:
NamingException
- if binding the classloader fails
-
unbindFromContext
public void unbindFromContext(org.apache.catalina.Context context) throws NamingException
Description copied from interface:TomcatContainer
Unbinds a naming context from the current thread's classloader.- Specified by:
unbindFromContext
in interfaceTomcatContainer
- Parameters:
context
- the catalina context- Throws:
NamingException
- if unbinding the classloader fails
-
registerGlobalResourceAccess
protected void registerGlobalResourceAccess(org.apache.tomcat.util.descriptor.web.ContextResourceLink resourceLink)
Register access to global resources.- Parameters:
resourceLink
- the resource link
-
changeContextBinding
private void changeContextBinding(org.apache.catalina.Context context, boolean bind) throws NamingException
Change context binding.- Parameters:
context
- the contextbind
- the bind- Throws:
NamingException
- the naming exception
-
compileItem
protected void compileItem(String jspName, org.apache.jasper.Options opt, org.apache.catalina.Context ctx, org.apache.jasper.compiler.JspRuntimeContext jrctx, Summary summary, URLClassLoader classLoader, int level, boolean compile)
Lists and optionally compiles a directory recursively.- Parameters:
jspName
- name of JSP file or directory to be listed and compiled.opt
- the JSP compiler optionsctx
- the contextjrctx
- the runtime context used to create the compilation contextsummary
- the summary in which the output is storedclassLoader
- the classloader used by the compilerlevel
- the depth in the tree at which the item was encounteredcompile
- whether or not to compile the item or just to check whether it's out of date
-
findContextInternal
protected org.apache.catalina.Context findContextInternal(String name)
Find context internal.- Parameters:
name
- the context name- Returns:
- the context
-
checkChanges
protected void checkChanges(String name) throws Exception
Check changes.- Parameters:
name
- the name- Throws:
Exception
- the exception
-
getNamingToken
protected abstract Object getNamingToken(org.apache.catalina.Context context)
Returns the security token required to bind to a naming context.- Parameters:
context
- the catalina context- Returns:
- the security token for use with
ContextBindings
-
createJspCompilationContext
protected abstract org.apache.jasper.JspCompilationContext createJspCompilationContext(String name, org.apache.jasper.Options opt, javax.servlet.ServletContext sctx, org.apache.jasper.compiler.JspRuntimeContext jrctx, ClassLoader classLoader)
Creates the jsp compilation context.- Parameters:
name
- the nameopt
- the optsctx
- the sctxjrctx
- the jrctxclassLoader
- the class loader- Returns:
- the jsp compilation context
-
createValve
protected abstract org.apache.catalina.Valve createValve()
Creates the valve.- Returns:
- the valve
-
addFilterMapping
protected void addFilterMapping(String filterName, String dispatcherMap, String filterClass, String[] types, List<FilterMapping> results, AbstractTomcatContainer.FilterMapType filterMapType)
Adds the filter mapping.- Parameters:
filterName
- the filter namedispatcherMap
- the dispatcher mapfilterClass
- the filter classtypes
- the types as urls or servlet nameresults
- the resultsfilterMapType
- the filter map type
-
-