Package org.apache.druid.server.http
Class ServletResourceUtils
java.lang.Object
org.apache.druid.server.http.ServletResourceUtils
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic javax.ws.rs.core.Responsestatic <T> javax.ws.rs.core.ResponsebuildReadResponse(Supplier<T> readOperation) static javax.ws.rs.core.ResponsebuildUpdateResponse(Supplier<Boolean> updateOperation) static javax.servlet.AsyncListenercreateAsyncTimeoutListener(Consumer<javax.servlet.AsyncEvent> onTimeoutHandler) Creates anAsyncListenerwhich performs the given action on the event in case of aAsyncListener.onTimeout(javax.servlet.AsyncEvent).static <T> TgetDefaultValueIfCauseIs404ElseThrow(Exception e, Supplier<T> defaultValueSupplier) Returns the given default value if the root cause of the exception is anHttpResponseExceptionwith status codeHttpResponseStatus.NOT_FOUND.Converts String errorMsg into a Map so that it produces valid json on serialization into response.Sanitize the exception as a map of "error" to information about the exception.
-
Constructor Details
-
ServletResourceUtils
public ServletResourceUtils()
-
-
Method Details
-
sanitizeException
Sanitize the exception as a map of "error" to information about the exception. This method explicitly suppresses the stack trace and any other logging. Any logging should be handled by the caller.- Parameters:
t- The exception to sanitize- Returns:
- An immutable Map with a single entry which maps "error" to information about the error suitable for passing as an entity in a servlet error response.
-
jsonize
Converts String errorMsg into a Map so that it produces valid json on serialization into response. -
buildErrorResponseFrom
-
buildUpdateResponse
-
buildReadResponse
-
getDefaultValueIfCauseIs404ElseThrow
public static <T> T getDefaultValueIfCauseIs404ElseThrow(Exception e, Supplier<T> defaultValueSupplier) Returns the given default value if the root cause of the exception is anHttpResponseExceptionwith status codeHttpResponseStatus.NOT_FOUND. Otherwise, re-throws the given exception wrapped in aRuntimeException. -
createAsyncTimeoutListener
public static javax.servlet.AsyncListener createAsyncTimeoutListener(Consumer<javax.servlet.AsyncEvent> onTimeoutHandler) Creates anAsyncListenerwhich performs the given action on the event in case of aAsyncListener.onTimeout(javax.servlet.AsyncEvent). The other actions performed by the listener viz.AsyncListener.onStartAsync(javax.servlet.AsyncEvent),AsyncListener.onComplete(javax.servlet.AsyncEvent)andAsyncListener.onError(javax.servlet.AsyncEvent)are noop.
-