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<Servlet>
-
- org.eclipse.jetty.servlet.ServletHolder
-
- All Implemented Interfaces:
Comparable<ServletHolder>,org.eclipse.jetty.server.UserIdentity.Scope,org.eclipse.jetty.util.component.Dumpable,org.eclipse.jetty.util.component.LifeCycle
@ManagedObject("Servlet Holder") public class ServletHolder extends Holder<Servlet> implements org.eclipse.jetty.server.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
Nested Classes Modifier and Type Class Description protected classServletHolder.Configstatic classServletHolder.JspContainerclassServletHolder.Registration-
Nested classes/interfaces inherited from class org.eclipse.jetty.servlet.Holder
Holder.HolderConfig, Holder.HolderRegistration
-
-
Field Summary
Fields Modifier and Type Field Description static StringAPACHE_SENTINEL_CLASSstatic StringJSP_GENERATED_PACKAGE_NAMEstatic Map<String,String>NO_MAPPED_ROLES-
Fields inherited from class org.eclipse.jetty.servlet.Holder
_asyncSupported, _displayName, _initialized, _initParams, _name
-
Fields inherited from class org.eclipse.jetty.servlet.BaseHolder
_class, _className, _extInstance, _servletHandler, _source
-
-
Constructor Summary
Constructors Constructor Description ServletHolder()Constructor .ServletHolder(Class<? extends Servlet> servlet)Constructor for servlet class.ServletHolder(String name, Class<? extends Servlet> servlet)Constructor for servlet class.ServletHolder(String name, Servlet servlet)Constructor for servlet class.ServletHolder(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 voidappendPath(StringBuffer path, String element)Concatenate an element on to fully qualified classname.voidcheckServletType()Check to ensure class of servlet is acceptable.intcompareTo(ServletHolder sh)Comparator by init order.voiddestroyInstance(Object o)voiddoStart()voiddoStop()voiddump(Appendable out, String indent)ServletensureInstance()Deprecated.booleanequals(Object o)StringgetClassNameForJsp(String jsp)StringgetContextPath()StringgetForcedPath()intgetInitOrder()StringgetJspPackagePrefix()StringgetNameOfJspClass(String jsp)StringgetPackageOfJspClass(String jsp)ServletRegistration.DynamicgetRegistration()Map<String,String>getRoleRefMap()StringgetRunAsRole()ServletgetServlet()Get the servlet.ServletgetServletInstance()Get the servlet instance (no initialization done).UnavailableExceptiongetUnavailableException()StringgetUserRoleLink(String name)get a user role link.voidhandle(org.eclipse.jetty.server.Request baseRequest, ServletRequest request, ServletResponse response)Service a request with this servlet.inthashCode()voidinitialize()Do any setup necessary after startingprotected voidinitJspServlet()protected voidinitMultiPart()Register a ServletRequestListener that will ensure tmp multipart files are deleted when the request goes out of scope.booleanisAvailable()booleanisEnabled()protected booleanisJspServlet()protected booleanisJspServlet(String classname)protected ServletnewInstance()protected voidprepare(org.eclipse.jetty.server.Request baseRequest, ServletRequest request, ServletResponse response)Prepare to service a request.voidsetEnabled(boolean enabled)voidsetForcedPath(String forcedPath)voidsetInitOrder(int order)Set the initialize order.voidsetRunAsRole(String role)voidsetServlet(Servlet servlet)voidsetUserRoleLink(String name, String link)Link a user role.StringtoString()-
Methods inherited from class org.eclipse.jetty.servlet.Holder
dump, getDisplayName, getInitParameter, getInitParameterNames, getInitParameters, getName, isAsyncSupported, setAsyncSupported, setClassName, setDisplayName, setHeldClass, setInitParameter, setInitParameters, setName
-
Methods inherited from class org.eclipse.jetty.servlet.BaseHolder
getClassName, getHeldClass, getServletHandler, getSource, illegalStateIfContextStarted, isInstance, setServletHandler
-
Methods inherited from class org.eclipse.jetty.util.component.AbstractLifeCycle
addLifeCycleListener, getState, getState, getStopTimeout, isFailed, isRunning, isStarted, isStarting, isStopped, isStopping, removeLifeCycleListener, setStopTimeout, start, stop
-
-
-
-
Field Detail
-
APACHE_SENTINEL_CLASS
public static final String APACHE_SENTINEL_CLASS
- See Also:
- Constant Field Values
-
JSP_GENERATED_PACKAGE_NAME
public static final 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(Servlet servlet)
Constructor for existing servlet.- Parameters:
servlet- the servlet
-
ServletHolder
public ServletHolder(String name, Class<? extends Servlet> servlet)
Constructor for servlet class.- Parameters:
name- the name of the servletservlet- the servlet class
-
ServletHolder
public ServletHolder(String name, Servlet servlet)
Constructor for servlet class.- Parameters:
name- the servlet nameservlet- the servlet
-
-
Method Detail
-
getUnavailableException
public UnavailableException getUnavailableException()
- Returns:
- The unavailable exception or null if not unavailable
-
setServlet
public void setServlet(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:
compareToin interfaceComparable<ServletHolder>
-
setUserRoleLink
public void setUserRoleLink(String name, 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 String getUserRoleLink(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 String getForcedPath()- Returns:
- Returns the forcedPath.
-
setForcedPath
public void setForcedPath(String forcedPath)
- Parameters:
forcedPath- The forcedPath to set.
-
isEnabled
public boolean isEnabled()
-
setEnabled
public void setEnabled(boolean enabled)
-
doStart
public void doStart() throws Exception- Overrides:
doStartin classBaseHolder<Servlet>- Throws:
Exception
-
initialize
public void initialize() throws ExceptionDescription copied from class:BaseHolderDo any setup necessary after starting- Overrides:
initializein classBaseHolder<Servlet>- Throws:
Exception- if unable to initialize
-
doStop
public void doStop() throws Exception- Overrides:
doStopin classBaseHolder<Servlet>- Throws:
Exception
-
destroyInstance
public void destroyInstance(Object o) throws Exception
- Overrides:
destroyInstancein classHolder<Servlet>- Throws:
Exception
-
getServlet
public Servlet getServlet() throws ServletException
Get the servlet.- Returns:
- The servlet
- Throws:
ServletException- if unable to init the servlet on first use
-
getServletInstance
public Servlet getServletInstance()
Get the servlet instance (no initialization done).- Returns:
- The servlet or null
-
checkServletType
public void checkServletType() throws UnavailableExceptionCheck to ensure class of servlet is acceptable.- Throws:
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 Exception- Throws:
Exception- if unable to init the JSP Servlet
-
initMultiPart
protected void initMultiPart() throws ExceptionRegister a ServletRequestListener that will ensure tmp multipart files are deleted when the request goes out of scope.- Throws:
Exception- if unable to init the multipart
-
getContextPath
public String getContextPath()
- Specified by:
getContextPathin interfaceorg.eclipse.jetty.server.UserIdentity.Scope- See Also:
UserIdentity.Scope.getContextPath()
-
getRoleRefMap
public Map<String,String> getRoleRefMap()
- Specified by:
getRoleRefMapin interfaceorg.eclipse.jetty.server.UserIdentity.Scope- See Also:
UserIdentity.Scope.getRoleRefMap()
-
getRunAsRole
@ManagedAttribute(value="role to run servlet as", readonly=true) public String getRunAsRole()
-
setRunAsRole
public void setRunAsRole(String role)
-
prepare
protected void prepare(org.eclipse.jetty.server.Request baseRequest, ServletRequest request, ServletResponse response) throws ServletException, UnavailableExceptionPrepare to service a request.- Parameters:
baseRequest- the base requestrequest- the requestresponse- the response- Throws:
ServletException- if unable to prepare the servletUnavailableException- if not available
-
ensureInstance
@Deprecated public Servlet ensureInstance() throws ServletException, UnavailableException
Deprecated.- Throws:
ServletExceptionUnavailableException
-
handle
public void handle(org.eclipse.jetty.server.Request baseRequest, ServletRequest request, ServletResponse response) throws ServletException, UnavailableException, IOExceptionService a request with this servlet.- Parameters:
baseRequest- the base requestrequest- the requestresponse- the response- Throws:
ServletException- if unable to process the servletUnavailableException- if servlet is unavailableIOException- if unable to process the request or response
-
isJspServlet
protected boolean isJspServlet()
-
isJspServlet
protected boolean isJspServlet(String classname)
-
getNameOfJspClass
public String getNameOfJspClass(String jsp)
- Parameters:
jsp- the jsp-file- Returns:
- the simple classname of the jsp
-
getJspPackagePrefix
public String getJspPackagePrefix()
- Returns:
- the package for all jsps
-
getClassNameForJsp
public String getClassNameForJsp(String jsp)
- Parameters:
jsp- the jsp-file from web.xml- Returns:
- the fully qualified classname
-
appendPath
protected void appendPath(StringBuffer path, 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 ServletRegistration.Dynamic getRegistration()
-
newInstance
protected Servlet newInstance() throws ServletException, IllegalAccessException, InstantiationException, NoSuchMethodException, InvocationTargetException
- Returns:
- the newly created Servlet instance
- Throws:
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 exception
-
dump
public void dump(Appendable out, String indent) throws IOException
- Specified by:
dumpin interfaceorg.eclipse.jetty.util.component.Dumpable- Overrides:
dumpin classBaseHolder<Servlet>- Throws:
IOException
-
-