Class EntityHttpServletRequest
- java.lang.Object
-
- org.sakaiproject.entitybroker.util.http.EntityHttpServletRequest
-
- All Implemented Interfaces:
HttpServletRequest,ServletRequest
public class EntityHttpServletRequest extends Object implements HttpServletRequest
Makes a copy of the data in a servlet request into a new request object- Author:
- Aaron Zeckoski (azeckoski @ gmail.com)
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classEntityHttpServletRequest.EntityHttpSessionA fake session for testing, from the spring mock sessionstatic classEntityHttpServletRequest.EntityRequestDispatcherA non-functional request dispatcher, based on the spring mock versionstatic classEntityHttpServletRequest.EntityServletContextFor testing, based on the spring Mock version
-
Field Summary
Fields Modifier and Type Field Description HttpServletRequestcopystatic StringDEFAULT_PROTOCOLdefault protocol: HTTP/1.0static StringDEFAULT_REMOTE_ADDRdefault remote address: 127.0.0.1static StringDEFAULT_REMOTE_HOSTThe default remote host: 'localhost'.static StringDEFAULT_SCHEMAdefault schema: httpstatic StringDEFAULT_SERVER_ADDRdefault server address: 127.0.0.1static StringDEFAULT_SERVER_NAMEdefault server name: localhoststatic intDEFAULT_SERVER_PORTdefault server port: 80Map<String,String[]>pathQueryParamsThis stores all the query params found when the request was created-
Fields inherited from interface javax.servlet.http.HttpServletRequest
BASIC_AUTH, CLIENT_CERT_AUTH, DIGEST_AUTH, FORM_AUTH
-
-
Constructor Summary
Constructors Constructor Description EntityHttpServletRequest(String pathString)Create a request using the pathStringEntityHttpServletRequest(String method, String pathString)Create a request using the pathString and setting the methodEntityHttpServletRequest(String method, String pathString, String... params)Create a request using the pathString and setting the method and paramsEntityHttpServletRequest(HttpServletRequest req)Create a new request from a given requestEntityHttpServletRequest(HttpServletRequest req, String pathString)Create a new request from a given request and modify it based on the path stringEntityHttpServletRequest(HttpServletRequest req, String method, String pathString)Create a new request from a given request and modify it based on the path string and method
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddCookie(Cookie cookie)Adds a new cookie to the requestvoidaddHeader(String name, String... content)voidaddParameter(String name, String value)Add a single parameter, this will append to an existing onevoidaddParameter(String name, String[] values)Add an array of values for a parameter, these will append to existing onesvoidclearAttributes()Remove all attributesvoidclearCookies()Remove all cookiesvoidclearHeaders()Remove all headersvoidclearParameters()Remove all parametersObjectgetAttribute(String name)EnumerationgetAttributeNames()StringgetAuthType()StringgetCharacterEncoding()ServletInputStreamgetContent()Gets the content data out of the request, ensures that the data can be retrieved somehowintgetContentLength()StringgetContentType()StringgetContextPath()Cookie[]getCookies()longgetDateHeader(String name)StringgetHeader(String name)EnumerationgetHeaderNames()EnumerationgetHeaders(String name)ServletInputStreamgetInputStream()intgetIntHeader(String name)StringgetLocalAddr()LocalegetLocale()EnumerationgetLocales()StringgetLocalName()intgetLocalPort()StringgetMethod()StringgetParameter(String name)MapgetParameterMap()EnumerationgetParameterNames()Map<String,String[]>getParameters()String[]getParameterValues(String name)StringgetPathInfo()StringgetPathTranslated()StringgetProtocol()StringgetQueryString()BufferedReadergetReader()StringgetRealPath(String path)StringgetRemoteAddr()StringgetRemoteHost()intgetRemotePort()StringgetRemoteUser()RequestDispatchergetRequestDispatcher(String path)StringgetRequestedSessionId()StringgetRequestURI()StringBuffergetRequestURL()StringgetScheme()StringgetServerName()intgetServerPort()StringgetServletPath()HttpSessiongetSession()HttpSessiongetSession(boolean create)Map<String,String>getStringParameters()PrincipalgetUserPrincipal()booleanisRequestedSessionIdFromCookie()booleanisRequestedSessionIdFromUrl()booleanisRequestedSessionIdFromURL()booleanisRequestedSessionIdValid()booleanisSecure()booleanisUserInRole(String role)voidremoveAttribute(String name)voidremoveCookie(String name)Removes the cookie with the given name from the requestvoidremoveHeader(String name)voidremoveParameter(String name)Removes a parameter and all values for itvoidsetAttribute(String name, Object o)voidsetCharacterEncoding(String env)voidsetContent(byte[] content)Allows control over the content data which is used in this request, all data should be UTF-8 encodedvoidsetContent(InputStream contentStream, int contentLength)Allows control over the content data which is used in this request, all data should be UTF-8 encodedvoidsetContent(String content)Allows control over the content data which is used in this request, all data should be UTF-8 encodedvoidsetContentType(String contentType)Sets the content type for this request contentvoidsetContextPath(String contextPath)voidsetLocale(Locale locale)voidsetMethod(String method)voidsetParameter(String name, String[] values)Set a new parameter (overwrite an existing one)voidsetParameters(Map<String,String[]> params)Set a large number of params at once, replaces existing paramsvoidsetPathInfo(String pathInfo)URLDatasetPathString(String pathString)This will set the given url/path string values into this request, this will override any values that are currently setvoidsetQueryString(String queryString)voidsetRequestValues(HttpServletRequest req)Set all the values from a request on this request object and set this request as the one which the values were copied fromvoidsetServletPath(String servletPath)voidsetUseRealDispatcher(boolean real)StringtoString()
-
-
-
Field Detail
-
DEFAULT_SCHEMA
public static final String DEFAULT_SCHEMA
default schema: http- See Also:
- Constant Field Values
-
DEFAULT_PROTOCOL
public static final String DEFAULT_PROTOCOL
default protocol: HTTP/1.0- See Also:
- Constant Field Values
-
DEFAULT_SERVER_ADDR
public static final String DEFAULT_SERVER_ADDR
default server address: 127.0.0.1- See Also:
- Constant Field Values
-
DEFAULT_SERVER_NAME
public static final String DEFAULT_SERVER_NAME
default server name: localhost- See Also:
- Constant Field Values
-
DEFAULT_SERVER_PORT
public static final int DEFAULT_SERVER_PORT
default server port: 80- See Also:
- Constant Field Values
-
DEFAULT_REMOTE_ADDR
public static final String DEFAULT_REMOTE_ADDR
default remote address: 127.0.0.1- See Also:
- Constant Field Values
-
DEFAULT_REMOTE_HOST
public static final String DEFAULT_REMOTE_HOST
The default remote host: 'localhost'.- See Also:
- Constant Field Values
-
copy
public HttpServletRequest copy
-
-
Constructor Detail
-
EntityHttpServletRequest
public EntityHttpServletRequest(HttpServletRequest req)
Create a new request from a given request- Parameters:
req- any request
-
EntityHttpServletRequest
public EntityHttpServletRequest(HttpServletRequest req, String pathString)
Create a new request from a given request and modify it based on the path string- Parameters:
req- any requestpathString- any full path or URL (/direct/prefix/id.xml)
-
EntityHttpServletRequest
public EntityHttpServletRequest(HttpServletRequest req, String method, String pathString)
Create a new request from a given request and modify it based on the path string and method- Parameters:
req- any requestmethod- GET, POST, PUT, DELETE (PUT and DELETE not supported by browsers), this will be set to POST if null or unsetpathString- any full path or URL (/direct/prefix/id.xml)
-
EntityHttpServletRequest
public EntityHttpServletRequest(String pathString)
Create a request using the pathString- Parameters:
pathString- any path or URL
-
EntityHttpServletRequest
public EntityHttpServletRequest(String method, String pathString)
Create a request using the pathString and setting the method- Parameters:
pathString- any path or URLmethod- GET, POST, PUT, DELETE (PUT and DELETE not supported by browsers), this will be set to POST if null or unset
-
EntityHttpServletRequest
public EntityHttpServletRequest(String method, String pathString, String... params)
Create a request using the pathString and setting the method and params- Parameters:
method- GET, POST, PUT, DELETE (PUT and DELETE not supported by browsers), this will be set to POST if null or unsetpathString- any path or URLparams- alternating keys and values (starting with keys) to place into the request parameters
-
-
Method Detail
-
setRequestValues
public void setRequestValues(HttpServletRequest req)
Set all the values from a request on this request object and set this request as the one which the values were copied from- Parameters:
req- any request
-
setPathString
public URLData setPathString(String pathString)
This will set the given url/path string values into this request, this will override any values that are currently set- Parameters:
pathString- any url or path string- Returns:
- the url data object based on the input object OR null if the string is null or empty
-
setContent
public void setContent(InputStream contentStream, int contentLength)
Allows control over the content data which is used in this request, all data should be UTF-8 encoded- Parameters:
content- any IS content, UTF-8 encoded, replaces existing content
-
setContent
public void setContent(byte[] content)
Allows control over the content data which is used in this request, all data should be UTF-8 encoded- Parameters:
content- any byte[] content, UTF-8 encoded, replaces existing content
-
setContent
public void setContent(String content)
Allows control over the content data which is used in this request, all data should be UTF-8 encoded- Parameters:
content- any string content, UTF-8 encoded, replaces existing content
-
getContent
public ServletInputStream getContent() throws IOException
Gets the content data out of the request, ensures that the data can be retrieved somehow- Returns:
- the content data from the request
- Throws:
IOException- if there is a failure
-
getAttribute
public Object getAttribute(String name)
- Specified by:
getAttributein interfaceServletRequest
-
getAttributeNames
public Enumeration getAttributeNames()
- Specified by:
getAttributeNamesin interfaceServletRequest
-
removeAttribute
public void removeAttribute(String name)
- Specified by:
removeAttributein interfaceServletRequest
-
setAttribute
public void setAttribute(String name, Object o)
- Specified by:
setAttributein interfaceServletRequest
-
clearAttributes
public void clearAttributes()
Remove all attributes
-
setCharacterEncoding
public void setCharacterEncoding(String env) throws UnsupportedEncodingException
- Specified by:
setCharacterEncodingin interfaceServletRequest- Throws:
UnsupportedEncodingException
-
getCharacterEncoding
public String getCharacterEncoding()
- Specified by:
getCharacterEncodingin interfaceServletRequest
-
setContentType
public void setContentType(String contentType)
Sets the content type for this request content- Parameters:
contentType-
-
getContentType
public String getContentType()
- Specified by:
getContentTypein interfaceServletRequest
-
getContentLength
public int getContentLength()
- Specified by:
getContentLengthin interfaceServletRequest
-
getInputStream
public ServletInputStream getInputStream() throws IOException
- Specified by:
getInputStreamin interfaceServletRequest- Throws:
IOException
-
getReader
public BufferedReader getReader() throws IOException
- Specified by:
getReaderin interfaceServletRequest- Throws:
IOException
-
setLocale
public void setLocale(Locale locale)
-
getLocale
public Locale getLocale()
- Specified by:
getLocalein interfaceServletRequest
-
setMethod
public void setMethod(String method)
-
getMethod
public String getMethod()
- Specified by:
getMethodin interfaceHttpServletRequest
-
setContextPath
public void setContextPath(String contextPath)
-
getContextPath
public String getContextPath()
- Specified by:
getContextPathin interfaceHttpServletRequest
-
setPathInfo
public void setPathInfo(String pathInfo)
-
getPathInfo
public String getPathInfo()
- Specified by:
getPathInfoin interfaceHttpServletRequest
-
getPathTranslated
public String getPathTranslated()
- Specified by:
getPathTranslatedin interfaceHttpServletRequest
-
setQueryString
public void setQueryString(String queryString)
-
getQueryString
public String getQueryString()
- Specified by:
getQueryStringin interfaceHttpServletRequest
-
getRequestURI
public String getRequestURI()
- Specified by:
getRequestURIin interfaceHttpServletRequest
-
getRequestURL
public StringBuffer getRequestURL()
- Specified by:
getRequestURLin interfaceHttpServletRequest
-
setServletPath
public void setServletPath(String servletPath)
-
getServletPath
public String getServletPath()
- Specified by:
getServletPathin interfaceHttpServletRequest
-
addCookie
public void addCookie(Cookie cookie)
Adds a new cookie to the request- Parameters:
cookie- a cookie to add, will displace existing cookies with the same name
-
removeCookie
public void removeCookie(String name)
Removes the cookie with the given name from the request- Parameters:
name- the name of a cookie
-
getCookies
public Cookie[] getCookies()
- Specified by:
getCookiesin interfaceHttpServletRequest
-
clearCookies
public void clearCookies()
Remove all cookies
-
removeHeader
public void removeHeader(String name)
-
getHeader
public String getHeader(String name)
- Specified by:
getHeaderin interfaceHttpServletRequest
-
getHeaderNames
public Enumeration getHeaderNames()
- Specified by:
getHeaderNamesin interfaceHttpServletRequest
-
getHeaders
public Enumeration getHeaders(String name)
- Specified by:
getHeadersin interfaceHttpServletRequest
-
getDateHeader
public long getDateHeader(String name)
- Specified by:
getDateHeaderin interfaceHttpServletRequest
-
getIntHeader
public int getIntHeader(String name)
- Specified by:
getIntHeaderin interfaceHttpServletRequest
-
clearHeaders
public void clearHeaders()
Remove all headers
-
getAuthType
public String getAuthType()
- Specified by:
getAuthTypein interfaceHttpServletRequest
-
getLocalAddr
public String getLocalAddr()
- Specified by:
getLocalAddrin interfaceServletRequest
-
getLocales
public Enumeration getLocales()
- Specified by:
getLocalesin interfaceServletRequest
-
getLocalName
public String getLocalName()
- Specified by:
getLocalNamein interfaceServletRequest
-
getLocalPort
public int getLocalPort()
- Specified by:
getLocalPortin interfaceServletRequest
-
getStringParameters
public Map<String,String> getStringParameters()
- Returns:
- all parameters in this request as single strings
-
getParameter
public String getParameter(String name)
- Specified by:
getParameterin interfaceServletRequest
-
getParameterMap
public Map getParameterMap()
- Specified by:
getParameterMapin interfaceServletRequest
-
getParameterNames
public Enumeration getParameterNames()
- Specified by:
getParameterNamesin interfaceServletRequest
-
getParameterValues
public String[] getParameterValues(String name)
- Specified by:
getParameterValuesin interfaceServletRequest
-
addParameter
public void addParameter(String name, String value)
Add a single parameter, this will append to an existing one
-
addParameter
public void addParameter(String name, String[] values)
Add an array of values for a parameter, these will append to existing ones
-
setParameter
public void setParameter(String name, String[] values)
Set a new parameter (overwrite an existing one)
-
setParameters
public void setParameters(Map<String,String[]> params)
Set a large number of params at once, replaces existing params- Parameters:
params- map of params
-
removeParameter
public void removeParameter(String name)
Removes a parameter and all values for it- Parameters:
name-
-
clearParameters
public void clearParameters()
Remove all parameters
-
getProtocol
public String getProtocol()
- Specified by:
getProtocolin interfaceServletRequest
-
getRealPath
public String getRealPath(String path)
- Specified by:
getRealPathin interfaceServletRequest
-
getRemoteAddr
public String getRemoteAddr()
- Specified by:
getRemoteAddrin interfaceServletRequest
-
getRemoteHost
public String getRemoteHost()
- Specified by:
getRemoteHostin interfaceServletRequest
-
getRemotePort
public int getRemotePort()
- Specified by:
getRemotePortin interfaceServletRequest
-
getRemoteUser
public String getRemoteUser()
- Specified by:
getRemoteUserin interfaceHttpServletRequest
-
setUseRealDispatcher
public void setUseRealDispatcher(boolean real)
- Parameters:
real- if true and there is a real RequestDispatcher available then use it, otherwise just emulate a forward/include call using the fake one (will always use the fake one if no real one is found)
-
getRequestDispatcher
public RequestDispatcher getRequestDispatcher(String path)
- Specified by:
getRequestDispatcherin interfaceServletRequest
-
getScheme
public String getScheme()
- Specified by:
getSchemein interfaceServletRequest
-
getServerName
public String getServerName()
- Specified by:
getServerNamein interfaceServletRequest
-
getServerPort
public int getServerPort()
- Specified by:
getServerPortin interfaceServletRequest
-
getRequestedSessionId
public String getRequestedSessionId()
- Specified by:
getRequestedSessionIdin interfaceHttpServletRequest
-
getSession
public HttpSession getSession()
- Specified by:
getSessionin interfaceHttpServletRequest
-
getSession
public HttpSession getSession(boolean create)
- Specified by:
getSessionin interfaceHttpServletRequest
-
getUserPrincipal
public Principal getUserPrincipal()
- Specified by:
getUserPrincipalin interfaceHttpServletRequest
-
isRequestedSessionIdFromCookie
public boolean isRequestedSessionIdFromCookie()
- Specified by:
isRequestedSessionIdFromCookiein interfaceHttpServletRequest
-
isRequestedSessionIdFromUrl
public boolean isRequestedSessionIdFromUrl()
- Specified by:
isRequestedSessionIdFromUrlin interfaceHttpServletRequest
-
isRequestedSessionIdFromURL
public boolean isRequestedSessionIdFromURL()
- Specified by:
isRequestedSessionIdFromURLin interfaceHttpServletRequest
-
isRequestedSessionIdValid
public boolean isRequestedSessionIdValid()
- Specified by:
isRequestedSessionIdValidin interfaceHttpServletRequest
-
isSecure
public boolean isSecure()
- Specified by:
isSecurein interfaceServletRequest
-
isUserInRole
public boolean isUserInRole(String role)
- Specified by:
isUserInRolein interfaceHttpServletRequest
-
-