Interface ApiHttpExchange

    • Method Detail

      • getHttpMethod

        String getHttpMethod()
      • getContextPath

        String getContextPath()
        Returns the context path of the server. Blank if the server context is the root of the server
      • getServerURL

        String getServerURL()
        Returns the scheme, hostname and port part of the requesting URL, for example http://www.example.com or https://localhost:8443
      • getContextURL

        default URL getContextURL()
        Returns the scheme, hostname, port and context path of the server
      • getApiURL

        default URL getApiURL()
        Returns the path to where the controllers paths are evaluated relative to, that is, the Servlet's context URL. For example, if an ApiServlet is bound as "/api/*" in a webapp mounted at "/app", getApiURL might return https://example.com:7443/app/api.
      • getPathInfo

        String getPathInfo()
        Returns the part of the URL after getApiURL. For example if a controller is mounted at https://example.com:7443/app/api and the client requests GET https://example.com:7443/app/api/hello/world getPathInfo returns "/hello/world"
      • getRequestURL

        default String getRequestURL()
      • getQueryString

        String getQueryString()
        Returns the query string of the requested url. For example if the client requests GET https://example.com:7443/app/api/hello/world?greeting=Hello+There getQueryString() returns greeting=Hello+There.
      • getParameters

        List<String> getParameters​(String name)
        Returns the specified query string of the requested url for a get request or x-www-form-urlencoded body parameter for a POST or PUT request. For example if the client requests GET https://example.com:7443/app/api/hello/world?greeting=Hello+There&greeting=Hi getParameter("greeting") returns ["Hello There", "Hi"].
        Parameters:
        name - The query parameter name
        Returns:
        the non-empty list of parameters matching the name or null if none were provided
      • requiredParameter

        default String requiredParameter​(String name)
      • hasParameter

        default boolean hasParameter​(String name)
      • getHeaders

        List<String> getHeaders​(String name)
        Returns the values for all instances of this header in the HTTP request
        Parameters:
        name - The header name
        Returns:
        the non-empty list of headers matching the name or null if none were provided
      • accept

        default boolean accept​(String contentType)
        Returns true if the "Accept" request header matches the argument content type
      • getClientIp

        String getClientIp()
      • setResponseHeader

        void setResponseHeader​(String key,
                               String value)
      • addResponseHeader

        void addResponseHeader​(String key,
                               String value)
      • setPathParameters

        void setPathParameters​(Map<String,​String> pathParameters)
      • setCookie

        default void setCookie​(String name,
                               String value)
        Sets a cookie with default values. If value == null, deletes the cookie
      • setCookie

        default void setCookie​(String name,
                               String value,
                               boolean secure,
                               boolean isHttpOnly)
        Sets a cookie with default values. If value == null, deletes the cookie
      • setCookie

        void setCookie​(String name,
                       String value,
                       boolean secure,
                       boolean isHttpOnly,
                       String contextPath,
                       int maxAge,
                       String domain,
                       String comment)
        Sets a cookie with default values. If value == null, deletes the cookie
      • getCookies

        List<String> getCookies​(String name)
        Returns all values of this cookie
        Parameters:
        name - The cookie name
        Returns:
        a non-null list of cookies matching the name or empty if none were provided
      • setStatus

        void setStatus​(int statusCode)
                throws IOException
        Sets the http status code, but don't trigger the error handler (servlets)
        Throws:
        IOException
      • isUserLoggedIn

        boolean isUserLoggedIn()
      • isUserInRole

        boolean isUserInRole​(String role)
      • setSessionAttribute

        void setSessionAttribute​(String name,
                                 Object value,
                                 boolean invalidate)
      • getSessionAttribute

        Optional getSessionAttribute​(String name,
                                     boolean createIfMissing)
      • getSessionAttribute

        default Optional getSessionAttribute​(String name)
      • getSessionAttribute

        default <T> Optional<T> getSessionAttribute​(Class<T> name,
                                                    boolean createIfMissing)
      • getSessionAttribute

        default <T> Optional<T> getSessionAttribute​(Class<T> name)
      • getUserPrincipal

        Principal getUserPrincipal()