public class FiltersKt
| Modifier and Type | Method and Description |
|---|---|
static <T extends ComponentsProvider> |
defaultContentTypeFilter(ContentType contentType)
Filter that sets the default content type of the response.
|
static <T extends ComponentsProvider> |
defaultExceptionMappingFilter()
Returns a filter that catches any exceptions thrown by the handler and builds a response containing the error
status and message.
|
static <T extends ComponentsProvider> |
defineFilter(kotlin.jvm.functions.Function3<? super T,? super ws.osiris.core.Request,? super kotlin.jvm.functions.Function2<? super T,? super ws.osiris.core.Request,ws.osiris.core.Response>,? extends java.lang.Object> handler)
Creates a filter that is applied to all endpoints.
|
static <T extends ComponentsProvider> |
exceptionMappingFilter(java.util.List<? extends ws.osiris.core.ExceptionHandler<?>> exceptionHandlers)
Returns a filter that catches any exceptions thrown by the handler and builds a response containing the error
status and message.
|
static org.slf4j.Logger |
getLog() |
static <T extends ComponentsProvider> |
jsonSerialisingFilter()
Filter that serialises the response body to JSON so it can be written to the response.
|
public static org.slf4j.Logger getLog()
public static <T extends ComponentsProvider> Filter<T> defineFilter(kotlin.jvm.functions.Function3<? super T,? super ws.osiris.core.Request,? super kotlin.jvm.functions.Function2<? super T,? super ws.osiris.core.Request,ws.osiris.core.Response>,? extends java.lang.Object> handler)
Creates a filter that is applied to all endpoints.
If a filter only applies to a subset of endpoints it should be defined as part of the API.
public static <T extends ComponentsProvider> Filter<T> defaultContentTypeFilter(ContentType contentType)
Filter that sets the default content type of the response.
This is done by changing the defaultResponseHeaders of the request. This is propagated to
the response headers via Request.responseBuilder function.
Request.responseBuilderpublic static <T extends ComponentsProvider> Filter<T> jsonSerialisingFilter()
Filter that serialises the response body to JSON so it can be written to the response.
This filter is only applied if the content type is application/json. For all other
content types the response is returned unchanged.
Handling of body types:
null - no body
string - assumed to be JSON, used as-is
object - converted to a JSON string using Jackson
public static <T extends ComponentsProvider> Filter<T> exceptionMappingFilter(java.util.List<? extends ws.osiris.core.ExceptionHandler<?>> exceptionHandlers)
Returns a filter that catches any exceptions thrown by the handler and builds a response containing the error status and message.
The exception is passed to each of the handlers in turn until one of them handles it. If none of them handles it a 500 (server error) is returned with a generic message ("Server Error").
public static <T extends ComponentsProvider> Filter<T> defaultExceptionMappingFilter()
Returns a filter that catches any exceptions thrown by the handler and builds a response containing the error status and message.
The filter catches all subclasses of the listed exceptions. Any other exceptions will result in a status of 500 (server error) with a generic error message.
This catches
exception HttpException, returns the status and message from the exception
IllegalArgumentException, returns a status of 400 (bad request) and the exception message
exception HttpException,
IllegalArgumentException