Class RequestData
- java.lang.Object
-
- org.apache.sling.engine.impl.request.RequestData
-
public class RequestData extends Object
TheRequestDataclass provides access to objects which are set on a Servlet Request wide basis such as the repository session, the persistence manager, etc. The setup order is:- Invoke constructor
- Invoke initResource()
- Invoke initServlet()
- See Also:
ContentData
-
-
Field Summary
Fields Modifier and Type Field Description static intDEFAULT_MAX_CALL_COUNTERThe default value for the number of calls to theservice(SlingHttpServletRequest, SlingHttpServletResponse)method for a single instance of this class (value is 1000).static intDEFAULT_MAX_INCLUSION_COUNTERThe default value for the number of recursive inclusions for a single instance of this class (value is 50).static StringREQUEST_RESOURCE_PATH_ATTRThe name of the request attribute providing the resource addressed by the request URL.
-
Constructor Summary
Constructors Constructor Description RequestData(org.apache.sling.engine.impl.SlingRequestProcessorImpl slingRequestProcessor, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description <Type> TypeadaptTo(Object object, Class<Type> type)StringgetActiveServletName()Returns the name of the currently active servlet.static ArrayList<org.apache.sling.engine.impl.StaticResponseHeader>getAdditionalResponseHeaders()ContentDatagetContentData()longgetElapsedTimeMsec()javax.servlet.ServletInputStreamgetInputStream()static intgetMaxCallCounter()static intgetMaxIncludeCounter()StringgetMimeType(String fileName)ParameterSupportgetParameterSupport()intgetPeakRecusionDepth()BufferedReadergetReader()static RequestDatagetRequestData(javax.servlet.ServletRequest request)static RequestDatagetRequestData(org.apache.sling.api.SlingHttpServletRequest request)org.apache.sling.api.request.RequestProgressTrackergetRequestProgressTracker()org.apache.sling.api.resource.ResourceResolvergetResourceResolver()intgetServletCallCount()javax.servlet.http.HttpServletRequestgetServletRequest()javax.servlet.http.HttpServletResponsegetServletResponse()org.apache.sling.api.SlingHttpServletRequestgetSlingRequest()org.apache.sling.engine.impl.SlingRequestProcessorImplgetSlingRequestProcessor()org.apache.sling.api.SlingHttpServletResponsegetSlingResponse()org.apache.sling.api.resource.ResourceinitResource(org.apache.sling.api.resource.ResourceResolver resourceResolver)voidinitServlet(org.apache.sling.api.resource.Resource resource, org.apache.sling.api.servlets.ServletResolver sr)voidresetContent(ContentData data)static voidservice(org.apache.sling.api.SlingHttpServletRequest request, org.apache.sling.api.SlingHttpServletResponse response)Helper method to call the servlet for the current content data.StringsetActiveServletName(String servletName)Sets the name of the currently active servlet and returns the name of the previously active servlet.static voidsetAdditionalResponseHeaders(ArrayList<org.apache.sling.engine.impl.StaticResponseHeader> mappings)ContentDatasetContent(org.apache.sling.api.resource.Resource resource, org.apache.sling.api.request.RequestPathInfo requestPathInfo)static voidsetMaxCallCounter(int maxCallCounter)static voidsetMaxIncludeCounter(int maxInclusionCounter)static voidsetSlingMainServlet(org.apache.sling.engine.impl.SlingMainServlet slingMainServlet)static org.apache.sling.api.SlingHttpServletRequesttoSlingHttpServletRequest(javax.servlet.ServletRequest request)static org.apache.sling.api.SlingHttpServletResponsetoSlingHttpServletResponse(javax.servlet.ServletResponse response)static org.apache.sling.api.SlingHttpServletRequestunwrap(javax.servlet.ServletRequest request)Unwraps the ServletRequest to a SlingHttpServletRequest.static org.apache.sling.api.SlingHttpServletResponseunwrap(javax.servlet.ServletResponse response)Unwraps the ServletRequest to a SlingHttpServletRequest.static org.apache.sling.engine.impl.SlingHttpServletRequestImplunwrap(org.apache.sling.api.SlingHttpServletRequest request)Unwraps the SlingHttpServletRequest to a SlingHttpServletRequestImplstatic org.apache.sling.engine.impl.SlingHttpServletResponseImplunwrap(org.apache.sling.api.SlingHttpServletResponse response)Unwraps a SlingHttpServletResponse to a SlingHttpServletResponseImpl
-
-
-
Field Detail
-
DEFAULT_MAX_INCLUSION_COUNTER
public static final int DEFAULT_MAX_INCLUSION_COUNTER
The default value for the number of recursive inclusions for a single instance of this class (value is 50).- See Also:
- Constant Field Values
-
DEFAULT_MAX_CALL_COUNTER
public static final int DEFAULT_MAX_CALL_COUNTER
The default value for the number of calls to theservice(SlingHttpServletRequest, SlingHttpServletResponse)method for a single instance of this class (value is 1000).- See Also:
- Constant Field Values
-
REQUEST_RESOURCE_PATH_ATTR
public static final String REQUEST_RESOURCE_PATH_ATTR
The name of the request attribute providing the resource addressed by the request URL.- See Also:
- Constant Field Values
-
-
Method Detail
-
setMaxCallCounter
public static void setMaxCallCounter(int maxCallCounter)
-
getMaxCallCounter
public static int getMaxCallCounter()
-
setMaxIncludeCounter
public static void setMaxIncludeCounter(int maxInclusionCounter)
-
getMaxIncludeCounter
public static int getMaxIncludeCounter()
-
setSlingMainServlet
public static void setSlingMainServlet(org.apache.sling.engine.impl.SlingMainServlet slingMainServlet)
-
setAdditionalResponseHeaders
public static void setAdditionalResponseHeaders(ArrayList<org.apache.sling.engine.impl.StaticResponseHeader> mappings)
-
getAdditionalResponseHeaders
public static ArrayList<org.apache.sling.engine.impl.StaticResponseHeader> getAdditionalResponseHeaders()
-
initResource
public org.apache.sling.api.resource.Resource initResource(org.apache.sling.api.resource.ResourceResolver resourceResolver)
-
initServlet
public void initServlet(org.apache.sling.api.resource.Resource resource, org.apache.sling.api.servlets.ServletResolver sr)
-
getSlingRequestProcessor
public org.apache.sling.engine.impl.SlingRequestProcessorImpl getSlingRequestProcessor()
-
getServletRequest
public javax.servlet.http.HttpServletRequest getServletRequest()
-
getServletResponse
public javax.servlet.http.HttpServletResponse getServletResponse()
-
getSlingRequest
public org.apache.sling.api.SlingHttpServletRequest getSlingRequest()
-
getSlingResponse
public org.apache.sling.api.SlingHttpServletResponse getSlingResponse()
-
unwrap
public static org.apache.sling.api.SlingHttpServletRequest unwrap(javax.servlet.ServletRequest request)
Unwraps the ServletRequest to a SlingHttpServletRequest.- Parameters:
request- the request- Returns:
- the unwrapped request
- Throws:
IllegalArgumentException- If therequestis not aSlingHttpServletRequestand not aServletRequestWrapperwrapping aSlingHttpServletRequest.
-
unwrap
public static org.apache.sling.engine.impl.SlingHttpServletRequestImpl unwrap(org.apache.sling.api.SlingHttpServletRequest request)
Unwraps the SlingHttpServletRequest to a SlingHttpServletRequestImpl- Parameters:
request- the request- Returns:
- the unwrapped request
- Throws:
IllegalArgumentException- Ifrequestis not aSlingHttpServletRequestImpland notSlingHttpServletRequestWrapperwrapping aSlingHttpServletRequestImpl.
-
unwrap
public static org.apache.sling.api.SlingHttpServletResponse unwrap(javax.servlet.ServletResponse response)
Unwraps the ServletRequest to a SlingHttpServletRequest.- Parameters:
response- the response- Returns:
- the unwrapped response
- Throws:
IllegalArgumentException- If theresponseis not aSlingHttpServletResponseand not aServletResponseWrapperwrapping aSlingHttpServletResponse.
-
unwrap
public static org.apache.sling.engine.impl.SlingHttpServletResponseImpl unwrap(org.apache.sling.api.SlingHttpServletResponse response)
Unwraps a SlingHttpServletResponse to a SlingHttpServletResponseImpl- Parameters:
response- the response- Returns:
- the unwrapped response
- Throws:
IllegalArgumentException- Ifresponseis not aSlingHttpServletResponseImpland notSlingHttpServletResponseWrapperwrapping aSlingHttpServletResponseImpl.
-
getRequestData
public static RequestData getRequestData(javax.servlet.ServletRequest request)
- Parameters:
request- the request- Returns:
- the request data
- Throws:
IllegalArgumentException- If therequestis not aSlingHttpServletRequestand not aServletRequestWrapperwrapping aSlingHttpServletRequest.
-
getRequestData
public static RequestData getRequestData(org.apache.sling.api.SlingHttpServletRequest request)
- Parameters:
request- the request- Returns:
- the request data
- Throws:
IllegalArgumentException- Ifrequestis not aSlingHttpServletRequestImpland notSlingHttpServletRequestWrapperwrapping aSlingHttpServletRequestImpl.
-
toSlingHttpServletRequest
public static org.apache.sling.api.SlingHttpServletRequest toSlingHttpServletRequest(javax.servlet.ServletRequest request)
- Parameters:
request- the request- Returns:
- the sling http servlet request
- Throws:
IllegalArgumentException- ifrequestis not aHttpServletRequestof ifrequestis not backed bySlingHttpServletRequestImpl.
-
toSlingHttpServletResponse
public static org.apache.sling.api.SlingHttpServletResponse toSlingHttpServletResponse(javax.servlet.ServletResponse response)
- Parameters:
response- the response- Returns:
- the sling http servlet response
- Throws:
IllegalArgumentException- ifresponseis not aHttpServletResponseof ifresponseis not backed bySlingHttpServletResponseImpl.
-
service
public static void service(org.apache.sling.api.SlingHttpServletRequest request, org.apache.sling.api.SlingHttpServletResponse response) throws IOException, javax.servlet.ServletExceptionHelper method to call the servlet for the current content data. If the current content data has no servlet, NOT_FOUND (404) error is sent and the method terminates.If the the servlet exists, the
SlingConstants.SLING_CURRENT_SERVLET_NAMErequest attribute is set to the name of that servlet and that servlet name is also set as thecurrently active servlet. After the termination of the servlet (normal or throwing a Throwable) the request attribute is reset to the previous value. The name of the currently active servlet is only reset to the previous value if the servlet terminates normally. In case of a Throwable, the active servlet name is not reset and indicates which servlet caused the potential abort of the request.- Parameters:
request- The request object for the service methodresponse- The response object for the service method- Throws:
IOException- May be thrown by the servlet's service methodjavax.servlet.ServletException- May be thrown by the servlet's service method
-
setContent
public ContentData setContent(org.apache.sling.api.resource.Resource resource, org.apache.sling.api.request.RequestPathInfo requestPathInfo)
-
resetContent
public void resetContent(ContentData data)
-
getContentData
public ContentData getContentData()
-
getResourceResolver
public org.apache.sling.api.resource.ResourceResolver getResourceResolver()
-
getRequestProgressTracker
public org.apache.sling.api.request.RequestProgressTracker getRequestProgressTracker()
-
getPeakRecusionDepth
public int getPeakRecusionDepth()
-
getServletCallCount
public int getServletCallCount()
-
getElapsedTimeMsec
public long getElapsedTimeMsec()
-
setActiveServletName
public String setActiveServletName(String servletName)
Sets the name of the currently active servlet and returns the name of the previously active servlet.- Parameters:
servletName- the servlet name- Returns:
- the previous servlet name
-
getActiveServletName
public String getActiveServletName()
Returns the name of the currently active servlet. If this name is notnullat the end of request processing, more precisly in the case of an uncaughtThrowableat the end of request processing, this is the name of the servlet causing the uncaughtThrowable.- Returns:
- the current servlet name
-
getInputStream
public javax.servlet.ServletInputStream getInputStream() throws IOException- Throws:
IOException
-
getReader
public BufferedReader getReader() throws UnsupportedEncodingException, IOException
-
getParameterSupport
public ParameterSupport getParameterSupport()
-
-