Package org.eclipse.jetty.servlet
Class ServletHolder
- java.lang.Object
-
- org.eclipse.jetty.util.component.AbstractLifeCycle
-
- org.eclipse.jetty.servlet.BaseHolder<T>
-
- org.eclipse.jetty.servlet.Holder<javax.servlet.Servlet>
-
- org.eclipse.jetty.servlet.ServletHolder
-
- All Implemented Interfaces:
java.lang.Comparable<ServletHolder>
,UserIdentity.Scope
,Dumpable
,LifeCycle
- Direct Known Subclasses:
AntWebAppContext.AntServletHolder
@ManagedObject("Servlet Holder") public class ServletHolder extends Holder<javax.servlet.Servlet> implements UserIdentity.Scope, java.lang.Comparable<ServletHolder>
Servlet Instance and Context Holder.Holds the name, params and some state of a javax.servlet.Servlet instance. It implements the ServletConfig interface. This class will organise the loading of the servlet when needed or requested.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected class
ServletHolder.Config
static class
ServletHolder.JspContainer
class
ServletHolder.Registration
static interface
ServletHolder.WrapFunction
Experimental Wrapper mechanism for Servlet objects.static class
ServletHolder.Wrapper
-
Nested classes/interfaces inherited from class org.eclipse.jetty.servlet.Holder
Holder.HolderConfig, Holder.HolderRegistration
-
Nested classes/interfaces inherited from class org.eclipse.jetty.util.component.AbstractLifeCycle
AbstractLifeCycle.AbstractLifeCycleListener
-
Nested classes/interfaces inherited from interface org.eclipse.jetty.util.component.Dumpable
Dumpable.DumpableContainer
-
Nested classes/interfaces inherited from interface org.eclipse.jetty.util.component.LifeCycle
LifeCycle.Listener
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
APACHE_SENTINEL_CLASS
static java.lang.String
JSP_GENERATED_PACKAGE_NAME
-
Constructor Summary
Constructors Constructor Description ServletHolder()
Constructor .ServletHolder(java.lang.Class<? extends javax.servlet.Servlet> servlet)
Constructor for servlet class.ServletHolder(java.lang.String name, java.lang.Class<? extends javax.servlet.Servlet> servlet)
Constructor for servlet class.ServletHolder(java.lang.String name, javax.servlet.Servlet servlet)
Constructor for servlet class.ServletHolder(javax.servlet.Servlet servlet)
Constructor for existing servlet.ServletHolder(Source creator)
Constructor .
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description protected void
appendPath(java.lang.StringBuffer path, java.lang.String element)
Concatenate an element on to fully qualified classname.void
checkServletType()
Check to ensure class of servlet is acceptable.int
compareTo(ServletHolder sh)
Comparator by init order.void
destroyInstance(java.lang.Object o)
void
doStart()
void
doStop()
void
dump(java.lang.Appendable out, java.lang.String indent)
Dump this object (and children) into an Appendable using the provided indent after any new lines.javax.servlet.Servlet
ensureInstance()
Deprecated.boolean
equals(java.lang.Object o)
java.lang.String
getClassNameForJsp(java.lang.String jsp)
ContextHandler
getContextHandler()
java.lang.String
getContextPath()
java.lang.String
getForcedPath()
int
getInitOrder()
java.lang.String
getJspPackagePrefix()
java.lang.String
getNameOfJspClass(java.lang.String jsp)
java.lang.String
getPackageOfJspClass(java.lang.String jsp)
javax.servlet.ServletRegistration.Dynamic
getRegistration()
java.util.Map<java.lang.String,java.lang.String>
getRoleRefMap()
java.lang.String
getRunAsRole()
javax.servlet.Servlet
getServlet()
Get the servlet.javax.servlet.Servlet
getServletInstance()
Get the servlet instance (no initialization done).javax.servlet.UnavailableException
getUnavailableException()
java.lang.String
getUserRoleLink(java.lang.String name)
get a user role link.void
handle(Request baseRequest, javax.servlet.ServletRequest request, javax.servlet.ServletResponse response)
Service a request with this servlet.int
hashCode()
void
initialize()
Do any setup necessary after startingprotected void
initJspServlet()
protected void
initMultiPart()
Register a ServletRequestListener that will ensure tmp multipart files are deleted when the request goes out of scope.boolean
isAvailable()
boolean
isEnabled()
protected boolean
isJspServlet()
protected boolean
isJspServlet(java.lang.String classname)
protected javax.servlet.Servlet
newInstance()
protected void
prepare(Request baseRequest, javax.servlet.ServletRequest request, javax.servlet.ServletResponse response)
Prepare to service a request.void
setEnabled(boolean enabled)
void
setForcedPath(java.lang.String forcedPath)
void
setInitOrder(int order)
Set the initialize order.void
setRunAsRole(java.lang.String role)
void
setServlet(javax.servlet.Servlet servlet)
void
setUserRoleLink(java.lang.String name, java.lang.String link)
Link a user role.java.lang.String
toString()
-
Methods inherited from class org.eclipse.jetty.servlet.Holder
dump, getDisplayName, getInitParameter, getInitParameterNames, getInitParameters, getName, isAsyncSupported, setAsyncSupported, setClassName, setDisplayName, setHeldClass, setInitParameter, setInitParameters, setInstance, setName
-
Methods inherited from class org.eclipse.jetty.servlet.BaseHolder
getClassName, getHeldClass, getInstance, getServletHandler, getSource, illegalStateIfContextStarted, isInstance, setServletHandler, unwrap, wrap
-
Methods inherited from class org.eclipse.jetty.util.component.AbstractLifeCycle
addLifeCycleListener, getState, getState, getStopTimeout, isFailed, isRunning, isStarted, isStarting, isStopped, isStopping, removeLifeCycleListener, setStopTimeout, start, stop
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.eclipse.jetty.server.UserIdentity.Scope
getName
-
-
-
-
Field Detail
-
APACHE_SENTINEL_CLASS
public static final java.lang.String APACHE_SENTINEL_CLASS
- See Also:
- Constant Field Values
-
JSP_GENERATED_PACKAGE_NAME
public static final java.lang.String JSP_GENERATED_PACKAGE_NAME
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
ServletHolder
public ServletHolder()
Constructor .
-
ServletHolder
public ServletHolder(Source creator)
Constructor .- Parameters:
creator
- the holder source
-
ServletHolder
public ServletHolder(javax.servlet.Servlet servlet)
Constructor for existing servlet.- Parameters:
servlet
- the servlet
-
ServletHolder
public ServletHolder(java.lang.String name, java.lang.Class<? extends javax.servlet.Servlet> servlet)
Constructor for servlet class.- Parameters:
name
- the name of the servletservlet
- the servlet class
-
ServletHolder
public ServletHolder(java.lang.String name, javax.servlet.Servlet servlet)
Constructor for servlet class.- Parameters:
name
- the servlet nameservlet
- the servlet
-
ServletHolder
public ServletHolder(java.lang.Class<? extends javax.servlet.Servlet> servlet)
Constructor for servlet class.- Parameters:
servlet
- the servlet class
-
-
Method Detail
-
getUnavailableException
public javax.servlet.UnavailableException getUnavailableException()
- Returns:
- The unavailable exception or null if not unavailable
-
setServlet
public void setServlet(javax.servlet.Servlet servlet)
-
getInitOrder
@ManagedAttribute(value="initialization order", readonly=true) public int getInitOrder()
-
setInitOrder
public void setInitOrder(int order)
Set the initialize order.Holders with order<0, are initialized on use. Those with order>=0 are initialized in increasing order when the handler is started.
- Parameters:
order
- the servlet init order
-
compareTo
public int compareTo(ServletHolder sh)
Comparator by init order.- Specified by:
compareTo
in interfacejava.lang.Comparable<ServletHolder>
-
equals
public boolean equals(java.lang.Object o)
- Overrides:
equals
in classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
setUserRoleLink
public void setUserRoleLink(java.lang.String name, java.lang.String link)
Link a user role. Translate the role name used by a servlet, to the link name used by the container.- Parameters:
name
- The role name as used by the servletlink
- The role name as used by the container.
-
getUserRoleLink
public java.lang.String getUserRoleLink(java.lang.String name)
get a user role link.- Parameters:
name
- The name of the role- Returns:
- The name as translated by the link. If no link exists, the name is returned.
-
getForcedPath
@ManagedAttribute(value="forced servlet path", readonly=true) public java.lang.String getForcedPath()
- Returns:
- Returns the forcedPath.
-
setForcedPath
public void setForcedPath(java.lang.String forcedPath)
- Parameters:
forcedPath
- The forcedPath to set.
-
isEnabled
public boolean isEnabled()
-
setEnabled
public void setEnabled(boolean enabled)
-
doStart
public void doStart() throws java.lang.Exception
- Overrides:
doStart
in classBaseHolder<javax.servlet.Servlet>
- Throws:
java.lang.Exception
-
initialize
public void initialize() throws java.lang.Exception
Description copied from class:BaseHolder
Do any setup necessary after starting- Overrides:
initialize
in classBaseHolder<javax.servlet.Servlet>
- Throws:
java.lang.Exception
- if unable to initialize
-
doStop
public void doStop() throws java.lang.Exception
- Overrides:
doStop
in classBaseHolder<javax.servlet.Servlet>
- Throws:
java.lang.Exception
-
destroyInstance
public void destroyInstance(java.lang.Object o)
- Overrides:
destroyInstance
in classHolder<javax.servlet.Servlet>
-
getServlet
public javax.servlet.Servlet getServlet() throws javax.servlet.ServletException
Get the servlet.- Returns:
- The servlet
- Throws:
javax.servlet.ServletException
- if unable to init the servlet on first use
-
getServletInstance
public javax.servlet.Servlet getServletInstance()
Get the servlet instance (no initialization done).- Returns:
- The servlet or null
-
checkServletType
public void checkServletType() throws javax.servlet.UnavailableException
Check to ensure class of servlet is acceptable.- Throws:
javax.servlet.UnavailableException
- if Servlet class is not of typeServlet
-
isAvailable
public boolean isAvailable()
- Returns:
- true if the holder is started and is not unavailable
-
initJspServlet
protected void initJspServlet() throws java.lang.Exception
- Throws:
java.lang.Exception
- if unable to init the JSP Servlet
-
initMultiPart
protected void initMultiPart() throws java.lang.Exception
Register a ServletRequestListener that will ensure tmp multipart files are deleted when the request goes out of scope.- Throws:
java.lang.Exception
- if unable to init the multipart
-
getContextHandler
public ContextHandler getContextHandler()
- Specified by:
getContextHandler
in interfaceUserIdentity.Scope
- Returns:
- The context handler that the identity is being considered within
-
getContextPath
public java.lang.String getContextPath()
- Specified by:
getContextPath
in interfaceUserIdentity.Scope
- Returns:
- The context path that the identity is being considered within
- See Also:
UserIdentity.Scope.getContextPath()
-
getRoleRefMap
public java.util.Map<java.lang.String,java.lang.String> getRoleRefMap()
- Specified by:
getRoleRefMap
in interfaceUserIdentity.Scope
- Returns:
- A map of role reference names that converts from names used by application code to names used by the context deployment.
- See Also:
UserIdentity.Scope.getRoleRefMap()
-
getRunAsRole
@ManagedAttribute(value="role to run servlet as", readonly=true) public java.lang.String getRunAsRole()
-
setRunAsRole
public void setRunAsRole(java.lang.String role)
-
prepare
protected void prepare(Request baseRequest, javax.servlet.ServletRequest request, javax.servlet.ServletResponse response) throws javax.servlet.ServletException, javax.servlet.UnavailableException
Prepare to service a request.- Parameters:
baseRequest
- the base requestrequest
- the requestresponse
- the response- Throws:
javax.servlet.ServletException
- if unable to prepare the servletjavax.servlet.UnavailableException
- if not available
-
ensureInstance
@Deprecated public javax.servlet.Servlet ensureInstance() throws javax.servlet.ServletException
Deprecated.- Throws:
javax.servlet.ServletException
-
handle
public void handle(Request baseRequest, javax.servlet.ServletRequest request, javax.servlet.ServletResponse response) throws javax.servlet.ServletException, javax.servlet.UnavailableException, java.io.IOException
Service a request with this servlet.- Parameters:
baseRequest
- the base requestrequest
- the requestresponse
- the response- Throws:
javax.servlet.ServletException
- if unable to process the servletjavax.servlet.UnavailableException
- if servlet is unavailablejava.io.IOException
- if unable to process the request or response
-
isJspServlet
protected boolean isJspServlet()
-
isJspServlet
protected boolean isJspServlet(java.lang.String classname)
-
getNameOfJspClass
public java.lang.String getNameOfJspClass(java.lang.String jsp)
- Parameters:
jsp
- the jsp-file- Returns:
- the simple classname of the jsp
-
getPackageOfJspClass
public java.lang.String getPackageOfJspClass(java.lang.String jsp)
-
getJspPackagePrefix
public java.lang.String getJspPackagePrefix()
- Returns:
- the package for all jsps
-
getClassNameForJsp
public java.lang.String getClassNameForJsp(java.lang.String jsp)
- Parameters:
jsp
- the jsp-file from web.xml- Returns:
- the fully qualified classname
-
appendPath
protected void appendPath(java.lang.StringBuffer path, java.lang.String element)
Concatenate an element on to fully qualified classname.- Parameters:
path
- the path under constructionelement
- the element of the name to add
-
getRegistration
public javax.servlet.ServletRegistration.Dynamic getRegistration()
-
newInstance
protected javax.servlet.Servlet newInstance() throws javax.servlet.ServletException, java.lang.IllegalAccessException, java.lang.InstantiationException, java.lang.NoSuchMethodException, java.lang.reflect.InvocationTargetException
- Returns:
- the newly created Servlet instance
- Throws:
javax.servlet.ServletException
- if unable to create a new instancejava.lang.IllegalAccessException
- if not allowed to create a new instancejava.lang.InstantiationException
- if creating new instance resulted in errorjava.lang.NoSuchMethodException
- if creating new instance resulted in errorjava.lang.reflect.InvocationTargetException
- If creating new instance throws an exception
-
dump
public void dump(java.lang.Appendable out, java.lang.String indent) throws java.io.IOException
Description copied from interface:Dumpable
Dump this object (and children) into an Appendable using the provided indent after any new lines. The indent should not be applied to the first object dumped.- Specified by:
dump
in interfaceDumpable
- Overrides:
dump
in classBaseHolder<javax.servlet.Servlet>
- Parameters:
out
- The appendable to dump toindent
- The indent to apply after any new lines.- Throws:
java.io.IOException
- if unable to write to Appendable
-
-