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 |
assets(String path,
List<String> indexFiles)
A handler that serves static assets at the given file system path, relative to the contextual file system binding.
|
static Handler |
chain(Handler... handlers)
Creates a handler chain from the given handlers.
|
static Handler |
chain(LaunchConfig launchConfig,
Action<? super Chain> action)
Builds a handler chain, with no backing registry.
|
static Handler |
chain(LaunchConfig launchConfig,
Registry registry,
Action<? super Chain> action)
Builds a chain, backed by the given registry.
|
static Handler |
chain(List<? extends Handler> handlers)
Creates a handler chain from the given handlers.
|
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 |
fileSystem(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 |
header(String headerName,
String headerValue,
Handler handler)
Creates a handler that delegates to the given handler if the
request has a HTTPHeader with the
given name and a it's value matches the given value exactly. |
static Handler |
next()
A handler that simply delegates to the next handler.
|
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 <T> Handler |
register(Class<? super T> type,
T object,
Handler handler)
Creates a handler that inserts the handler chain defined by the builder, with the given service addition.
|
static <T> Handler |
register(T object,
Handler handler)
Creates a handler that inserts the handler chain defined by the builder, with the given service addition.
|
public static <T> Handler register(T object, Handler handler)
The service object will be available by its concrete type.
To make it available by a different type (perhaps one of its interfaces) use register(Class, Object, Handler)
.
T
- The concrete type of the service additionobject
- The object to add to the service, only for the handlers defined by builder
handler
- The handler topublic static <T> Handler register(Class<? super T> type, T object, Handler handler)
T
- The concrete type of the service additiontype
- The type by which to make the service addition availableobject
- The object to add to the service, only for the handlers defined by builder
handler
- The handler topublic static Handler chain(LaunchConfig launchConfig, Action<? super Chain> action) throws Exception
launchConfig
- The application launch configaction
- The chain definitionException
- any thrown by action
public static Handler chain(@Nullable LaunchConfig launchConfig, @Nullable Registry registry, Action<? super Chain> action) throws Exception
launchConfig
- The application launch configregistry
- 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 fileSystem(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.
path
- The relative path to the new file system binding pointhandler
- The handler to execute with the new file system bindingpublic static Handler assets(String path, List<String> indexFiles)
The file to serve is calculated based on the contextual FileSystemBinding
and the
contextual PathBinding
.
The PathBinding.getPastBinding()
of the contextual path binding is used to find a file/directory
relative to the contextual file system binding.
If the request matches a directory, an index file may be served.
The indexFiles
array specifies the names of files to look for in order to serve.
If no file can be found to serve, then control will be delegated to the next handler.
path
- The relative path to the location of the assets to serveindexFiles
- The index files to try if the request is for a directorypublic static Handler next()
Effectively a noop.
public static Handler get()
public static Handler post()
public static Handler contentTypes(String... contentTypes)
contentTypes
- The request content types to requirepublic static Handler accepts(String... contentTypes)
contentTypes
- The content types to verify that the request can support for the responsepublic static Handler put()
public static Handler patch()
public static Handler delete()
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 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 header(String headerName, String headerValue, Handler handler)
request
has a HTTPHeader
with the
given name and a it's value matches the given value exactly.headerName
- the name of the HTTP Header to match onheaderValue
- the value of the HTTP Header to match onhandler
- the handler to delegate to