org.jboss.jsfunit.context
Class JSFUnitHttpServletRequest

java.lang.Object
  extended by org.jboss.jsfunit.context.JSFUnitHttpServletRequest
All Implemented Interfaces:
javax.servlet.http.HttpServletRequest, javax.servlet.ServletRequest

public class JSFUnitHttpServletRequest
extends Object
implements javax.servlet.http.HttpServletRequest

This class takes the same approach as the JSFUnitExternalContext in that it caches everything possible from the HttpServletRequest so that it will be available to the JSFUnit test. For a few methods, it is impossible or impractical to provide an implementation because the request is finished and the servlet container is free to recycle the original HttpServletRequest. So a few methods throw UnsupportedOperationException. A few methods also warn that using them can lead to unexpected results. Those methods that are unreliable have a warning in the javadoc.

Since:
1.0
Author:
Stan Silvert

Field Summary
 
Fields inherited from interface javax.servlet.http.HttpServletRequest
BASIC_AUTH, CLIENT_CERT_AUTH, DIGEST_AUTH, FORM_AUTH
 
Constructor Summary
JSFUnitHttpServletRequest(JSFUnitExternalContext extCtx, javax.servlet.http.HttpServletRequest request)
           
 
Method Summary
 boolean authenticate(javax.servlet.http.HttpServletResponse response)
          This method not supported.
 javax.servlet.AsyncContext getAsyncContext()
           
 Object getAttribute(String name)
           
 Enumeration getAttributeNames()
           
 String getAuthType()
           
 String getCharacterEncoding()
           
 int getContentLength()
           
 String getContentType()
           
 String getContextPath()
           
 javax.servlet.http.Cookie[] getCookies()
           
 long getDateHeader(String name)
           
 javax.servlet.DispatcherType getDispatcherType()
           
 String getHeader(String name)
           
 Enumeration getHeaderNames()
           
 Enumeration getHeaders(String name)
           
 javax.servlet.ServletInputStream getInputStream()
           
 int getIntHeader(String name)
           
 String getLocalAddr()
           
 Locale getLocale()
           
 Enumeration getLocales()
           
 String getLocalName()
           
 int getLocalPort()
           
 String getMethod()
           
 String getParameter(String name)
           
 Map getParameterMap()
           
 Enumeration getParameterNames()
           
 String[] getParameterValues(String name)
           
 javax.servlet.http.Part getPart(String part)
          This method not supported yet.
 Collection<javax.servlet.http.Part> getParts()
          This method not supported yet.
 String getPathInfo()
           
 String getPathTranslated()
           
 String getProtocol()
           
 String getQueryString()
           
 BufferedReader getReader()
           
 String getRealPath(String string)
           
 String getRemoteAddr()
           
 String getRemoteHost()
           
 int getRemotePort()
           
 String getRemoteUser()
           
 javax.servlet.RequestDispatcher getRequestDispatcher(String string)
           
 String getRequestedSessionId()
           
 String getRequestURI()
           
 StringBuffer getRequestURL()
           
 String getScheme()
           
 String getServerName()
           
 int getServerPort()
           
 javax.servlet.ServletContext getServletContext()
           
 String getServletPath()
           
 javax.servlet.http.HttpSession getSession()
           
 javax.servlet.http.HttpSession getSession(boolean create)
           
 Principal getUserPrincipal()
           
 boolean isAsyncStarted()
           
 boolean isAsyncSupported()
           
 boolean isRequestedSessionIdFromCookie()
           
 boolean isRequestedSessionIdFromUrl()
           
 boolean isRequestedSessionIdFromURL()
           
 boolean isRequestedSessionIdValid()
           
 boolean isSecure()
           
 boolean isUserInRole(String name)
          Warning: This method could yield unexpected results.
 void login(String username, String password)
          This method not supported.
 void logout()
          This method not supported.
 void removeAttribute(String name)
           
 void setAttribute(String attribute, Object value)
           
 void setCharacterEncoding(String string)
          This method is a no-op.
 javax.servlet.AsyncContext startAsync()
           
 javax.servlet.AsyncContext startAsync(javax.servlet.ServletRequest servletRequest, javax.servlet.ServletResponse servletResponse)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JSFUnitHttpServletRequest

public JSFUnitHttpServletRequest(JSFUnitExternalContext extCtx,
                                 javax.servlet.http.HttpServletRequest request)
Method Detail

getQueryString

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

getProtocol

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

getPathTranslated

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

getPathInfo

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

getParameterNames

public Enumeration getParameterNames()
Specified by:
getParameterNames in interface javax.servlet.ServletRequest

getParameterMap

public Map getParameterMap()
Specified by:
getParameterMap in interface javax.servlet.ServletRequest

