Package io.hawt.web
Class ServletHelpers
java.lang.Object
io.hawt.web.ServletHelpers
Helpers for servlet
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic StringNormalizes a path.static voiddoAuthPrompt(jakarta.servlet.http.HttpServletResponse response, String realm) static voiddoForbidden(jakarta.servlet.http.HttpServletResponse response) static voiddoForbidden(jakarta.servlet.http.HttpServletResponse response, ForbiddenReason reason) static voiddoTooManyRequests(jakarta.servlet.http.HttpServletResponse response, long retryAfter) static inthawtioPathIndex(jakarta.servlet.ServletContext servletContext) Return a number of web path segments that need to be skipped to reach hawtio path.static InputStreamstatic org.jolokia.json.JSONObjectreadObject(BufferedReader reader) static StringsanitizeHeader(String header) Strip out unwanted characters from the header such a CR/LF charsstatic voidsendJSONResponse(jakarta.servlet.http.HttpServletResponse response, boolean value) static voidsendJSONResponse(jakarta.servlet.http.HttpServletResponse response, String json) static StringwebContextPath(String first, String... more) Creates a web context path from components.static voidwriteEmpty(PrintWriter out) static voidwriteObjectAsJson(PrintWriter out, Object data)
-
Field Details
-
HEADER_HAWTIO_FORBIDDEN_REASON
- See Also:
-
-
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
-
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
- Throws:
IOException
-
writeEmpty
-
writeObjectAsJson
-
loadFile
-
sanitizeHeader
Strip out unwanted characters from the header such a CR/LF chars -
cleanPath
Normalizes a path. If the path contains a single '/' character it is returned unchanged, otherwise the path is:- stripped from all multiple consecutive occurrences of '/' characters
- stripped from trailing '/' character(s)
- Parameters:
path- path to normalize- Returns:
- normalized path
-
webContextPath
Creates a web context path from components. Concatenates all path components using '/' character as delimiter and the result is then:- prefixed with '/' character
- stripped from all multiple consecutive occurrences of '/' characters
- 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", so0is returned. In Spring Boot we may have to skip some segments (like/actuator/hawtio).- Parameters:
servletContext-- Returns:
-