org.apache.sling.commons.testing.sling
Class MockSlingHttpServletRequest

java.lang.Object
  extended by org.apache.sling.commons.testing.sling.MockSlingHttpServletRequest
All Implemented Interfaces:
javax.servlet.http.HttpServletRequest, javax.servlet.ServletRequest, SlingHttpServletRequest

public class MockSlingHttpServletRequest
extends java.lang.Object
implements SlingHttpServletRequest

Mock request object. This does not do anything useful, it just returns the constructor parameter secure in the isSecure method.


Field Summary
static java.lang.String RESOURCE_TYPE
           
 
Fields inherited from interface javax.servlet.http.HttpServletRequest
BASIC_AUTH, CLIENT_CERT_AUTH, DIGEST_AUTH, FORM_AUTH
 
Constructor Summary
MockSlingHttpServletRequest(java.lang.String resourcePath, java.lang.String selectors, java.lang.String extension, java.lang.String suffix, java.lang.String queryString)
           
 
Method Summary
 java.lang.Object getAttribute(java.lang.String name)
           
 java.util.Enumeration<?> getAttributeNames()
           
 java.lang.String getAuthType()
           
 java.lang.String getCharacterEncoding()
           
 int getContentLength()
           
 java.lang.String getContentType()
           
 java.lang.String getContextPath()
           
 javax.servlet.http.Cookie getCookie(java.lang.String name)
          Returns the named cookie from the HTTP request or null if no such cookie exists in the request.
 javax.servlet.http.Cookie[] getCookies()
           
 long getDateHeader(java.lang.String name)
           
 java.lang.String getHeader(java.lang.String name)
           
 java.util.Enumeration<?> getHeaderNames()
           
 java.util.Enumeration<?> getHeaders(java.lang.String name)
           
 javax.servlet.ServletInputStream getInputStream()
           
 int getIntHeader(java.lang.String name)
           
 java.lang.String getLocalAddr()
           
 java.util.Locale getLocale()
           
 java.util.Enumeration<?> getLocales()
           
 java.lang.String getLocalName()
           
 int getLocalPort()
           
 java.lang.String getMethod()
           
 java.lang.String getParameter(java.lang.String name)
           
 java.util.Map<?,?> getParameterMap()
           
 java.util.Enumeration<?> getParameterNames()
           
 java.lang.String[] getParameterValues(java.lang.String name)
           
 java.lang.String getPathInfo()
           
 java.lang.String getPathTranslated()
           
 java.lang.String getProtocol()
           
 java.lang.String getQueryString()
           
 java.io.BufferedReader getReader()
           
 java.lang.String getRealPath(java.lang.String path)
           
 java.lang.String getRemoteAddr()
           
 java.lang.String getRemoteHost()
           
 int getRemotePort()
           
 java.lang.String getRemoteUser()
           
 javax.servlet.RequestDispatcher getRequestDispatcher(Resource resource)
          Same as SlingHttpServletRequest.getRequestDispatcher(Resource,RequestDispatcherOptions) but using empty options.
 javax.servlet.RequestDispatcher getRequestDispatcher(Resource resource, RequestDispatcherOptions options)
          Returns a RequestDispatcher object that acts as a wrapper for the resource located at the given resource.
 javax.servlet.RequestDispatcher getRequestDispatcher(java.lang.String path)
           
 javax.servlet.RequestDispatcher getRequestDispatcher(java.lang.String path, RequestDispatcherOptions options)
          Returns a RequestDispatcher object that acts as a wrapper for the resource located at the given path.
 java.lang.String getRequestedSessionId()
           
 RequestParameter getRequestParameter(java.lang.String name)
          Returns the value of a request parameter as a RequestParameter, or null if the parameter does not exist.
 RequestParameterMap getRequestParameterMap()
          Returns a Map of the parameters of this request.
 RequestParameter[] getRequestParameters(java.lang.String name)
          Returns an array of RequestParameter objects containing all of the values the given request parameter has, or null if the parameter does not exist.
 RequestPathInfo getRequestPathInfo()
          Returns the RequestPathInfo pertaining to this request.
 RequestProgressTracker getRequestProgressTracker()
          Returns the RequestProgressTracker of this request.
 java.lang.String getRequestURI()
           
 java.lang.StringBuffer getRequestURL()
           
 Resource getResource()
          Returns the Resource object on whose behalf the servlet acts.
 java.util.ResourceBundle getResourceBundle(java.util.Locale locale)
          Returns the resource bundle for the given locale.
 java.util.ResourceBundle getResourceBundle(java.lang.String baseName, java.util.Locale locale)
          Returns the resource bundle of the given base name for the given locale.
 ResourceResolver getResourceResolver()
          Returns the ResourceResolver which resolved the resource of this request.
 java.lang.String getResponseContentType()
          Returns the framework preferred content type for the response.
 java.util.Enumeration<java.lang.String> getResponseContentTypes()
          Gets a list of content types which the framework accepts for the response.
 java.lang.String getScheme()
           
 java.lang.String getServerName()
           
 int getServerPort()
           
 java.lang.String getServletPath()
           
 javax.servlet.http.HttpSession getSession()
           
 javax.servlet.http.HttpSession getSession(boolean create)
           
 java.security.Principal getUserPrincipal()
           
 boolean isRequestedSessionIdFromCookie()
           
 boolean isRequestedSessionIdFromUrl()
           
 boolean isRequestedSessionIdFromURL()
           
 boolean isRequestedSessionIdValid()
           
 boolean isSecure()
           
 boolean isUserInRole(java.lang.String role)
           
 void removeAttribute(java.lang.String name)
           
 void setAttribute(java.lang.String name, java.lang.Object o)
           
 void setCharacterEncoding(java.lang.String env)
           
 void setMethod(java.lang.String method)
           
 void setResource(Resource resource)
           
 void setResourceResolver(MockResourceResolver resolver)
           
 void setSecure(boolean secure)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

