Package org.kohsuke.stapler
Class Stapler
- java.lang.Object
-
- javax.servlet.GenericServlet
-
- javax.servlet.http.HttpServlet
-
- org.kohsuke.stapler.Stapler
-
- All Implemented Interfaces:
Serializable
,javax.servlet.Servlet
,javax.servlet.ServletConfig
public class Stapler extends javax.servlet.http.HttpServlet
Maps an HTTP request to a method call / JSP invocation against a model object by evaluating the request URL in a EL-ish way.This servlet should be used as the default servlet.
- Author:
- Kohsuke Kawaguchi
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description static org.apache.commons.beanutils.ConvertUtilsBean
CONVERT_UTILS
This is theConverter
registry that Stapler uses, primarily for form-to-JSON binding inStaplerRequest.bindJSON(Class, JSONObject)
and its family of methods.
-
Constructor Summary
Constructors Constructor Description Stapler()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description void
buildResourcePaths()
Rebuild the internal cache for static resources.static String
escape(String v)
Escapes HTML/XML unsafe characters for the PCDATA section.void
forward(javax.servlet.RequestDispatcher dispatcher, StaplerRequest req, javax.servlet.http.HttpServletResponse rsp)
ClassLoader
getClassLoader()
Deprecated.static ClassLoader
getClassLoader(javax.servlet.ServletContext context)
Deprecated.static Stapler
getCurrent()
Gets the currentStapler
that the calling thread is associated with.static StaplerRequest
getCurrentRequest()
Gets the currentStaplerRequest
that the calling thread is associated with.static StaplerResponse
getCurrentResponse()
Gets the currentStaplerResponse
that the calling thread is associated with.static String
getViewURL(Class clazz, String jspName)
Gets the URL (e.g., "/WEB-INF/side-files/fully/qualified/class/name/jspName") from a class and the JSP name.WebApp
getWebApp()
static Object
htmlSafeArgument(Object o)
For XSS prevention, escape unsafe characters in String by default, unless it's specifically wrapped inRawHtmlArgument
.static Object[]
htmlSafeArguments(Object[] args)
void
init(javax.servlet.ServletConfig servletConfig)
void
invoke(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse rsp, Object root, String url)
Performs stapler processing on the given root object and request URL.static boolean
isSocketException(Throwable x)
Used to detect exceptions thrown when writing content that seem to be due merely to a closed socket.static org.apache.commons.beanutils.Converter
lookupConverter(Class type)
protected void
service(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse rsp)
static void
setClassLoader(javax.servlet.ServletContext context, ClassLoader classLoader)
Deprecated.static void
setRoot(javax.servlet.ServletContextEvent event, Object rootApp)
Sets the specified object as the root of the web application.-
Methods inherited from class javax.servlet.http.HttpServlet
doDelete, doGet, doHead, doOptions, doPost, doPut, doTrace, getLastModified, service
-
-
-
-
Field Detail
-
CONVERT_UTILS
public static final org.apache.commons.beanutils.ConvertUtilsBean CONVERT_UTILS
This is theConverter
registry that Stapler uses, primarily for form-to-JSON binding inStaplerRequest.bindJSON(Class, JSONObject)
and its family of methods.
-
-
Method Detail
-
init
public void init(javax.servlet.ServletConfig servletConfig) throws javax.servlet.ServletException
- Specified by:
init
in interfacejavax.servlet.Servlet
- Overrides:
init
in classjavax.servlet.GenericServlet
- Throws:
javax.servlet.ServletException
-
buildResourcePaths
public void buildResourcePaths()
Rebuild the internal cache for static resources.
-
getWebApp
public WebApp getWebApp()
-
service
protected void service(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse rsp) throws javax.servlet.ServletException, IOException
- Overrides:
service
in classjavax.servlet.http.HttpServlet
- Throws:
javax.servlet.ServletException
IOException
-
invoke
public void invoke(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse rsp, Object root, String url) throws IOException, javax.servlet.ServletException
Performs stapler processing on the given root object and request URL.- Throws:
IOException
javax.servlet.ServletException
-
isSocketException
public static boolean isSocketException(Throwable x)
Used to detect exceptions thrown when writing content that seem to be due merely to a closed socket.- Parameters:
x
- an exception that got caught- Returns:
- true if this looks like a closed stream, false for some real problem
- Since:
- 1.222
-
forward
public void forward(javax.servlet.RequestDispatcher dispatcher, StaplerRequest req, javax.servlet.http.HttpServletResponse rsp) throws javax.servlet.ServletException, IOException
- Throws:
javax.servlet.ServletException
IOException
-
getViewURL
public static String getViewURL(Class clazz, String jspName)
Gets the URL (e.g., "/WEB-INF/side-files/fully/qualified/class/name/jspName") from a class and the JSP name.
-
setRoot
public static void setRoot(javax.servlet.ServletContextEvent event, Object rootApp)
Sets the specified object as the root of the web application.This method should be invoked from your implementation of
ServletContextListener.contextInitialized(ServletContextEvent)
.This is just a convenience method to invoke
servletContext.setAttribute("app",rootApp)
.The root object is bound to the URL '/' and used to resolve all the requests to this web application.
-
setClassLoader
@Deprecated public static void setClassLoader(javax.servlet.ServletContext context, ClassLoader classLoader)
Deprecated.Sets the classloader used byStaplerRequest.bindJSON(Class, JSONObject)
and its sibling methods.
-
getClassLoader
@Deprecated public static ClassLoader getClassLoader(javax.servlet.ServletContext context)
Deprecated.
-
getClassLoader
@Deprecated public ClassLoader getClassLoader()
Deprecated.
-
getCurrentRequest
public static StaplerRequest getCurrentRequest()
Gets the currentStaplerRequest
that the calling thread is associated with.
-
getCurrentResponse
public static StaplerResponse getCurrentResponse()
Gets the currentStaplerResponse
that the calling thread is associated with.
-
getCurrent
public static Stapler getCurrent()
Gets the currentStapler
that the calling thread is associated with.
-
lookupConverter
public static org.apache.commons.beanutils.Converter lookupConverter(Class type)
-
escape
public static String escape(String v)
Escapes HTML/XML unsafe characters for the PCDATA section. This method does not handle whitespace-preserving escape, nor attribute escapes.
-
htmlSafeArgument
public static Object htmlSafeArgument(Object o)
For XSS prevention, escape unsafe characters in String by default, unless it's specifically wrapped inRawHtmlArgument
.
-
-