Package io.hawt.web

Class ServletHelpers

java.lang.Object
io.hawt.web.ServletHelpers

public class ServletHelpers extends Object
Helpers for servlet
  • Field Details

  • Constructor Details

    • ServletHelpers

      public ServletHelpers()
  • Method Details

    • doForbidden

      public static void doForbidden(jakarta.servlet.http.HttpServletResponse response)
    • doForbidden

      public static void doForbidden(jakarta.servlet.http.HttpServletResponse response, ForbiddenReason reason)
    • doAuthPrompt

      public static void doAuthPrompt(jakarta.servlet.http.HttpServletResponse response, String realm)
    • doTooManyRequests

      public static void doTooManyRequests(jakarta.servlet.http.HttpServletResponse response, long retryAfter)
    • sendJSONResponse

      public static void sendJSONResponse(jakarta.servlet.http.HttpServletResponse response, boolean value) throws IOException
      Throws:
      IOException
    • sendJSONResponse

      public static void sendJSONResponse(jakarta.servlet.http.HttpServletResponse response, String json) throws IOException
      Throws:
      IOException
    • readObject

      public static org.jolokia.json.JSONObject readObject(BufferedReader reader) throws IOException
      Throws:
      IOException
    • writeEmpty

      public static void writeEmpty(PrintWriter out)
    • writeObjectAsJson

      public static void writeObjectAsJson(PrintWriter out, Object data)
    • loadFile

      public static InputStream loadFile(String path)
    • sanitizeHeader

      public static String sanitizeHeader(String header)
      Strip out unwanted characters from the header such a CR/LF chars
    • cleanPath

      public static String cleanPath(String path)
      Normalizes a path. If the path contains a single '/' character it is returned unchanged, otherwise the path is:
      1. stripped from all multiple consecutive occurrences of '/' characters
      2. stripped from trailing '/' character(s)
      Parameters:
      path - path to normalize
      Returns:
      normalized path
    • webContextPath

      public static String webContextPath(String first, String... more)
      Creates a web context path from components. Concatenates all path components using '/' character as delimiter and the result is then:
      1. prefixed with '/' character
      2. stripped from all multiple consecutive occurrences of '/' characters
      3. stripped from trailing '/' character(s)
      Returns:
      empty string or string which starts with a "/" character but does not end with a "/" character
    • hawtioPathIndex

      public static int hawtioPathIndex(jakarta.servlet.ServletContext servletContext)
      Return a number of web path segments that need to be skipped to reach hawtio path. In JakartaEE environment (WAR) everything after context path is "hawtio path", so 0 is returned. In Spring Boot we may have to skip some segments (like /actuator/hawtio).
      Parameters:
      servletContext -
      Returns: