Class AwsHttpServletRequest

java.lang.Object
com.amazonaws.serverless.proxy.internal.servlet.AwsHttpServletRequest
All Implemented Interfaces:
jakarta.servlet.http.HttpServletRequest, jakarta.servlet.ServletRequest
Direct Known Subclasses:
AwsHttpApiV2ProxyHttpServletRequest, AwsProxyHttpServletRequest

public abstract class AwsHttpServletRequest extends Object implements jakarta.servlet.http.HttpServletRequest
Base HttpServletRequest object. This object exposes some utility methods to work with request values such as headers and query string parameters. New implementations of HttpServletRequest can extend this class to reuse the utility methods
  • Field Details

  • Constructor Details

    • AwsHttpServletRequest

      protected AwsHttpServletRequest(com.amazonaws.services.lambda.runtime.Context lambdaContext)
      Protected constructors for implementing classes. This should be called first with the context received from AWS Lambda
      Parameters:
      lambdaContext - The Lambda function context. This object is used for utility methods such as log
  • Method Details

    • getResponse

      public AwsHttpServletResponse getResponse()
    • setResponse

      public void setResponse(AwsHttpServletResponse response)
    • setContainerHandler

      public void setContainerHandler(AwsLambdaServletContainerHandler containerHandler)
    • getRequestedSessionId

      public String getRequestedSessionId()
      Specified by:
      getRequestedSessionId in interface jakarta.servlet.http.HttpServletRequest
    • getSession

      public jakarta.servlet.http.HttpSession getSession(boolean b)
      Specified by:
      getSession in interface jakarta.servlet.http.HttpServletRequest
    • getSession

      public jakarta.servlet.http.HttpSession getSession()
      as per Servlet spec this method creates a session if none exists
      Specified by:
      getSession in interface jakarta.servlet.http.HttpServletRequest
      Returns:
      exisiting or new http session
    • changeSessionId

      public String changeSessionId()
      Specified by:
      changeSessionId in interface jakarta.servlet.http.HttpServletRequest
    • isRequestedSessionIdValid

      public boolean isRequestedSessionIdValid()
      Specified by:
      isRequestedSessionIdValid in interface jakarta.servlet.http.HttpServletRequest
    • isRequestedSessionIdFromCookie

      public boolean isRequestedSessionIdFromCookie()
      Specified by:
      isRequestedSessionIdFromCookie in interface jakarta.servlet.http.HttpServletRequest
    • isRequestedSessionIdFromURL

      public boolean isRequestedSessionIdFromURL()
      Specified by:
      isRequestedSessionIdFromURL in interface jakarta.servlet.http.HttpServletRequest
    • getAttribute

      public Object getAttribute(String s)
      Specified by:
      getAttribute in interface jakarta.servlet.ServletRequest
    • getAttributeNames

      public Enumeration<String> getAttributeNames()
      Specified by:
      getAttributeNames in interface jakarta.servlet.ServletRequest
    • getServerName

      public String getServerName()
      Specified by:
      getServerName in interface jakarta.servlet.ServletRequest
    • getServerPort

      public int getServerPort()
      Specified by:
      getServerPort in interface jakarta.servlet.ServletRequest
    • setAttribute

      public void setAttribute(String s, Object o)
      Specified by:
      setAttribute in interface jakarta.servlet.ServletRequest
    • removeAttribute

      public void removeAttribute(String s)
      Specified by:
      removeAttribute in interface jakarta.servlet.ServletRequest
    • getLocalName

      public String getLocalName()
      Specified by:
      getLocalName in interface jakarta.servlet.ServletRequest
    • getLocalAddr

      public String getLocalAddr()
      Specified by:
      getLocalAddr in interface jakarta.servlet.ServletRequest
    • getLocalPort

      public int getLocalPort()
      Specified by:
      getLocalPort in interface jakarta.servlet.ServletRequest
    • getServletContext

      public jakarta.servlet.ServletContext getServletContext()
      Specified by:
      getServletContext in interface jakarta.servlet.ServletRequest
    • isAsyncStarted

      public boolean isAsyncStarted()
      Specified by:
      isAsyncStarted in interface jakarta.servlet.ServletRequest
    • isAsyncSupported

      public boolean isAsyncSupported()
      Specified by:
      isAsyncSupported in interface jakarta.servlet.ServletRequest
    • getDispatcherType

      public jakarta.servlet.DispatcherType getDispatcherType()
      Specified by:
      getDispatcherType in interface jakarta.servlet.ServletRequest
    • getServletPath

      public String getServletPath()
      Specified by:
      getServletPath in interface jakarta.servlet.http.HttpServletRequest
    • setServletContext

      public void setServletContext(jakarta.servlet.ServletContext context)
    • parseCookieHeaderValue

      protected jakarta.servlet.http.Cookie[] parseCookieHeaderValue(String headerValue)
      Given the Cookie header value, parses it and creates a Cookie object
      Parameters:
      headerValue - The string value of the HTTP Cookie header
      Returns:
      An array of Cookie objects from the header
    • generateQueryString

      protected String generateQueryString(MultiValuedTreeMap<String,String> parameters, boolean encode, String encodeCharset) throws jakarta.servlet.ServletException
      Given a map of key/values query string parameters from API Gateway, creates a query string as it would have been in the original url.
      Parameters:
      parameters - A Map<String, String> of query string parameters
      encode - Whether the key and values should be URL encoded
      encodeCharset - Charset to use for encoding the query string
      Returns:
      The generated query string for the URI
      Throws:
      jakarta.servlet.ServletException
    • generateContextPath

      protected String generateContextPath(ContainerConfig config, String apiStage)
    • generateRequestURL

      protected StringBuffer generateRequestURL(String requestPath)
    • bodyStringToInputStream

      protected jakarta.servlet.ServletInputStream bodyStringToInputStream(String body, boolean isBase64Encoded) throws IOException
      Throws:
      IOException
    • getFirstQueryParamValue

      protected String getFirstQueryParamValue(MultiValuedTreeMap<String,String> queryString, String key, boolean isCaseSensitive)
    • getFormBodyParameterCaseInsensitive

      protected String[] getFormBodyParameterCaseInsensitive(String key)
    • getFormUrlEncodedParametersMap

      protected Map<String,List<String>> getFormUrlEncodedParametersMap()
    • getCookieProcessor

      protected CookieProcessor getCookieProcessor()
    • getParts

      public Collection<jakarta.servlet.http.Part> getParts() throws IOException, jakarta.servlet.ServletException
      Specified by:
      getParts in interface jakarta.servlet.http.HttpServletRequest
      Throws:
      IOException
      jakarta.servlet.ServletException
    • getPart

      public jakarta.servlet.http.Part getPart(String s) throws IOException, jakarta.servlet.ServletException
      Specified by:
      getPart in interface jakarta.servlet.http.HttpServletRequest
      Throws:
      IOException
      jakarta.servlet.ServletException
    • getMultipartFormParametersMap

      protected Map<String,List<jakarta.servlet.http.Part>> getMultipartFormParametersMap() throws IOException
      Throws:
      IOException
    • getQueryParamValues

      protected String[] getQueryParamValues(MultiValuedTreeMap<String,String> qs, String key, boolean isCaseSensitive)
    • getQueryParamValuesAsList

      public static List<String> getQueryParamValuesAsList(MultiValuedTreeMap<String,String> qs, String key, boolean isCaseSensitive)
    • generateParameterMap

      protected Map<String,String[]> generateParameterMap(MultiValuedTreeMap<String,String> qs, ContainerConfig config)
    • generateParameterMap

      protected Map<String,String[]> generateParameterMap(MultiValuedTreeMap<String,String> qs, ContainerConfig config, boolean decodeQueryParams)
    • getSchemeFromHeader

      protected String getSchemeFromHeader(Headers headers)
    • parseHeaderValue

      protected List<AwsHttpServletRequest.HeaderValue> parseHeaderValue(String headerValue)
      Prases a header value using the default value separator "," and qualifier separator ";".
      Parameters:
      headerValue - The value to be parsed
      Returns:
      A list of SimpleMapEntry objects with all of the possible values for the header.
    • parseHeaderValue

      protected List<AwsHttpServletRequest.HeaderValue> parseHeaderValue(String headerValue, String valueSeparator, String qualifierSeparator)
      Generic method to parse an HTTP header value and split it into a list of key/values for all its components. When the property in the header does not specify a key the key field in the output pair is null and only the value is populated. For example, The header Accept: application/json; application/xml will contain two key value pairs with key null and the value set to application/json and application/xml respectively.
      Parameters:
      headerValue - The string value for the HTTP header
      valueSeparator - The separator to be used for parsing header values
      Returns:
      A list of SimpleMapEntry objects with all of the possible values for the header.
    • parseAcceptLanguageHeader

      protected List<Locale> parseAcceptLanguageHeader(String headerValue)
    • parseLanguageTag

      protected Locale parseLanguageTag(String languageTag)
    • decodeValueIfEncoded

      public static String decodeValueIfEncoded(String value)