Class WebUtils
This class supports parsing and formatting of HTTP cookie headers, case-insensitive HTTP header maps, and discovery
of WebPattern annotations on handler methods annotated with HandleWeb.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionasHeaderMap(Map<String, List<String>> input) Converts the input map into a case-insensitive header map.static StringconcatenateUrlParts(String... parts) Concatenates multiple segments of a URL, ensuring that: Double slashes in schemes likehttps://are preserved Duplicate slashes between path segments are removed Null or empty segments are skippedReturns a new case-insensitive header map, with keys compared ignoring case.extractPathParameters(String path) Extracts all named path parameters from the given path.static StringgetHandlerPath(Class<?> targetClass, Object handler, Executable method) Computes the complete@Pathvalue for the given handler.Retrieves the first header value for the given name from the provided Metadata object.getHeaders(Metadata metadata) Retrieves a case-insensitive map of headers from the provided Metadata object.static List<WebPattern> getWebPatterns(Class<?> targetClass, Object handler, Executable method) Returns allWebPatterninstances declared on the given method in the given target class.static booleanhasPathParameter(String path) Checks if the given path contains a named path parameter.static List<HttpCookie> parseRequestCookieHeader(String cookieHeader) Parses aCookierequest header string into a list ofHttpCookieinstances.static List<HttpCookie> parseResponseCookieHeader(List<String> setCookieHeaders) Parses a list ofSet-Cookieheader values into a list ofHttpCookieinstances.static StringreplacePathParameter(String path, String parameterName, String value) Replaces named path parameter with provided value.static StringtoRequestHeaderString(@NonNull HttpCookie cookie) Returns a formatted string for theCookierequest header containing the given cookie.static StringtoResponseHeaderString(@NonNull HttpCookie cookie) Returns a properly formattedSet-Cookieheader value for the given cookie.
-
Constructor Details
-
WebUtils
public WebUtils()
-
-
Method Details
-
toResponseHeaderString
Returns a properly formattedSet-Cookieheader value for the given cookie.The result includes standard attributes such as
Domain,Path,Max-Age,HttpOnly, andSecureif they are set on the cookie.- Parameters:
cookie- the cookie to format (must not benull)- Returns:
- a header string suitable for a
Set-Cookieresponse header
-
toRequestHeaderString
Returns a formatted string for theCookierequest header containing the given cookie.- Parameters:
cookie- the cookie to encode (must not benull)- Returns:
- a header string suitable for inclusion in a
Cookierequest header
-
parseRequestCookieHeader
Parses aCookierequest header string into a list ofHttpCookieinstances.The input is expected to contain one or more name-value pairs separated by semicolons.
- Parameters:
cookieHeader- the value of theCookieheader, ornull- Returns:
- a list of parsed
HttpCookieinstances (empty if input isnull)
-
parseResponseCookieHeader
Parses a list ofSet-Cookieheader values into a list ofHttpCookieinstances.Each value in the input list should be a properly formatted
Set-Cookieheader line.- Parameters:
setCookieHeaders- the list ofSet-Cookieheader values, ornull- Returns:
- a list of parsed
HttpCookieinstances (empty if input isnull)
-
getWebPatterns
public static List<WebPattern> getWebPatterns(Class<?> targetClass, @Nullable Object handler, Executable method) Returns allWebPatterninstances declared on the given method in the given target class.This inspects all
HandleWebannotations on the method and resolves any declaredWebParametersto extract associated patterns.- Parameters:
targetClass- the target classhandler- the handler instance (may benull)method- the method to inspect- Returns:
- a list of
WebPatterninstances associated with the method
-
getHandlerPath
public static String getHandlerPath(Class<?> targetClass, @Nullable Object handler, @Nullable Executable method) Computes the complete@Pathvalue for the given handler.targetClassis required;handlerandmethodare not. The path value is determined by inspecting the following elements:- sub-packages
- class package
- target class
- handler properties (if the given handler is not null)
- handler method (if the given method is not null)
@Pathvalues are joined together in the order listed above, with a slash as delimiter. If any of the@Pathvalues start with a slash, the chain is reset. -
emptyHeaderMap
-
asHeaderMap
Converts the input map into a case-insensitive header map.Keys in the result will be case-insensitive, with the contents copied from the input map.
- Parameters:
input- the input map- Returns:
- a case-insensitive map containing the same entries
-
getHeaders
-
getHeader
-
hasPathParameter
Checks if the given path contains a named path parameter. -
extractPathParameters
-
replacePathParameter
-
concatenateUrlParts
Concatenates multiple segments of a URL, ensuring that:- Double slashes in schemes like
https://are preserved - Duplicate slashes between path segments are removed
- Null or empty segments are skipped
- Parameters:
parts- URL parts, e.g.,"https://", "example.org", "/api/", "/v1/"- Returns:
- A clean, properly concatenated URL, e.g.
"https://example.org/api/v1/"
- Double slashes in schemes like
-