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:
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, 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
Modifier and TypeClassDescriptionprotected class
static enum
class
static interface
Experimental Wrapper mechanism for Servlet objects.static class
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, AbstractLifeCycle.StopException
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
-
Constructor Summary
ConstructorDescriptionConstructor .ServletHolder
(Class<? extends javax.servlet.Servlet> servlet) Constructor for servlet class.ServletHolder
(String name, Class<? extends javax.servlet.Servlet> servlet) Constructor for servlet class.ServletHolder
(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
Modifier and TypeMethodDescriptionprotected void
appendPath
(StringBuffer path, String element) Concatenate an element on to fully qualified classname.void
Check to ensure class of servlet is acceptable.int
Comparator by init order.protected javax.servlet.Servlet
void
void
doStart()
Method to override to start the lifecyclevoid
doStop()
Method to override to stop the lifecyclevoid
dump
(Appendable out, String indent) Dump this object (and children) into an Appendable using the provided indent after any new lines.boolean
getClassNameForJsp
(String jsp) int
getNameOfJspClass
(String jsp) javax.servlet.ServletRegistration.Dynamic
javax.servlet.Servlet
Get the servlet.javax.servlet.Servlet
Get the servlet instance (no initialization done).javax.servlet.UnavailableException
getUserRoleLink
(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
Do any setup necessary after startingprotected void
boolean
boolean
protected boolean
protected boolean
isJspServlet
(String classname) protected javax.servlet.Servlet
protected void
prepare
(Request baseRequest, javax.servlet.ServletRequest request, javax.servlet.ServletResponse response) Prepare to service a request.void
setEnabled
(boolean enabled) void
setForcedPath
(String forcedPath) void
setInitOrder
(int order) Set the initialize order.void
setRunAsRole
(String role) void
setServlet
(javax.servlet.Servlet servlet) void
setUserRoleLink
(String name, String link) Link a user role.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, getServletContext, getServletHandler, getSource, illegalStateIfContextStarted, isInstance, setServletHandler, unwrap, wrap
Methods inherited from class org.eclipse.jetty.util.component.AbstractLifeCycle
addEventListener, getEventListeners, getState, getState, isFailed, isRunning, isStarted, isStarting, isStopped, isStopping, removeEventListener, setEventListeners, 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 Details
-
APACHE_SENTINEL_CLASS
- See Also:
-
JSP_GENERATED_PACKAGE_NAME
- See Also:
-
-
Constructor Details
-
ServletHolder
public ServletHolder()Constructor . -
ServletHolder
Constructor .- Parameters:
creator
- the holder source
-
ServletHolder
public ServletHolder(javax.servlet.Servlet servlet) Constructor for existing servlet.- Parameters:
servlet
- the servlet
-
ServletHolder
Constructor for servlet class.- Parameters:
name
- the name of the servletservlet
- the servlet class
-
ServletHolder
Constructor for servlet class.- Parameters:
name
- the servlet nameservlet
- the servlet
-
ServletHolder
Constructor for servlet class.- Parameters:
servlet
- the servlet class
-
-
Method Details
-
setServlet
public void setServlet(javax.servlet.Servlet servlet) -
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
Comparator by init order.- Specified by:
compareTo
in interfaceComparable<ServletHolder>
-
equals
-
hashCode
public int hashCode() -
setUserRoleLink
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
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
- Returns:
- Returns the forcedPath.
-
setForcedPath
- Parameters:
forcedPath
- The forcedPath to set.
-
isEnabled
public boolean isEnabled() -
setEnabled
public void setEnabled(boolean enabled) -
doStart
Description copied from class:AbstractLifeCycle
Method to override to start the lifecycle- Overrides:
doStart
in classBaseHolder<javax.servlet.Servlet>
- Throws:
AbstractLifeCycle.StopException
- If thrown, the lifecycle will immediately be stopped.Exception
- If there was a problem starting. Will cause a transition to FAILED state
-
initialize
Description copied from class:BaseHolder
Do any setup necessary after starting- Overrides:
initialize
in classBaseHolder<javax.servlet.Servlet>
- Throws:
Exception
- if unable to initialize
-
doStop
Description copied from class:AbstractLifeCycle
Method to override to stop the lifecycle- Overrides:
doStop
in classBaseHolder<javax.servlet.Servlet>
- Throws:
Exception
- If there was a problem stopping. Will cause a transition to FAILED state
-
destroyInstance
- Overrides:
destroyInstance
in classHolder<javax.servlet.Servlet>
-
getServlet
public javax.servlet.Servlet getServlet() throws javax.servlet.ServletExceptionGet 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.UnavailableExceptionCheck 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
- Throws:
Exception
- if unable to init the JSP Servlet
-
getContextHandler
- Specified by:
getContextHandler
in interfaceUserIdentity.Scope
- Returns:
- The context handler that the identity is being considered within
-
getContextPath
- Specified by:
getContextPath
in interfaceUserIdentity.Scope
- Returns:
- The context path that the identity is being considered within
-
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.
-
getRunAsRole
-
setRunAsRole
-
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
-
handle
public void handle(Request baseRequest, javax.servlet.ServletRequest request, javax.servlet.ServletResponse response) throws javax.servlet.ServletException, javax.servlet.UnavailableException, 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 unavailableIOException
- if unable to process the request or response
-
isJspServlet
protected boolean isJspServlet() -
isJspServlet
-
getNameOfJspClass
- Parameters:
jsp
- the jsp-file- Returns:
- the simple classname of the jsp
-
getPackageOfJspClass
-
getJspPackagePrefix
- Returns:
- the package for all jsps
-
getClassNameForJsp
- Parameters:
jsp
- the jsp-file from web.xml- Returns:
- the fully qualified classname
-
appendPath
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
- Returns:
- the newly created Servlet instance
- Throws:
javax.servlet.ServletException
- if unable to create a new instanceIllegalAccessException
- if not allowed to create a new instanceInstantiationException
- if creating new instance resulted in errorNoSuchMethodException
- if creating new instance resulted in errorInvocationTargetException
- If creating new instance throws an exceptionException
-
createInstance
- Overrides:
createInstance
in classBaseHolder<javax.servlet.Servlet>
- Throws:
Exception
-
dump
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:
IOException
- if unable to write to Appendable
-
toString