org.apache.sling.engine.impl.request
Class RequestData

java.lang.Object
  extended by org.apache.sling.engine.impl.request.RequestData
All Implemented Interfaces:
BufferProvider

public class RequestData
extends Object
implements BufferProvider

The RequestData class 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:

  1. Invoke constructor
  2. Invoke initResource()
  3. Invoke initServlet()

See Also:
ContentData

Field Summary
static int DEFAULT_MAX_CALL_COUNTER
          The default value for the number of calls to the service(SlingHttpServletRequest, SlingHttpServletResponse) method for a single instance of this class (value is 1000).
static int DEFAULT_MAX_INCLUSION_COUNTER
          The default value for the number of recursive inclusions for a single instance of this class (value is 50).
 
Constructor Summary
RequestData(SlingRequestProcessorImpl slingRequestProcessor, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
           
 
Method Summary
<Type> Type
adaptTo(Object object, Class<Type> type)
           
 void dispose()
           
 String getActiveServletName()
          Returns the name of the currently active servlet.
 BufferProvider getBufferProvider()
           
 int getBufferSize()
           
 ContentData getContentData()
           
 javax.servlet.ServletInputStream getInputStream()
           
static int getMaxCallCounter()
           
static int getMaxIncludeCounter()
           
 String getMimeType(String fileName)
           
 javax.servlet.ServletOutputStream getOutputStream()
           
 ParameterSupport getParameterSupport()
           
 BufferedReader getReader()
           
static RequestData getRequestData(javax.servlet.ServletRequest request)
           
static RequestData getRequestData(SlingHttpServletRequest request)
           
 RequestProgressTracker getRequestProgressTracker()
           
 ResourceResolver getResourceResolver()
           
 javax.servlet.http.HttpServletRequest getServletRequest()
           
 javax.servlet.http.HttpServletResponse getServletResponse()
           
 SlingHttpServletRequest getSlingRequest()
           
 SlingRequestProcessorImpl getSlingRequestProcessor()
           
 SlingHttpServletResponse getSlingResponse()
           
 PrintWriter getWriter()
           
 Resource initResource(ResourceResolver resourceResolver)
           
 void initServlet(Resource resource)
           
 boolean isContentIncluded()
          Returns true if request processing is currently processing a component which has been included by SlingHttpServletRequestDispatcher.include.
 ContentData popContent()
           
 ContentData pushContent(Resource resource, RequestPathInfo requestPathInfo)
           
static void service(SlingHttpServletRequest request, SlingHttpServletResponse response)
          Helper method to call the servlet for the current content data.
 String setActiveServletName(String servletName)
          Sets the name of the currently active servlet and returns the name of the previously active servlet.
 void setBufferSize(int size)
          Sets the size of the buffer to be used (by default) for output streams returned by BufferProvider.getOutputStream() or writers returned by BufferProvider.getWriter()
static void setMaxCallCounter(int maxCallCounter)
           
static void setMaxIncludeCounter(int maxInclusionCounter)
           
static void setSlingMainServlet(SlingMainServlet slingMainServlet)
           
static SlingHttpServletRequest toSlingHttpServletRequest(javax.servlet.ServletRequest request)
           
static SlingHttpServletResponse toSlingHttpServletResponse(javax.servlet.ServletResponse response)
           
static SlingHttpServletRequest unwrap(javax.servlet.ServletRequest request)
          Unwraps the ServletRequest to a SlingHttpServletRequest.
static SlingHttpServletResponse unwrap(javax.servlet.ServletResponse response)
          Unwraps the ServletRequest to a SlingHttpServletRequest.
static SlingHttpServletRequestImpl unwrap(SlingHttpServletRequest request)
          Unwraps the SlingHttpServletRequest to a SlingHttpServletRequestImpl
static SlingHttpServletResponseImpl unwrap(SlingHttpServletResponse response)
          Unwraps a SlingHttpServletResponse to a SlingHttpServletResponseImpl
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

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 the service(SlingHttpServletRequest, SlingHttpServletResponse) method for a single instance of this class (value is 1000).

See Also:
Constant Field Values
Constructor Detail

RequestData

public RequestData(SlingRequestProcessorImpl slingRequestProcessor,
                   javax.servlet.http.HttpServletRequest request,
                   javax.servlet.http.HttpServletResponse response)
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(SlingMainServlet slingMainServlet)

initResource

public Resource initResource(ResourceResolver resourceResolver)

initServlet

public void initServlet(Resource resource)

dispose

public void dispose()

getSlingRequestProcessor

public SlingRequestProcessorImpl getSlingRequestProcessor()

getServletRequest

public javax.servlet.http.HttpServletRequest getServletRequest()

getServletResponse

public javax.servlet.http.HttpServletResponse getServletResponse()

getSlingRequest

public SlingHttpServletRequest getSlingRequest()

getSlingResponse

public SlingHttpServletResponse getSlingResponse()

unwrap

public static SlingHttpServletRequest unwrap(javax.servlet.ServletRequest request)
Unwraps the ServletRequest to a SlingHttpServletRequest.

Throws:
IllegalArgumentException - If the request is not a SlingHttpServletRequest and not a ServletRequestWrapper wrapping a SlingHttpServletRequest.

unwrap

public static SlingHttpServletRequestImpl unwrap(SlingHttpServletRequest request)
Unwraps the SlingHttpServletRequest to a SlingHttpServletRequestImpl

Parameters:
request -
Throws:
IllegalArgumentException - If request is not a SlingHttpServletRequestImpl and not SlingHttpServletRequestWrapper wrapping a SlingHttpServletRequestImpl.

unwrap

public static SlingHttpServletResponse unwrap(javax.servlet.ServletResponse response)
Unwraps the ServletRequest to a SlingHttpServletRequest.

Throws:
IllegalArgumentException - If the response is not a SlingHttpServletResponse and not a ServletResponseWrapper wrapping a SlingHttpServletResponse.

unwrap

public static SlingHttpServletResponseImpl unwrap(SlingHttpServletResponse response)
Unwraps a SlingHttpServletResponse to a SlingHttpServletResponseImpl

Parameters:
response -
Throws:
IllegalArgumentException - If response is not a SlingHttpServletResponseImpl and not SlingHttpServletResponseWrapper wrapping a SlingHttpServletResponseImpl.

getRequestData

public static RequestData getRequestData(javax.servlet.ServletRequest request)
Parameters:
request -
Throws:
IllegalArgumentException - If the request is not a SlingHttpServletRequest and not a ServletRequestWrapper wrapping a SlingHttpServletRequest.

getRequestData

public static RequestData getRequestData(SlingHttpServletRequest request)
Parameters:
request -
Throws:
IllegalArgumentException - If request is not a SlingHttpServletRequestImpl and not SlingHttpServletRequestWrapper wrapping a SlingHttpServletRequestImpl.

toSlingHttpServletRequest

public static SlingHttpServletRequest toSlingHttpServletRequest(javax.servlet.ServletRequest request)
Parameters:
request -
Throws:
IllegalArgumentException - if request is not a HttpServletRequest of if request is not backed by SlingHttpServletRequestImpl.

toSlingHttpServletResponse

public static SlingHttpServletResponse toSlingHttpServletResponse(javax.servlet.ServletResponse response)
Parameters:
response -
Throws:
IllegalArgumentException - if response is not a HttpServletResponse of if response is not backed by SlingHttpServletResponseImpl.

service

public static void service(SlingHttpServletRequest request,
                           SlingHttpServletResponse response)
                    throws IOException,
                           javax.servlet.ServletException
Helper 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_NAME request attribute is set to the name of that servlet and that servlet name is also set as the currently 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 method
response - The response object for the service method
Throws:
IOException - May be thrown by the servlet's service method
javax.servlet.ServletException - May be thrown by the servlet's service method

pushContent

public ContentData pushContent(Resource resource,
                               RequestPathInfo requestPathInfo)

popContent

public ContentData popContent()

getContentData

public ContentData getContentData()

isContentIncluded

public boolean isContentIncluded()
Returns true if request processing is currently processing a component which has been included by SlingHttpServletRequestDispatcher.include.


getResourceResolver

public ResourceResolver getResourceResolver()

getRequestProgressTracker

public RequestProgressTracker getRequestProgressTracker()

setActiveServletName

public String setActiveServletName(String servletName)
Sets the name of the currently active servlet and returns the name of the previously active servlet.


getActiveServletName

public String getActiveServletName()
Returns the name of the currently active servlet. If this name is not null at the end of request processing, more precisly in the case of an uncaught Throwable at the end of request processing, this is the name of the servlet causing the uncaught Throwable.


adaptTo

public <Type> Type adaptTo(Object object,
                           Class<Type> type)

getMimeType

public String getMimeType(String fileName)

getBufferProvider

public BufferProvider getBufferProvider()

getBufferSize

public int getBufferSize()
Specified by:
getBufferSize in interface BufferProvider
Returns:
the currently set buffer size. This is either some default buffer size or the size last set by the BufferProvider.setBufferSize(int) method.

setBufferSize

public void setBufferSize(int size)
Description copied from interface: BufferProvider
Sets the size of the buffer to be used (by default) for output streams returned by BufferProvider.getOutputStream() or writers returned by BufferProvider.getWriter()

Specified by:
setBufferSize in interface BufferProvider
Parameters:
size - The default buffersize. Negative values or zero disable buffering.

getOutputStream

public javax.servlet.ServletOutputStream getOutputStream()
                                                  throws IOException
Specified by:
getOutputStream in interface BufferProvider
Returns:
a buffered ServletOutputStream whose initial buffer size is set to BufferProvider.getBufferSize().
Throws:
IOException - If an error occurrs setting up the output stream

getWriter

public PrintWriter getWriter()
                      throws IOException
Specified by:
getWriter in interface BufferProvider
Returns:
a buffered PrintWriter whose initial buffer size is set to BufferProvider.getBufferSize().
Throws:
IOException - If an error occurrs setting up the writer

getInputStream

public javax.servlet.ServletInputStream getInputStream()
                                                throws IOException
Throws:
IOException

getReader

public BufferedReader getReader()
                         throws UnsupportedEncodingException,
                                IOException
Throws:
UnsupportedEncodingException
IOException

getParameterSupport

public ParameterSupport getParameterSupport()


Copyright © 2007-2013 The Apache Software Foundation. All Rights Reserved.