Package io.avaje.jex

Interface Context

  • All Known Subinterfaces:
    SpiContext

    public interface Context
    Provides access to functions for handling the request and response.
    • Method Detail

      • matchedPath

        String matchedPath()
        Return the matched path as a raw expression.
      • attribute

        Context attribute​(String key,
                          Object value)
        Sets an attribute on the request. Attributes are available to other handlers in the request lifecycle
      • attribute

        <T> T attribute​(String key)
        Get the specified attribute from the request.
      • attributeMap

        Map<String,​Object> attributeMap()
        Gets a map with all the attribute keys and values on the request.
      • cookie

        String cookie​(String name)
        Return a request cookie by name, or null.
      • cookieMap

        Map<String,​String> cookieMap()
        Returns a map with all the cookie keys and values on the request.
      • cookie

        Context cookie​(String name,
                       String value)
        Sets a cookie with name, value with unlimited age.
      • cookie

        Context cookie​(String name,
                       String value,
                       int maxAge)
        Sets a cookie with name, value, and max-age.
      • cookie

        Context cookie​(javax.servlet.http.Cookie cookie)
        Sets a Cookie.
      • removeCookie

        Context removeCookie​(String name)
        Remove a cookie by name.
      • removeCookie

        Context removeCookie​(String name,
                             String path)
        Remove a cookie by name and path.
      • redirect

        void redirect​(String location)
        Redirect to the specified location using 302 status code.
      • redirect

        void redirect​(String location,
                      int httpStatusCode)
        Redirect to the location specifying the response status code.
      • bodyAsBytes

        byte[] bodyAsBytes()
        Return the request body as bytes.
      • bodyAsClass

        <T> T bodyAsClass​(Class<T> beanType)
        Return the request body as bean.
        Parameters:
        beanType - The bean type
      • body

        String body()
        Return the request body as String.
      • contentLength

        long contentLength()
        Return the request content length.
      • contentType

        String contentType()
        Return the request content type.
      • contentType

        Context contentType​(String contentType)
        Set the response content type.
      • pathParamMap

        Map<String,​String> pathParamMap()
        Return all the path parameters as a map.
      • pathParam

        String pathParam​(String name)
        Return the path parameter.
        Parameters:
        name - The path parameter name.
      • queryParam

        String queryParam​(String name)
        Return the first query parameter value.
        Parameters:
        name - The query parameter name
      • queryParams

        List<String> queryParams​(String name)
        Return all the query parameters for the given parameter name.
      • queryParamMap

        Map<String,​String> queryParamMap()
        Return all the query parameters as a map.

        Note this returns the first value for any given key if that key has multiple values.

      • queryString

        String queryString()
        Return the request query string, or null.
      • formParam

        String formParam​(String key)
        Return the first form param value for the specified key or null.
      • formParam

        String formParam​(String key,
                         String defaultValue)
        Return the first form param value for the specified key or the default value.
      • formParams

        List<String> formParams​(String key)
        Return the form params for the specified key, or empty list.
      • formParamMap

        Map<String,​List<String>> formParamMap()
        Returns a map with all the form param keys and values.
      • scheme

        String scheme()
        Return the request scheme.
      • sessionAttribute

        Context sessionAttribute​(String key,
                                 Object value)
        Sets an attribute for the user session.
      • sessionAttribute

        <T> T sessionAttribute​(String key)
        Gets specified attribute from the user session, or null.
      • sessionAttributeMap

        Map<String,​Object> sessionAttributeMap()
        Return a map of all the attributes in the user session.
      • url

        String url()
        Return the request url.
      • fullUrl

        String fullUrl()
        Return the full request url, including query string (if present)
      • contextPath

        String contextPath()
        Return the request context path.
      • userAgent

        String userAgent()
        Return the request user agent, or null.
      • status

        Context status​(int statusCode)
        Set the status code on the response.
      • status

        int status()
        Return the current response status.
      • text

        Context text​(String content)
        Write plain text content to the response.
      • html

        Context html​(String content)
        Write html content to the response.
      • json

        Context json​(Object bean)
        Set the response body as JSON for the given bean.
      • write

        Context write​(String content)
        Write raw content to the response.
      • render

        Context render​(String name)
        Render a template typically as html.
        Parameters:
        name - The template name
      • render

        Context render​(String name,
                       Map<String,​Object> model)
        Render a template typically as html with the given model.
        Parameters:
        name - The template name
        model - The model used with the template
      • headerMap

        Map<String,​String> headerMap()
        Return all the request headers as a map.
      • header

        String header​(String key)
        Return the request header.
        Parameters:
        key - The header key
      • header

        void header​(String key,
                    String value)
        Set the response header.
        Parameters:
        key - The header key
        value - The header value
      • host

        String host()
        Returns the request host, or null.
      • ip

        String ip()
        Returns the request IP.
      • isMultipart

        boolean isMultipart()
        Returns true if request is multipart.
      • isMultipartFormData

        boolean isMultipartFormData()
        Returns true if request is multipart/form-data.
      • method

        String method()
        Returns the request method.
      • path

        String path()
        Return the request path.
      • port

        int port()
        Return the request port.
      • protocol

        String protocol()
        Return the request protocol.
      • req

        javax.servlet.http.HttpServletRequest req()
        Return the underlying http servlet request.
      • res

        javax.servlet.http.HttpServletResponse res()
        Return the underlying http servlet response.
      • uploadedFile

        UploadedFile uploadedFile​(String name)
        Return the first UploadedFile for the specified name or null.
      • uploadedFiles

        List<UploadedFile> uploadedFiles​(String name)
        Return a list of UploadedFiles for the specified name, or empty list.