RESOURCE_TYPE

public static final java.lang.String RESOURCE_TYPE
See Also:
Constant Field Values
Constructor Detail

MockSlingHttpServletRequest

public MockSlingHttpServletRequest(java.lang.String resourcePath,
                                   java.lang.String selectors,
                                   java.lang.String extension,
                                   java.lang.String suffix,
                                   java.lang.String queryString)
Method Detail

setResourceResolver

public void setResourceResolver(MockResourceResolver resolver)

setResource

public void setResource(Resource resource)

setSecure

public void setSecure(boolean secure)

setMethod

public void setMethod(java.lang.String method)

getCookie

public javax.servlet.http.Cookie getCookie(java.lang.String name)
Description copied from interface: SlingHttpServletRequest
Returns the named cookie from the HTTP request or null if no such cookie exists in the request.

Specified by:
getCookie in interface SlingHttpServletRequest
Parameters:
name - The name of the cookie to return.
Returns:
The named cookie or null if no such cookie exists.

getRequestDispatcher

public javax.servlet.RequestDispatcher getRequestDispatcher(java.lang.String path,
                                                            RequestDispatcherOptions options)
Description copied from interface: SlingHttpServletRequest
Returns a RequestDispatcher object that acts as a wrapper for the resource located at the given path. A RequestDispatcher object can be used to include the resource in a response.

Returns null if a RequestDispatcher cannot be returned for any reason.

Specified by:
getRequestDispatcher in interface SlingHttpServletRequest
Parameters:
path - a String specifying the pathname to the resource. If it is relative, it must be relative against the current servlet.
options - influence the rendering of the included Resource
Returns:
a RequestDispatcher object that acts as a wrapper for the resource or null if an error occurs preparing the dispatcher.

getRequestDispatcher

public javax.servlet.RequestDispatcher getRequestDispatcher(Resource resource,
                                                            RequestDispatcherOptions options)
Description copied from interface: SlingHttpServletRequest
Returns a RequestDispatcher object that acts as a wrapper for the resource located at the given resource. A RequestDispatcher object can be used to include the resource in a response.

Returns null if a RequestDispatcher cannot be returned for any reason.

Specified by:
getRequestDispatcher in interface SlingHttpServletRequest
Parameters:
resource - The Resource instance whose response content may be included by the returned dispatcher.
options - influence the rendering of the included Resource
Returns:
a RequestDispatcher object that acts as a wrapper for the resource or null if an error occurs preparing the dispatcher.

getRequestDispatcher

public javax.servlet.RequestDispatcher getRequestDispatcher(Resource resource)
Description copied from interface: SlingHttpServletRequest
Same as SlingHttpServletRequest.getRequestDispatcher(Resource,RequestDispatcherOptions) but using empty options.

