Class WebApiUtil
-
Method Summary
Modifier and TypeMethodDescriptionstatic <T> TGets an object from the current request attributes.static booleanisApiRequestUri(String requestUri, String contextPath) Determines whether a request URI addresses one of the web API endpoints.static voidSets an error in the current request with the specified status code and exception.static voidSets an error in the current request with the specified status code and message.static voidSets an object in the current request attributes.static voidvalidate()Validates the current request by checking for stored web API exceptions.
-
Method Details
-
isApiRequestUri
Determines whether a request URI addresses one of the web API endpoints.This approximates the
WebApiManager#matches(HttpServletRequest)implementations, which are the established way Fess tells an API request from a browser request: each manager claims a path prefix and matches on the servlet path. This method exists for callers that cannot consult the managers directly because the servlet path no longer describes the original request -- notably the container error page, where the path elements describe the error page itself and only thejakarta.servlet.error.request_uriattribute still carries the original URI.An approximation, not a faithful copy, in two ways. It knows only the prefixes claimed by the managers bundled here; plugins register further ones (
/api/v1,/json,/suggest,/mcp) that it cannot see. And it matches the raw, undecoded URI, whereas the managers compare the decoded servlet path, so a percent-encoded prefix reads as a browser request. Both are tolerable because the only caller decides whether to replace an error status with an HTML page: every manager that can reach a container error page issuessendErrorunder/admin/server_, and a miss merely takes the browser arm, as this branch did unconditionally before.Deliberately dependency-free: it performs no component lookup and reads no configuration, so it stays safe to call while rendering an error response.
- Parameters:
requestUri- The original request URI, including the context path (may be null)contextPath- The context path to strip, as returned bygetContextPath()(may be null)- Returns:
- true if the URI addresses a web API endpoint
-
setObject
Sets an object in the current request attributes.- Parameters:
name- The attribute namevalue- The attribute value
-
getObject
Gets an object from the current request attributes.- Type Parameters:
T- The type of the object- Parameters:
name- The attribute name- Returns:
- The attribute value, or null if not found
-
setError
Sets an error in the current request with the specified status code and message.- Parameters:
statusCode- The HTTP status codemessage- The error message
-
setError
Sets an error in the current request with the specified status code and exception.- Parameters:
statusCode- The HTTP status codee- The exception that caused the error
-
validate
public static void validate()Validates the current request by checking for stored web API exceptions. Throws any stored WebApiException if found.- Throws:
WebApiException- If a web API exception was previously stored
-