public abstract class Handlers extends Object
Modifier and Type | Method and Description |
---|---|
static Handler |
accepts(String... contentTypes)
A handler that delegates to the next handler if the request claims that it can accept one of the given types, otherwise raises a 406 client error.
|
static Handler |
chain(Handler... handlers)
Creates a handler chain from the given handlers.
|
static Handler |
chain(List<? extends Handler> handlers)
Creates a handler chain from the given handlers.
|
static Handler |
chain(Registry registry,
Action<? super Chain> action)
Builds a chain, backed by the given registry.
|
static Handler |
chain(ServerConfig serverConfig,
Action<? super Chain> action)
Builds a handler chain, with no backing registry.
|
static Handler |
chain(ServerConfig serverConfig,
Registry registry,
Action<? super Chain> action)
Builds a chain, backed by the given registry.
|
static Handler |
clientError(int statusCode)
A handler that simply calls
Context.clientError(int) with the given status code. |
static Handler |
contentTypes(String... contentTypes)
A handler that delegates to the next handler if the content type of the request is one of the given types, otherwise raises a 415 client error.
|
static Handler |
delete()
A handler that delegates to the next handler if the request is DELETE, otherwise raises a 405 client error.
|
static Handler |
files(ServerConfig serverConfig,
Action<? super FileHandlerSpec> config)
Creates a handler that serves files from the file system.
|
static Handler |
fileSystem(ServerConfig serverConfig,
String path,
Handler handler)
A handlers that changes the
FileSystemBinding for the given handlers. |
static Handler |
get()
A handler that delegates to the next handler if the request is GET, otherwise raises a 405 client error.
|
static Handler |
next()
A handler that simply delegates to the next handler.
|
static Handler |
notFound()
Convenience for
clientError(404) . |
static Handler |
patch()
A handler that delegates to the next handler if the request is PATCH, otherwise raises a 405 client error.
|
static Handler |
path(PathBinder pathBinder,
Handler handler)
Creates a handler that delegates to the given handlers if the request can be bound by the given path binder.
|
static Handler |
path(String path,
Handler handler)
Creates a handler that delegates to the given handlers if the request matches the given path exactly.
|
static Handler |
post()
A handler that delegates to the next handler if the request is POST, otherwise raises a 405 client error.
|
static Handler |
prefix(String prefix,
Handler handler)
Creates a handler that delegates to the given handlers if the request path starts with the given prefix.
|
static Handler |
put()
A handler that delegates to the next handler if the request is PUT, otherwise raises a 405 client error.
|
static Handler |
redirect(int code,
String location)
Creates a handler that always issues a redirect using
Context.redirect(int, String) with exactly the given code and location. |
static Handler |
register(Registry registry)
A handler that simply calls
Context.next(Registry) with the given registry. |
static Handler |
register(Registry registry,
Handler handler)
A handler that simply calls
Context.insert(Registry, Handler...) with the given registry and handler. |
static Handler |
route(Predicate<? super Context> test,
Handler handler)
Creates a handler that inserts and delegates the given handler if the predicate applies to the context.
|
public static Handler accepts(String... contentTypes)
contentTypes
- The content types to verify that the request can support for the responsepublic static Handler files(ServerConfig serverConfig, Action<? super FileHandlerSpec> config) throws Exception
This method is a standalone version of Chain.files(Action)
.
serverConfig
- the server configconfig
- the configuration of the file handlerException
- any thrown by config
public static Handler chain(ServerConfig serverConfig, Action<? super Chain> action) throws Exception
serverConfig
- The server configaction
- The chain definitionException
- any thrown by action
public static Handler chain(@Nullable ServerConfig serverConfig, @Nullable Registry registry, Action<? super Chain> action) throws Exception
serverConfig
- The server configregistry
- The registry.action
- The chain building action.Exception
- any thrown by action
public static Handler chain(Registry registry, Action<? super Chain> action) throws Exception
registry
- The registry.action
- The chain building action.Exception
- any thrown by action
public static Handler chain(List<? extends Handler> handlers)
handlers
- The handlers to connect into a chainpublic static Handler chain(Handler... handlers)
handlers
- The handlers to connect into a chainpublic static Handler clientError(int statusCode)
Context.clientError(int)
with the given status code.statusCode
- The 4xx client error status codepublic static Handler contentTypes(String... contentTypes)
contentTypes
- The request content types to requirepublic static Handler delete()
public static Handler fileSystem(ServerConfig serverConfig, String path, Handler handler)
FileSystemBinding
for the given handlers.
The new file system binding will be created by the FileSystemBinding.binding(String)
method of the contextual binding.
serverConfig
- The application server configpath
- The relative path to the new file system binding pointhandler
- The handler to execute with the new file system bindingpublic static Handler get()
public static Handler next()
Effectively a noop.
public static Handler notFound()
clientError(404)
.public static Handler patch()
public static Handler path(String path, Handler handler)
The path
is relative to the contextual PathBinding
of the exchange.
A new contextual PathBinding
will be established for the given handlers,
using the given path as the bind point.
path
- The exact path to match tohandler
- The handlers to delegate to if the path matchespublic static Handler path(PathBinder pathBinder, Handler handler)
pathBinder
- The path binder that may bind to the request pathhandler
- The handlers to delegate to if path binder does bind to the pathpublic static Handler post()
public static Handler prefix(String prefix, Handler handler)
The prefix
is relative to the contextual PathBinding
of the exchange.
A new contextual PathBinding
will be established for the given handlers,
using the given prefix as the bind point.
prefix
- The path prefix to matchhandler
- The handler to delegate topublic static Handler put()
public static Handler register(Registry registry, Handler handler)
Context.insert(Registry, Handler...)
with the given registry and handler.registry
- the registry to inserthandler
- The handler to insertpublic static Handler register(Registry registry)
Context.next(Registry)
with the given registry.registry
- The registry to make available to the next handlersContext.next(Registry)
public static Handler redirect(int code, String location)
Context.redirect(int, String)
with exactly the given code and location.
This method will immediate throw an IllegalArgumentException
if code is < 300 || > 399.
code
- the 3XX HTTP status codelocation
- the URL to set in the Location response headerContext.redirect(int, String)
public static Handler route(Predicate<? super Context> test, Handler handler)
If the predicate does not apply, calls Context.next()
.
test
- the test whether to route to the given handlerhandler
- the handler to insert if the predicate applies