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:
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static interface 
    Progress listener interface.
    static enum 
    Enumeration for a WebSocket read event (not yet implemented).
    static enum 
    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
    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 String
    computePathInfo(javax.servlet.http.HttpServletRequest request, Configuration configuration)
     
    static String
    computePathInfo(javax.servlet.http.HttpServletRequest request, String scriptName, Configuration configuration)
     
    static String
    computeScriptName(javax.servlet.http.HttpServletRequest request, Configuration configuration)
     
     
    Returns a header value.
     
    Returns the parameter value for a parameter's name.
    Returns the parameter map.
    Returns the parameter values for a parameter.
    Returns the internal path information.
    Returns the request method.
    Returns the script name.
    Returns the list of uploaded files.
     
    Accesses to specific header fields (calls getHeaderValue()).
    boolean
    Returns whether this request is a WebSocket message.
    boolean
    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, changeSessionId, getAuthType, getContextPath, getCookies, getDateHeader, getHeader, getHeaderNames, getHeaders, getHttpServletMapping, getIntHeader, getMethod, getPart, getParts, getPathTranslated, getQueryString, getRemoteUser, getRequestedSessionId, getRequestURI, getRequestURL, getServletPath, getSession, getSession, getTrailerFields, getUserPrincipal, isRequestedSessionIdFromCookie, isRequestedSessionIdFromUrl, isRequestedSessionIdFromURL, isRequestedSessionIdValid, isTrailerFieldsReady, isUserInRole, login, logout, newPushBuilder, upgrade

    Methods inherited from class javax.servlet.ServletRequestWrapper

    getAsyncContext, getAttribute, getAttributeNames, getCharacterEncoding, getContentLength, getContentLengthLong, 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, getContentLengthLong, 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(Map<String,String[]> parameters, Map<String,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 String computeScriptName(javax.servlet.http.HttpServletRequest request, Configuration configuration)
    • computePathInfo

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

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

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

      public 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 String getHeaderValue(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 String getUserAgent()
      Accesses to specific header fields (calls getHeaderValue()).
    • getPathInfo

      public 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 Map<String,List<UploadedFile>> getUploadedFiles()
      Returns the list of uploaded files.
      Returns:
      the list of uploaded files.
    • getParameterMap

      public Map<String,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 String[] getParameterValues(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:
    • getParameter

      public String getParameter(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 String getClientAddress(Configuration conf)
    • getHostName

      public String getHostName(Configuration conf)
    • getUrlScheme

      public String getUrlScheme(Configuration conf)