Package mondrian.tui
Class MockHttpServletRequest
- java.lang.Object
-
- mondrian.tui.MockHttpServletRequest
-
- All Implemented Interfaces:
HttpServletRequest,ServletRequest
public class MockHttpServletRequest extends Object implements HttpServletRequest
Partial implementation of theHttpServletRequestwhere just enough is present to allow for communication between Mondrian's XMLA code and other code in the same JVM.Currently it is used in both the CmdRunner and in XMLA JUnit tests. If you need to add to this implementation, please do so.
- Author:
- Richard M. Emberson
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classMockHttpServletRequest.MockRequestDispatcher(package private) static classMockHttpServletRequest.MockServletInputStream
-
Field Summary
Fields Modifier and Type Field Description static StringAUTHORIZATIONstatic StringDATE_FORMAT_HEADER-
Fields inherited from interface javax.servlet.http.HttpServletRequest
BASIC_AUTH, CLIENT_CERT_AUTH, DIGEST_AUTH, FORM_AUTH
-
-
Constructor Summary
Constructors Constructor Description MockHttpServletRequest()MockHttpServletRequest(byte[] bytes)MockHttpServletRequest(String bodyContent)
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description voidaddCookie(Cookie cookie)voidaddHeader(String key, String value)voidaddLocale(Locale locale)voidaddLocales(List<Locale> localeList)booleanauthenticate(HttpServletResponse response)StringchangeSessionId()voidclearAttributes()voidclearHeader(String key)voidclearParameters()AsyncContextgetAsyncContext()ObjectgetAttribute(String name)Returns the value of the named attribute as an Object, or null if no attribute of the given name exists.EnumerationgetAttributeNames()to this request.StringgetAuthType()Returns the name of the authentication scheme used to protect the servlet, for example, "BASIC" or "SSL," or null if the servlet was not protected.StringgetCharacterEncoding()Returns the name of the character encoding used in the body of this request.intgetContentLength()Returns the length, in bytes, of the request body and made available by the input stream, or -1 if the length is not known.longgetContentLengthLong()StringgetContentType()Returns the MIME type of the body of the request, or null if the type is not known.StringgetContextPath()Returns the portion of the request URI that indicates the context of the request.Cookie[]getCookies()Returns an array containing all of the Cookie objects the client sent with this request.longgetDateHeader(String name)Returns the value of the specified request header as a long value that represents a Date object.DispatcherTypegetDispatcherType()StringgetHeader(String name)Returns the value of the specified request header as a String.EnumerationgetHeaderNames()Returns an enumeration of all the header names this request contains.EnumerationgetHeaders(String name)Returns all the values of the specified request header as an Enumeration of String objects.ServletInputStreamgetInputStream()Retrieves the body of the request as binary data using a ServletInputStream.intgetIntHeader(String name)Returns the value of the specified request header as an int.StringgetLocalAddr()LocalegetLocale()Returns the preferred Locale that the client will accept content in, based on the Accept-Language header.EnumerationgetLocales()Returns an Enumeration of Locale objects indicating, in decreasing order starting with the preferred locale, the locales that are acceptable to the client based on the Accept-Language header.StringgetLocalName()intgetLocalPort()StringgetMethod()Returns the name of the HTTP method with which this request was made, for example, GET, POST, or PUT.StringgetParameter(String name)Returns the value of a request parameter as a String, or null if the parameter does not exist.MapgetParameterMap()EnumerationgetParameterNames()Returns an Enumeration of String objects containing the names of the parameters contained in this request.String[]getParameterValues(String name)Returns an array of String objects containing all of the values the given request parameter has, or null if the parameter does not exist.PartgetPart(String name)Collection<Part>getParts()StringgetPathInfo()Returns any extra path information associated with the URL the client sent when it made this request.StringgetPathTranslated()Returns any extra path information after the servlet name but before the query string, and translates it to a real path.StringgetProtocol()Returns the name and version of the protocol the request uses in the form protocol/majorVersion.minorVersion, for example, HTTP/1.1.StringgetQueryString()Returns the query string that is contained in the request URL after the path.BufferedReadergetReader()Retrieves the body of the request as character data using a BufferedReader.StringgetRealPath(String path)Deprecated.Method getRealPath is deprecatedStringgetRemoteAddr()Returns the Internet Protocol (IP) address of the client that sent the request.StringgetRemoteHost()Returns the fully qualified name of the client that sent the request, or the IP address of the client if the name cannot be determined.intgetRemotePort()StringgetRemoteUser()Returns the login of the user making this request, if the user has been authenticated, or null if the user has not been authenticated.RequestDispatchergetRequestDispatcher(String path)Returns a RequestDispatcher object that acts as a wrapper for the resource located at the given path.Map<String,RequestDispatcher>getRequestDispatcherMap()StringgetRequestedSessionId()Returns the session ID specified by the client.StringgetRequestURI()Returns the part of this request's URL from the protocol name up to the query string in the first line of the HTTP request.StringBuffergetRequestURL()StringgetScheme()Returns the name of the scheme used to make this request, for example, http, https, or ftp.StringgetServerName()Returns the host name of the server that received the request.intgetServerPort()Returns the port number on which this request was received.ServletContextgetServletContext()StringgetServletPath()Returns the part of this request's URL that calls the servlet.HttpSessiongetSession()Returns the current session associated with this request, or if the request does not have a session, creates one.HttpSessiongetSession(boolean create)Returns the current HttpSession associated with this request or, if if there is no current session and create is true, returns a new session.PrincipalgetUserPrincipal()Returns a java.security.Principal object containing the name of the current authenticated user.booleanisAsyncStarted()booleanisAsyncSupported()booleanisRequestedSessionIdFromCookie()Checks whether the requested session ID came in as a cookie.booleanisRequestedSessionIdFromUrl()booleanisRequestedSessionIdFromURL()Checks whether the requested session ID came in as part of the request URL.booleanisRequestedSessionIdValid()Checks whether the requested session ID is still valid.booleanisSecure()Returns a boolean indicating whether this request was made using a secure channel, such as HTTPS.booleanisUserInRole(String role)Returns a boolean indicating whether the authenticated user is included in the specified logical "role".voidlogin(String username, String password)voidlogout()voidremoveAttribute(String name)Removes an attribute from this request.voidsetAttribute(String name, Object obj)Stores an attribute in this request.voidsetAuthType(String authType)voidsetBodyContent(byte[] data)voidsetBodyContent(String bodyContent)voidsetCharacterEncoding(String charEncoding)voidsetContentType(String contentType)voidsetContextPath(String contextPath)voidsetHeader(String name, String value)voidsetLocalAddr(String localAddr)voidsetLocalName(String localName)voidsetLocalPort(int localPort)voidsetMethod(String method)voidsetPathInfo(String pathInfo)voidsetPathTranslated(String pathTranslated)voidsetProtocol(String protocol)voidsetQueryString(String queryString)voidsetRemoteAddr(String remoteAddr)voidsetRemoteHost(String remoteHost)voidsetRemotePort(int remotePort)voidsetRemoteUser(String remoteUser)voidsetRequestDispatcher(String path, RequestDispatcher dispatcher)voidsetRequestedSessionId(String requestedSessionId)voidsetRequestedSessionIdFromCookie(boolean requestedSessionIdIsFromCookie)voidsetRequestURI(String requestedURI)voidsetRequestURL(String requestUrl)voidsetScheme(String schema)voidsetServerName(String serverName)voidsetServerPort(int serverPort)voidsetServletPath(String servletPath)voidsetSession(HttpSession session)voidsetupAddParameter(String key, String value)voidsetupAddParameter(String key, String[] values)voidsetUserInRole(String role, boolean isInRole)voidsetUserPrincipal(Principal principal)AsyncContextstartAsync()AsyncContextstartAsync(ServletRequest servletRequest, ServletResponse servletResponse)<T extends HttpUpgradeHandler>
Tupgrade(Class<T> handlerClass)-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface javax.servlet.http.HttpServletRequest
getHttpServletMapping, getTrailerFields, isTrailerFieldsReady, newPushBuilder
-
-
-
-
Field Detail
-
AUTHORIZATION
public static String AUTHORIZATION
-
DATE_FORMAT_HEADER
public static final String DATE_FORMAT_HEADER
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
MockHttpServletRequest
public MockHttpServletRequest()
-
MockHttpServletRequest
public MockHttpServletRequest(byte[] bytes)
-
MockHttpServletRequest
public MockHttpServletRequest(String bodyContent)
-
-
Method Detail
-
getAttribute
public Object getAttribute(String name)
Returns the value of the named attribute as an Object, or null if no attribute of the given name exists.- Specified by:
getAttributein interfaceServletRequest
-
getAttributeNames
public Enumeration getAttributeNames()
to this request.- Specified by:
getAttributeNamesin interfaceServletRequest
-
getCharacterEncoding
public String getCharacterEncoding()
Returns the name of the character encoding used in the body of this request.- Specified by:
getCharacterEncodingin interfaceServletRequest
-
setCharacterEncoding
public void setCharacterEncoding(String charEncoding) throws UnsupportedEncodingException
- Specified by:
setCharacterEncodingin interfaceServletRequest- Throws:
UnsupportedEncodingException
-
getContentLength
public int getContentLength()
Returns the length, in bytes, of the request body and made available by the input stream, or -1 if the length is not known.- Specified by:
getContentLengthin interfaceServletRequest
-
getContentType
public String getContentType()
Returns the MIME type of the body of the request, or null if the type is not known.- Specified by:
getContentTypein interfaceServletRequest
-
getInputStream
public ServletInputStream getInputStream() throws IOException
Retrieves the body of the request as binary data using a ServletInputStream.- Specified by:
getInputStreamin interfaceServletRequest- Throws:
IOException
-
getParameter
public String getParameter(String name)
Returns the value of a request parameter as a String, or null if the parameter does not exist.- Specified by:
getParameterin interfaceServletRequest
-
getParameterNames
public Enumeration getParameterNames()
Returns an Enumeration of String objects containing the names of the parameters contained in this request.- Specified by:
getParameterNamesin interfaceServletRequest
-
getParameterValues
public String[] getParameterValues(String name)
Returns an array of String objects containing all of the values the given request parameter has, or null if the parameter does not exist.- Specified by:
getParameterValuesin interfaceServletRequest
-
getProtocol
public String getProtocol()
Returns the name and version of the protocol the request uses in the form protocol/majorVersion.minorVersion, for example, HTTP/1.1.- Specified by:
getProtocolin interfaceServletRequest
-
getScheme
public String getScheme()
Returns the name of the scheme used to make this request, for example, http, https, or ftp.- Specified by:
getSchemein interfaceServletRequest
-
getServerName
public String getServerName()
Returns the host name of the server that received the request.- Specified by:
getServerNamein interfaceServletRequest
-
getServerPort
public int getServerPort()
Returns the port number on which this request was received.- Specified by:
getServerPortin interfaceServletRequest
-
getReader
public BufferedReader getReader() throws IOException
Retrieves the body of the request as character data using a BufferedReader.- Specified by:
getReaderin interfaceServletRequest- Throws:
IOException
-
getRemoteAddr
public String getRemoteAddr()
Returns the Internet Protocol (IP) address of the client that sent the request.- Specified by:
getRemoteAddrin interfaceServletRequest
-
getRemoteHost
public String getRemoteHost()
Returns the fully qualified name of the client that sent the request, or the IP address of the client if the name cannot be determined.- Specified by:
getRemoteHostin interfaceServletRequest
-
setAttribute
public void setAttribute(String name, Object obj)
Stores an attribute in this request.- Specified by:
setAttributein interfaceServletRequest
-
removeAttribute
public void removeAttribute(String name)
Removes an attribute from this request.- Specified by:
removeAttributein interfaceServletRequest
-
getLocale
public Locale getLocale()
Returns the preferred Locale that the client will accept content in, based on the Accept-Language header.- Specified by:
getLocalein interfaceServletRequest
-
getLocales
public Enumeration getLocales()
Returns an Enumeration of Locale objects indicating, in decreasing order starting with the preferred locale, the locales that are acceptable to the client based on the Accept-Language header.- Specified by:
getLocalesin interfaceServletRequest
-
isSecure
public boolean isSecure()
Returns a boolean indicating whether this request was made using a secure channel, such as HTTPS.- Specified by:
isSecurein interfaceServletRequest
-
getRequestDispatcher
public RequestDispatcher getRequestDispatcher(String path)
Returns a RequestDispatcher object that acts as a wrapper for the resource located at the given path.- Specified by:
getRequestDispatcherin interfaceServletRequest
-
getRealPath
public String getRealPath(String path)
Deprecated.Method getRealPath is deprecatedDeprecated. As of Version 2.1 of the Java Servlet API, use ServletContext.getRealPath(java.lang.String) instead.- Specified by:
getRealPathin interfaceServletRequest
-
getRemotePort
public int getRemotePort()
- Specified by:
getRemotePortin interfaceServletRequest
-
getLocalName
public String getLocalName()
- Specified by:
getLocalNamein interfaceServletRequest
-
getLocalAddr
public String getLocalAddr()
- Specified by:
getLocalAddrin interfaceServletRequest
-
getLocalPort
public int getLocalPort()
- Specified by:
getLocalPortin interfaceServletRequest
-
getAuthType
public String getAuthType()
Returns the name of the authentication scheme used to protect the servlet, for example, "BASIC" or "SSL," or null if the servlet was not protected.- Specified by:
getAuthTypein interfaceHttpServletRequest
-
getCookies
public Cookie[] getCookies()
Returns an array containing all of the Cookie objects the client sent with this request.- Specified by:
getCookiesin interfaceHttpServletRequest
-
getDateHeader
public long getDateHeader(String name)
Returns the value of the specified request header as a long value that represents a Date object.- Specified by:
getDateHeaderin interfaceHttpServletRequest
-
getHeader
public String getHeader(String name)
Returns the value of the specified request header as a String.- Specified by:
getHeaderin interfaceHttpServletRequest
-
getHeaders
public Enumeration getHeaders(String name)
Returns all the values of the specified request header as an Enumeration of String objects.- Specified by:
getHeadersin interfaceHttpServletRequest
-
getHeaderNames
public Enumeration getHeaderNames()
Returns an enumeration of all the header names this request contains.- Specified by:
getHeaderNamesin interfaceHttpServletRequest
-
getIntHeader
public int getIntHeader(String name)
Returns the value of the specified request header as an int.- Specified by:
getIntHeaderin interfaceHttpServletRequest
-
getMethod
public String getMethod()
Returns the name of the HTTP method with which this request was made, for example, GET, POST, or PUT.- Specified by:
getMethodin interfaceHttpServletRequest
-
getPathInfo
public String getPathInfo()
Returns any extra path information associated with the URL the client sent when it made this request.- Specified by:
getPathInfoin interfaceHttpServletRequest
-
getPathTranslated
public String getPathTranslated()
Returns any extra path information after the servlet name but before the query string, and translates it to a real path.- Specified by:
getPathTranslatedin interfaceHttpServletRequest
-
getContextPath
public String getContextPath()
Returns the portion of the request URI that indicates the context of the request.- Specified by:
getContextPathin interfaceHttpServletRequest
-
getQueryString
public String getQueryString()
Returns the query string that is contained in the request URL after the path.- Specified by:
getQueryStringin interfaceHttpServletRequest
-
getRemoteUser
public String getRemoteUser()
Returns the login of the user making this request, if the user has been authenticated, or null if the user has not been authenticated.- Specified by:
getRemoteUserin interfaceHttpServletRequest
-
isUserInRole
public boolean isUserInRole(String role)
Returns a boolean indicating whether the authenticated user is included in the specified logical "role".- Specified by:
isUserInRolein interfaceHttpServletRequest
-
getUserPrincipal
public Principal getUserPrincipal()
Returns a java.security.Principal object containing the name of the current authenticated user.- Specified by:
getUserPrincipalin interfaceHttpServletRequest
-
getRequestedSessionId
public String getRequestedSessionId()
Returns the session ID specified by the client.- Specified by:
getRequestedSessionIdin interfaceHttpServletRequest
-
getRequestURI
public String getRequestURI()
Returns the part of this request's URL from the protocol name up to the query string in the first line of the HTTP request.- Specified by:
getRequestURIin interfaceHttpServletRequest
-
getRequestURL
public StringBuffer getRequestURL()
- Specified by:
getRequestURLin interfaceHttpServletRequest
-
getServletPath
public String getServletPath()
Returns the part of this request's URL that calls the servlet.- Specified by:
getServletPathin interfaceHttpServletRequest
-
getSession
public HttpSession getSession(boolean create)
Returns the current HttpSession associated with this request or, if if there is no current session and create is true, returns a new session.- Specified by:
getSessionin interfaceHttpServletRequest
-
getSession
public HttpSession getSession()
Returns the current session associated with this request, or if the request does not have a session, creates one.- Specified by:
getSessionin interfaceHttpServletRequest
-
isRequestedSessionIdValid
public boolean isRequestedSessionIdValid()
Checks whether the requested session ID is still valid.- Specified by:
isRequestedSessionIdValidin interfaceHttpServletRequest
-
isRequestedSessionIdFromCookie
public boolean isRequestedSessionIdFromCookie()
Checks whether the requested session ID came in as a cookie.- Specified by:
isRequestedSessionIdFromCookiein interfaceHttpServletRequest
-
isRequestedSessionIdFromURL
public boolean isRequestedSessionIdFromURL()
Checks whether the requested session ID came in as part of the request URL.- Specified by:
isRequestedSessionIdFromURLin interfaceHttpServletRequest
-
isRequestedSessionIdFromUrl
public boolean isRequestedSessionIdFromUrl()
- Specified by:
isRequestedSessionIdFromUrlin interfaceHttpServletRequest
-
getParameterMap
public Map getParameterMap()
- Specified by:
getParameterMapin interfaceServletRequest
-
setServerName
public void setServerName(String serverName)
-
setRemoteHost
public void setRemoteHost(String remoteHost)
-
setRemoteAddr
public void setRemoteAddr(String remoteAddr)
-
setMethod
public void setMethod(String method)
-
setPathInfo
public void setPathInfo(String pathInfo)
-
setPathTranslated
public void setPathTranslated(String pathTranslated)
-
setContextPath
public void setContextPath(String contextPath)
-
setQueryString
public void setQueryString(String queryString)
-
setRemoteUser
public void setRemoteUser(String remoteUser)
-
setRequestedSessionId
public void setRequestedSessionId(String requestedSessionId)
-
setRequestURI
public void setRequestURI(String requestedURI)
-
setServletPath
public void setServletPath(String servletPath)
-
setLocalName
public void setLocalName(String localName)
-
setLocalAddr
public void setLocalAddr(String localAddr)
-
setAuthType
public void setAuthType(String authType)
-
setProtocol
public void setProtocol(String protocol)
-
setScheme
public void setScheme(String schema)
-
setRemotePort
public void setRemotePort(int remotePort)
-
setLocalPort
public void setLocalPort(int localPort)
-
setServerPort
public void setServerPort(int serverPort)
-
setContentType
public void setContentType(String contentType)
-
clearParameters
public void clearParameters()
-
clearAttributes
public void clearAttributes()
-
setSession
public void setSession(HttpSession session)
-
getRequestDispatcherMap
public Map<String,RequestDispatcher> getRequestDispatcherMap()
-
setRequestDispatcher
public void setRequestDispatcher(String path, RequestDispatcher dispatcher)
-
addLocale
public void addLocale(Locale locale)
-
clearHeader
public void clearHeader(String key)
-
setRequestURL
public void setRequestURL(String requestUrl)
-
setUserPrincipal
public void setUserPrincipal(Principal principal)
-
addCookie
public void addCookie(Cookie cookie)
-
setRequestedSessionIdFromCookie
public void setRequestedSessionIdFromCookie(boolean requestedSessionIdIsFromCookie)
-
setUserInRole
public void setUserInRole(String role, boolean isInRole)
-
setBodyContent
public void setBodyContent(byte[] data)
-
setBodyContent
public void setBodyContent(String bodyContent)
-
changeSessionId
public String changeSessionId()
- Specified by:
changeSessionIdin interfaceHttpServletRequest
-
authenticate
public boolean authenticate(HttpServletResponse response) throws IOException, ServletException
- Specified by:
authenticatein interfaceHttpServletRequest- Throws:
IOExceptionServletException
-
login
public void login(String username, String password) throws ServletException
- Specified by:
loginin interfaceHttpServletRequest- Throws:
ServletException
-
logout
public void logout() throws ServletException- Specified by:
logoutin interfaceHttpServletRequest- Throws:
ServletException
-
getParts
public Collection<Part> getParts() throws IOException, ServletException
- Specified by:
getPartsin interfaceHttpServletRequest- Throws:
IOExceptionServletException
-
getPart
public Part getPart(String name) throws IOException, ServletException
- Specified by:
getPartin interfaceHttpServletRequest- Throws:
IOExceptionServletException
-
upgrade
public <T extends HttpUpgradeHandler> T upgrade(Class<T> handlerClass) throws IOException, ServletException
- Specified by:
upgradein interfaceHttpServletRequest- Throws:
IOExceptionServletException
-
getContentLengthLong
public long getContentLengthLong()
- Specified by:
getContentLengthLongin interfaceServletRequest
-
getServletContext
public ServletContext getServletContext()
- Specified by:
getServletContextin interfaceServletRequest
-
startAsync
public AsyncContext startAsync() throws IllegalStateException
- Specified by:
startAsyncin interfaceServletRequest- Throws:
IllegalStateException
-
startAsync
public AsyncContext startAsync(ServletRequest servletRequest, ServletResponse servletResponse) throws IllegalStateException
- Specified by:
startAsyncin interfaceServletRequest- Throws:
IllegalStateException
-
isAsyncStarted
public boolean isAsyncStarted()
- Specified by:
isAsyncStartedin interfaceServletRequest
-
isAsyncSupported
public boolean isAsyncSupported()
- Specified by:
isAsyncSupportedin interfaceServletRequest
-
getAsyncContext
public AsyncContext getAsyncContext()
- Specified by:
getAsyncContextin interfaceServletRequest
-
getDispatcherType
public DispatcherType getDispatcherType()
- Specified by:
getDispatcherTypein interfaceServletRequest
-
-