Class RequestUtils

java.lang.Object
io.mangoo.utils.RequestUtils

public final class RequestUtils extends Object
Author:
svenkubiak
  • Method Summary

    Modifier and Type
    Method
    Description
    static io.undertow.util.AttachmentKey<Attachment>
     
    static Map<String,String>
    getRequestParameters(io.undertow.server.HttpServerExchange exchange)
    Converts request and query parameter into a single map
    static String
    getServerSentEventURL(io.undertow.server.handlers.sse.ServerSentEventConnection connection)
    Retrieves a URL from a Server-Sent Event connection
    static String
    getURL(URI uri)
    Creates and URL with only path and if present query and fragment, e.g.
    static String
    getWebSocketURL(io.undertow.websockets.core.WebSocketChannel channel)
    Retrieves the URL of a WebSocketChannel
    static boolean
    Checks if the given header contains a valid authentication
    static boolean
    isJsonRequest(io.undertow.server.HttpServerExchange exchange)
    Checks if the requests content-type contains application/json
    static boolean
    isPostPutPatch(io.undertow.server.HttpServerExchange exchange)
    Checks if the request is a POST, PUT or PATCH request
    static io.undertow.server.HttpHandler
    wrapBasicAuthentication(io.undertow.server.HttpHandler httpHandler, String username, String password)
    Adds a Wrapper to the handler when the request requires authentication

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • getAttachmentKey

      public static io.undertow.util.AttachmentKey<Attachment> getAttachmentKey()
    • getRequestParameters

      public static Map<String,String> getRequestParameters(io.undertow.server.HttpServerExchange exchange)
      Converts request and query parameter into a single map
      Parameters:
      exchange - The Undertow HttpServerExchange
      Returns:
      A single map contain both request and query parameter
    • isPostPutPatch

      public static boolean isPostPutPatch(io.undertow.server.HttpServerExchange exchange)
      Checks if the request is a POST, PUT or PATCH request
      Parameters:
      exchange - The Undertow HttpServerExchange
      Returns:
      True if the request is a POST, PUT or PATCH request, false otherwise
    • isJsonRequest

      public static boolean isJsonRequest(io.undertow.server.HttpServerExchange exchange)
      Checks if the requests content-type contains application/json
      Parameters:
      exchange - The Undertow HttpServerExchange
      Returns:
      True if the request content-type contains application/json, false otherwise
    • hasValidAuthentication

      public static boolean hasValidAuthentication(String cookie)
      Checks if the given header contains a valid authentication
      Parameters:
      cookie - The cookie to parse
      Returns:
      True if the cookie contains a valid authentication, false otherwise
    • getServerSentEventURL

      public static String getServerSentEventURL(io.undertow.server.handlers.sse.ServerSentEventConnection connection)
      Retrieves a URL from a Server-Sent Event connection
      Parameters:
      connection - The ServerSentEvent Connection
      Returns:
      The URL of the Server-Sent Event Connection
    • getWebSocketURL

      public static String getWebSocketURL(io.undertow.websockets.core.WebSocketChannel channel)
      Retrieves the URL of a WebSocketChannel
      Parameters:
      channel - The WebSocket Channel
      Returns:
      The URL of the WebSocket Channel
    • getURL

      public static String getURL(URI uri)
      Creates and URL with only path and if present query and fragment, e.g. /path/data?key=value#fragid1
      Parameters:
      uri - The URI to generate from
      Returns:
      The generated URL
    • wrapBasicAuthentication

      public static io.undertow.server.HttpHandler wrapBasicAuthentication(io.undertow.server.HttpHandler httpHandler, String username, String password)
      Adds a Wrapper to the handler when the request requires authentication
      Parameters:
      httpHandler - The Handler to wrap
      username - The username to use
      password - The password to use
      Returns:
      An HttpHandler wrapped through BasicAuthentication