Specified by:
getRequestDispatcher in interface SlingHttpServletRequest

getRequestParameter

public RequestParameter getRequestParameter(java.lang.String name)
Description copied from interface: SlingHttpServletRequest
Returns the value of a request parameter as a RequestParameter, or null if the parameter does not exist.

This method should only be used if the parameter has only one value. If the parameter might have more than one value, use SlingHttpServletRequest.getRequestParameters(String).

If this method is used with a multivalued parameter, the value returned is equal to the first value in the array returned by getRequestParameters.

This method is a shortcut for getRequestParameterMap().getValue(String).

Specified by:
getRequestParameter in interface SlingHttpServletRequest
Parameters:
name - a String specifying the name of the parameter
Returns:
a RequestParameter representing the single value of the parameter
See Also:
SlingHttpServletRequest.getRequestParameters(String), RequestParameterMap.getValue(String)

getRequestParameterMap

public RequestParameterMap getRequestParameterMap()
Description copied from interface: SlingHttpServletRequest
Returns a Map of the parameters of this request.

The values in the returned Map are from type RequestParameter array (RequestParameter[]).

If no parameters exist this method returns an empty Map.

Specified by:
getRequestParameterMap in interface SlingHttpServletRequest
Returns:
an immutable Map containing parameter names as keys and parameter values as map values, or an empty Map if no parameters exist. The keys in the parameter map are of type String. The values in the parameter map are of type RequestParameter array (RequestParameter[]).

getRequestParameters

public RequestParameter[] getRequestParameters(java.lang.String name)
Description copied from interface: SlingHttpServletRequest
Returns an array of RequestParameter objects containing all of the values the given request parameter has, or null if the parameter does not exist.

If the parameter has a single value, the array has a length of 1.

This method is a shortcut for getRequestParameterMap().getValues(String).

Specified by:
getRequestParameters in interface SlingHttpServletRequest
Parameters:
name - a String containing the name of the parameter the value of which is requested
Returns:
an array of RequestParameter objects containing the parameter values.
See Also:
SlingHttpServletRequest.getRequestParameter(String), RequestParameterMap.getValues(String)

getRequestPathInfo

public RequestPathInfo getRequestPathInfo()
Description copied from interface: SlingHttpServletRequest
Returns the RequestPathInfo pertaining to this request.

Specified by:
getRequestPathInfo in interface SlingHttpServletRequest
Returns:
the request path info.

getRequestProgressTracker

public RequestProgressTracker getRequestProgressTracker()
Description copied from interface: SlingHttpServletRequest
Returns the RequestProgressTracker of this request.

Specified by:
getRequestProgressTracker in interface SlingHttpServletRequest

getResource

public Resource getResource()
Description copied from interface: SlingHttpServletRequest
Returns the Resource object on whose behalf the servlet acts.

Specified by:
getResource in interface SlingHttpServletRequest
Returns:
The Resource object of this request.

getResourceBundle

public java.util.ResourceBundle getResourceBundle(java.util.Locale locale)
Description copied from interface: SlingHttpServletRequest
Returns the resource bundle for the given locale.

Specified by:
getResourceBundle in interface SlingHttpServletRequest
Parameters:
locale - the locale for which to retrieve the resource bundle. If this is null, the locale returned by ServletRequest.getLocale() is used to select the resource bundle.
Returns:
the resource bundle for the given locale

getResourceBundle

public java.util.ResourceBundle getResourceBundle(java.lang.String baseName,
                                                  java.util.Locale locale)
Description copied from interface: SlingHttpServletRequest
Returns the resource bundle of the given base name for the given locale.

Specified by:
getResourceBundle in interface SlingHttpServletRequest
Parameters:
baseName - The base name of the resource bundle to returned. If this parameter is null, the same resource bundle must be returned as if the SlingHttpServletRequest.getResourceBundle(Locale) method is called.
locale - the locale for which to retrieve the resource bundle. If this is null, the locale returned by ServletRequest.getLocale() is used to select the resource bundle.
Returns:
the resource bundle for the given locale

getResourceResolver

public ResourceResolver getResourceResolver()
Description copied from interface: SlingHttpServletRequest
Returns the ResourceResolver which resolved the resource of this request.

Specified by:
getResourceResolver in interface SlingHttpServletRequest
Returns:
The resource resolver