getMethod

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

getLocales

public Enumeration getLocales()
Specified by:
getLocales in interface javax.servlet.ServletRequest

getLocale

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

getAttributeNames

public Enumeration getAttributeNames()
Specified by:
getAttributeNames in interface javax.servlet.ServletRequest

getAuthType

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

getCharacterEncoding

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

getContentLength

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

getContentType

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

getContextPath

public 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

getHeaderNames

public Enumeration getHeaderNames()
Specified by:
getHeaderNames in interface javax.servlet.http.HttpServletRequest

getInputStream

public javax.servlet.ServletInputStream getInputStream()
                                                throws IOException
Specified by:
getInputStream in interface javax.servlet.ServletRequest
Throws:
UnsupportedOperationException
IOException

getReader

public BufferedReader getReader()
                         throws IOException
Specified by:
getReader in interface javax.servlet.ServletRequest
Throws:
UnsupportedOperationException
IOException

getRemoteAddr

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

getRemoteHost

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

getRemoteUser

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

getRequestURI

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

getRequestURL

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

getRequestedSessionId

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

getScheme

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

getServerName

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

getServerPort

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

getServletPath

public 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

getUserPrincipal

public 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

isSecure

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

getSession

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

setAttribute

public void setAttribute(String attribute,
                         Object value)
Specified by:
setAttribute in interface javax.servlet.ServletRequest

setCharacterEncoding

public void setCharacterEncoding(String string)
                          throws UnsupportedEncodingException
This method is a no-op. Since the response is over by the time this object is active, it is too late to override the name of the character encoding.

Specified by:
setCharacterEncoding in interface javax.servlet.ServletRequest
Throws:
UnsupportedEncodingException

getParameterValues

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

getParameter

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

getIntHeader

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

getAttribute

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

getDateHeader

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

getHeader

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

getHeaders

public Enumeration getHeaders(String name)
Specified by:
getHeaders in interface javax.servlet.http.HttpServletRequest

getRealPath

public String getRealPath(String string)
Specified by:
getRealPath in interface javax.servlet.ServletRequest
Throws:
UnsupportedOperationException

getRequestDispatcher

public javax.servlet.RequestDispatcher getRequestDispatcher(String string)
Specified by:
getRequestDispatcher in interface javax.servlet.ServletRequest
Throws:
UnsupportedOperationException

isUserInRole

public boolean isUserInRole(String name)
Warning: This method could yield unexpected results.

Specified by:
isUserInRole in interface javax.servlet.http.HttpServletRequest

removeAttribute

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

getLocalPort

public int getLocalPort()
Throws:
UnsupportedOperationException - if running in a container that does not support servlet 2.4 or greater.

getRemotePort

public int getRemotePort()
Throws:
UnsupportedOperationException - if running in a container that does not support servlet 2.4 or greater.

getLocalName

public String getLocalName()
Throws:
UnsupportedOperationException - if running in a container that does not support servlet 2.4 or greater.

getLocalAddr

public String getLocalAddr()
Throws:
UnsupportedOperationException - if running in a container that does not support servlet 2.4 or greater.

getPart

public javax.servlet.http.Part getPart(String part)
This method not supported yet.

Throws:
UnsupportedOperationException

getParts

public Collection<javax.servlet.http.Part> getParts()
This method not supported yet.

Throws:
UnsupportedOperationException

logout

public void logout()
            throws javax.servlet.ServletException
This method not supported.

Throws:
UnsupportedOperationException
javax.servlet.ServletException

login

public void login(String username,
                  String password)
           throws javax.servlet.ServletException
This method not supported.

Throws:
UnsupportedOperationException
javax.servlet.ServletException

authenticate

public boolean authenticate(javax.servlet.http.HttpServletResponse response)
                     throws IOException,
                            javax.servlet.ServletException
This method not supported.

Throws:
UnsupportedOperationException
IOException
javax.servlet.ServletException

getDispatcherType

public javax.servlet.DispatcherType getDispatcherType()

getAsyncContext

public javax.servlet.AsyncContext getAsyncContext()

isAsyncStarted

public boolean isAsyncStarted()

isAsyncSupported

public boolean isAsyncSupported()

startAsync

public javax.servlet.AsyncContext startAsync()

startAsync

public javax.servlet.AsyncContext startAsync(javax.servlet.ServletRequest servletRequest,
                                             javax.servlet.ServletResponse servletResponse)
                                      throws IllegalStateException
Throws:
IllegalStateException

getServletContext

public javax.servlet.ServletContext getServletContext()


Copyright © 2007-2010 JBoss, a division of Red Hat, Inc.. All Rights Reserved.