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(LaunchConfig launchConfig,
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 |
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 |
fileSystem(LaunchConfig launchConfig,
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 |
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 |
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. |
public static Handler accepts(String... contentTypes)
contentTypes
- The content types to verify that the request can support for the responsepublic static Handler assets(LaunchConfig launchConfig, 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.
launchConfig
- The application launch configpath
- 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 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 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(LaunchConfig launchConfig, 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.
launchConfig
- The application launch 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 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 topublic 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)