getResponseContentType

public java.lang.String getResponseContentType()
Description copied from interface: SlingHttpServletRequest
Returns the framework preferred content type for the response. The content type only includes the MIME type, not the character set.

For included resources this method will returned the same string as returned by the ServletResponse.getContentType() without the character set.

Specified by:
getResponseContentType in interface SlingHttpServletRequest
Returns:
preferred MIME type of the response

getResponseContentTypes

public java.util.Enumeration<java.lang.String> getResponseContentTypes()
Description copied from interface: SlingHttpServletRequest
Gets a list of content types which the framework accepts for the response. This list is ordered with the most preferable types listed first. The content type only includes the MIME type, not the character set.

For included resources this method will returned an enumeration containing a single entry which is the same string as returned by the ServletResponse.getContentType() without the character set.

Specified by:
getResponseContentTypes in interface SlingHttpServletRequest
Returns:
ordered list of MIME types for the response

getAuthType

public java.lang.String getAuthType()
Specified by:
getAuthType in interface javax.servlet.http.HttpServletRequest

getContextPath

public java.lang.String getContextPath()
Specified by:
getContextPath in interface javax.servlet.http.HttpServletRequest

getCookies

public javax.servlet.http.Cookie[] getCookies()
Specified by:
getCookies in interface javax.servlet.http.HttpServletRequest

getDateHeader

public long getDateHeader(java.lang.String name)
Specified by:
getDateHeader in interface javax.servlet.http.HttpServletRequest

getHeader

public java.lang.String getHeader(java.lang.String name)
Specified by:
getHeader in interface javax.servlet.http.HttpServletRequest

getHeaderNames

public java.util.Enumeration<?> getHeaderNames()
Specified by:
getHeaderNames in interface javax.servlet.http.HttpServletRequest

getHeaders

public java.util.Enumeration<?> getHeaders(java.lang.String name)
Specified by:
getHeaders in interface javax.servlet.http.HttpServletRequest

getIntHeader

public int getIntHeader(java.lang.String name)
Specified by:
getIntHeader in interface javax.servlet.http.HttpServletRequest

getMethod

public java.lang.String getMethod()
Specified by:
getMethod in interface javax.servlet.http.HttpServletRequest

getPathInfo

public java.lang.String getPathInfo()
Specified by:
getPathInfo in interface javax.servlet.http.HttpServletRequest

getPathTranslated

public java.lang.String getPathTranslated()
Specified by:
getPathTranslated in interface javax.servlet.http.HttpServletRequest

getQueryString

public java.lang.String getQueryString()
Specified by:
getQueryString in interface javax.servlet.http.HttpServletRequest

getRemoteUser

public java.lang.String getRemoteUser()
Specified by:
getRemoteUser in interface javax.servlet.http.HttpServletRequest

getRequestURI

public java.lang.String getRequestURI()
Specified by:
getRequestURI in interface javax.servlet.http.HttpServletRequest

getRequestURL

public java.lang.StringBuffer getRequestURL()
Specified by:
getRequestURL in interface javax.servlet.http.HttpServletRequest

getRequestedSessionId

public java.lang.String getRequestedSessionId()
Specified by:
getRequestedSessionId in interface javax.servlet.http.HttpServletRequest

getServletPath

public java.lang.String getServletPath()
Specified by:
getServletPath in interface javax.servlet.http.HttpServletRequest

getSession

public javax.servlet.http.HttpSession getSession()
Specified by:
getSession in interface javax.servlet.http.HttpServletRequest

getSession

public javax.servlet.http.HttpSession getSession(boolean create)
Specified by:
getSession in interface javax.servlet.http.HttpServletRequest

getUserPrincipal

public java.security.Principal getUserPrincipal()
Specified by:
getUserPrincipal in interface javax.servlet.http.HttpServletRequest

isRequestedSessionIdFromCookie

public boolean isRequestedSessionIdFromCookie()
Specified by:
isRequestedSessionIdFromCookie in interface javax.servlet.http.HttpServletRequest

isRequestedSessionIdFromURL

public boolean isRequestedSessionIdFromURL()
Specified by:
isRequestedSessionIdFromURL in interface javax.servlet.http.HttpServletRequest

isRequestedSessionIdFromUrl

