Class WebRequest

java.lang.Object
javax.servlet.ServletRequestWrapper
javax.servlet.http.HttpServletRequestWrapper
eu.webtoolkit.jwt.servlet.WebRequest
All Implemented Interfaces:
javax.servlet.http.HttpServletRequest, javax.servlet.ServletRequest

public class WebRequest
extends javax.servlet.http.HttpServletRequestWrapper
A WebRequest which wraps the HttpServletRequest to add support for file uploads and testing.

WebRequest is used instead of HttpServletRequest inside JWt's request handling, and also in WResource.handleRequest(WebRequest request, WebResponse response). It handles files being POST'ed, and treats parameters in the URL or within the request body in the same way.

See Also:
WebResponse
  • Nested Class Summary

    Nested Classes
    Modifier and Type Class Description
    static interface  WebRequest.ProgressListener
    Progress listener interface.
    static class  WebRequest.ReadEvent
    Enumeration for a WebSocket read event (not yet implemented).
    static class  WebRequest.ResponseType
    The type of response that this request will need.
  • Field Summary

    Fields inherited from interface javax.servlet.http.HttpServletRequest

    BASIC_AUTH, CLIENT_CERT_AUTH, DIGEST_AUTH, FORM_AUTH
  • Constructor Summary

    Constructors
    Constructor Description
    WebRequest​(java.util.Map<java.lang.String,​java.lang.String[]> parameters, java.util.Map<java.lang.String,​java.util.List<UploadedFile>> files)
    Creates a mock WebRequest given list of parameters and a list of POST'ed files.
    WebRequest​(javax.servlet.http.HttpServletRequest request, WebRequest.ProgressListener progressListener, Configuration configuration)
    Creates a WebRequest by wrapping an HttpServletRequest
  • Method Summary

    Modifier and Type Method Description
    static java.lang.String computePathInfo​(javax.servlet.http.HttpServletRequest request, Configuration configuration)  
    static java.lang.String computePathInfo​(javax.servlet.http.HttpServletRequest request, java.lang.String scriptName, Configuration configuration)  
    static java.lang.String computeScriptName​(javax.servlet.http.HttpServletRequest request, Configuration configuration)  
    java.lang.String getClientAddress​(boolean behindReverseProxy)  
    java.lang.String getHeaderValue​(java.lang.String header)
    Returns a header value.
    java.lang.String getParameter​(java.lang.String name)
    Returns the parameter value for a parameter's name.
    java.util.Map<java.lang.String,​java.lang.String[]> getParameterMap()
    Returns the parameter map.
    java.lang.String[] getParameterValues​(java.lang.String name)
    Returns the parameter values for a parameter.
    java.lang.String getPathInfo()
    Returns the internal path information.
    java.lang.String getRequestMethod()
    Returns the request method.
    java.lang.String getScriptName()
    Returns the script name.
    java.util.Map<java.lang.String,​java.util.List<UploadedFile>> getUploadedFiles()
    Returns the list of uploaded files.
    java.lang.String getUserAgent()
    Accesses to specific header fields (calls getHeaderValue()).
    boolean isWebSocketMessage()
    Returns whether this request is a WebSocket message.
    boolean isWebSocketRequest()
    Returns whether this request is a WebSocket request.
    protected void readParameters​(byte[] buf)
    Read and store query parameters

    Methods inherited from class javax.servlet.http.HttpServletRequestWrapper

    authenticate, getAuthType, getContextPath, getCookies, getDateHeader, getHeader, getHeaderNames, getHeaders, getIntHeader, getMethod, getPart, getParts, getPathTranslated, getQueryString, getRemoteUser, getRequestedSessionId, getRequestURI, getRequestURL, getServletPath, getSession, getSession, getUserPrincipal, isRequestedSessionIdFromCookie, isRequestedSessionIdFromUrl, isRequestedSessionIdFromURL, isRequestedSessionIdValid, isUserInRole, login, logout

    Methods inherited from class javax.servlet.ServletRequestWrapper

    getAsyncContext, getAttribute, getAttributeNames, getCharacterEncoding, getContentLength, getContentType, getDispatcherType, getInputStream, getLocalAddr, getLocale, getLocales, getLocalName, getLocalPort, getParameterNames, getProtocol, getReader, getRealPath, getRemoteAddr, getRemoteHost, getRemotePort, getRequest, getRequestDispatcher, getScheme, getServerName, getServerPort, getServletContext, isAsyncStarted, isAsyncSupported, isSecure, isWrapperFor, isWrapperFor, removeAttribute, setAttribute, setCharacterEncoding, setRequest, startAsync, startAsync

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface javax.servlet.ServletRequest

    getAsyncContext, getAttribute, getAttributeNames, getCharacterEncoding, getContentLength, getContentType, getDispatcherType, getInputStream, getLocalAddr, getLocale, getLocales, getLocalName, getLocalPort, getParameterNames, getProtocol, getReader, getRealPath, getRemoteAddr, getRemoteHost, getRemotePort, getRequestDispatcher, getScheme, getServerName, getServerPort, getServletContext, isAsyncStarted, isAsyncSupported, isSecure, removeAttribute, setAttribute, setCharacterEncoding, startAsync, startAsync
  • Constructor Details

    • WebRequest

      public WebRequest​(javax.servlet.http.HttpServletRequest request, WebRequest.ProgressListener progressListener, Configuration configuration)
      Creates a WebRequest by wrapping an HttpServletRequest
      Parameters:
      request - The request to be wrapped.
      progressListener - a progress listener implementation
      configuration -
    • WebRequest

      public WebRequest​(java.util.Map<java.lang.String,​java.lang.String[]> parameters, java.util.Map<java.lang.String,​java.util.List<UploadedFile>> files)
      Creates a mock WebRequest given list of parameters and a list of POST'ed files.
      Parameters:
      parameters - a list of request parameters
      files - a list of POST'ed files
  • Method Details

    • computeScriptName

      public static java.lang.String computeScriptName​(javax.servlet.http.HttpServletRequest request, Configuration configuration)
    • computePathInfo

      public static java.lang.String computePathInfo​(javax.servlet.http.HttpServletRequest request, Configuration configuration)
    • computePathInfo

      public static java.lang.String computePathInfo​(javax.servlet.http.HttpServletRequest request, java.lang.String scriptName, Configuration configuration)
    • getRequestMethod

      public java.lang.String getRequestMethod()
      Returns the request method.
    • getScriptName

      public java.lang.String getScriptName()
      Returns the script name.

      This returns in principle HttpServletRequestWrapper.getContextPath() + HttpServletRequestWrapper.getServletPath(), but with workaround code for corner cases and container workarounds.

      Returns:
      the url at which the application is deployed
    • getHeaderValue

      public java.lang.String getHeaderValue​(java.lang.String header)
      Returns a header value.

      Returns the corresponding header value, using HttpServletRequestWrapper.getHeader(String) or null if the header value is not present

      Parameters:
      header - the header name
      Returns:
      the header value, or null.
    • getUserAgent

      public java.lang.String getUserAgent()
      Accesses to specific header fields (calls getHeaderValue()).
    • getPathInfo

      public java.lang.String getPathInfo()
      Returns the internal path information.

      Returns the HttpServletRequestWrapper.getPathInfo() or the empty string if there is no internal path in the request. This method also uses workarounds for corner cases for some servlet containers.

      Specified by:
      getPathInfo in interface javax.servlet.http.HttpServletRequest
      Overrides:
      getPathInfo in class javax.servlet.http.HttpServletRequestWrapper
      Returns:
      the internal path information, or an empty string if there is no internal path.
    • readParameters

      protected void readParameters​(byte[] buf)
      Read and store query parameters
      Parameters:
      buf - UTF-8 encoded byte array with the URI query part
    • getUploadedFiles

      public java.util.Map<java.lang.String,​java.util.List<UploadedFile>> getUploadedFiles()
      Returns the list of uploaded files.
      Returns:
      the list of uploaded files.
    • getParameterMap

      public java.util.Map<java.lang.String,​java.lang.String[]> getParameterMap()
      Returns the parameter map.

      The parameter map includes both the parameters from the query string, as well as parameters posted in the body.

      Specified by:
      getParameterMap in interface javax.servlet.ServletRequest
      Overrides:
      getParameterMap in class javax.servlet.ServletRequestWrapper
    • getParameterValues

      public java.lang.String[] getParameterValues​(java.lang.String name)
      Returns the parameter values for a parameter.

      Returns an array of parameters values given for a particular parameter. When no parameter value was assigned to the parameter, an empty array is returned.

      Specified by:
      getParameterValues in interface javax.servlet.ServletRequest
      Overrides:
      getParameterValues in class javax.servlet.ServletRequestWrapper
      See Also:
      getParameterMap()
    • getParameter

      public java.lang.String getParameter​(java.lang.String name)
      Returns the parameter value for a parameter's name.
      Specified by:
      getParameter in interface javax.servlet.ServletRequest
      Overrides:
      getParameter in class javax.servlet.ServletRequestWrapper
      See Also:
      ServletRequestWrapper.getParameter(java.lang.String)
    • isWebSocketRequest

      public boolean isWebSocketRequest()
      Returns whether this request is a WebSocket request. This is an internal JWt method.
    • isWebSocketMessage

      public boolean isWebSocketMessage()
      Returns whether this request is a WebSocket message. This is an internal JWt method.
    • getClientAddress

      public java.lang.String getClientAddress​(boolean behindReverseProxy)