public boolean isRequestedSessionIdFromUrl()
Specified by:
isRequestedSessionIdFromUrl in interface javax.servlet.http.HttpServletRequest

isRequestedSessionIdValid

public boolean isRequestedSessionIdValid()
Specified by:
isRequestedSessionIdValid in interface javax.servlet.http.HttpServletRequest

isUserInRole

public boolean isUserInRole(java.lang.String role)
Specified by:
isUserInRole in interface javax.servlet.http.HttpServletRequest

getAttribute

public java.lang.Object getAttribute(java.lang.String name)
Specified by:
getAttribute in interface javax.servlet.ServletRequest

getAttributeNames

public java.util.Enumeration<?> getAttributeNames()
Specified by:
getAttributeNames in interface javax.servlet.ServletRequest

getCharacterEncoding

public java.lang.String getCharacterEncoding()
Specified by:
getCharacterEncoding in interface javax.servlet.ServletRequest

getContentLength

public int getContentLength()
Specified by:
getContentLength in interface javax.servlet.ServletRequest

getContentType

public java.lang.String getContentType()
Specified by:
getContentType in interface javax.servlet.ServletRequest

getInputStream

public javax.servlet.ServletInputStream getInputStream()
Specified by:
getInputStream in interface javax.servlet.ServletRequest

getLocalAddr

public java.lang.String getLocalAddr()
Specified by:
getLocalAddr in interface javax.servlet.ServletRequest

getLocalName

public java.lang.String getLocalName()
Specified by:
getLocalName in interface javax.servlet.ServletRequest

getLocalPort

public int getLocalPort()
Specified by:
getLocalPort in interface javax.servlet.ServletRequest

getLocale

public java.util.Locale getLocale()
Specified by:
getLocale in interface javax.servlet.ServletRequest

getLocales

public java.util.Enumeration<?> getLocales()
Specified by:
getLocales in interface javax.servlet.ServletRequest

getParameter

public java.lang.String getParameter(java.lang.String name)
Specified by:
getParameter in interface javax.servlet.ServletRequest

getParameterMap

public java.util.Map<?,?> getParameterMap()
Specified by:
getParameterMap in interface javax.servlet.ServletRequest

getParameterNames

public java.util.Enumeration<?> getParameterNames()
Specified by:
getParameterNames in interface javax.servlet.ServletRequest

getParameterValues

public java.lang.String[] getParameterValues(java.lang.String name)
Specified by:
getParameterValues in interface javax.servlet.ServletRequest

getProtocol

public java.lang.String getProtocol()
Specified by:
getProtocol in interface javax.servlet.ServletRequest

getReader

public java.io.BufferedReader getReader()
Specified by:
getReader in interface javax.servlet.ServletRequest

getRealPath

public java.lang.String getRealPath(java.lang.String path)
Specified by:
getRealPath in interface javax.servlet.ServletRequest

getRemoteAddr

public java.lang.String getRemoteAddr()
Specified by:
getRemoteAddr in interface javax.servlet.ServletRequest

getRemoteHost

public java.lang.String getRemoteHost()
Specified by:
getRemoteHost in interface javax.servlet.ServletRequest

getRemotePort

public int getRemotePort()
Specified by:
getRemotePort in interface javax.servlet.ServletRequest

getRequestDispatcher

public javax.servlet.RequestDispatcher getRequestDispatcher(java.lang.String path)
Specified by:
getRequestDispatcher in interface javax.servlet.ServletRequest

getScheme

public java.lang.String getScheme()
Specified by:
getScheme in interface javax.servlet.ServletRequest

getServerName

public java.lang.String getServerName()
Specified by:
getServerName in interface javax.servlet.ServletRequest

getServerPort

public int getServerPort()
Specified by:
getServerPort in interface javax.servlet.ServletRequest

isSecure

public boolean isSecure()
Specified by:
isSecure in interface javax.servlet.ServletRequest

removeAttribute

public void removeAttribute(java.lang.String name)
Specified by:
removeAttribute in interface javax.servlet.ServletRequest

setAttribute

public void setAttribute(java.lang.String name,
                         java.lang.Object o)
Specified by:
setAttribute in interface javax.servlet.ServletRequest

setCharacterEncoding

public void setCharacterEncoding(java.lang.String env)
Specified by:
setCharacterEncoding in interface javax.servlet.ServletRequest


Copyright © 2007-2009. All Rights Reserved.