public class Route extends Object
Class
object
for routes.Modifier and Type | Class and Description |
---|---|
static interface |
Route.After
Execute application logic after a response has been generated by a route handler.
|
static interface |
Route.Aware |
static interface |
Route.Before
Decorates a handler and run logic before handler is executed.
|
static interface |
Route.Complete
Listener interface for events that are run at the completion of a request/response
cycle (i.e.
|
static interface |
Route.Decorator
Decorates a route handler by running logic before and after route handler.
|
static interface |
Route.Handler
Route handler here is where the application logic lives.
|
Modifier and Type | Field and Description |
---|---|
static Route.Before |
ACCEPT
Handler for
StatusCode.NOT_ACCEPTABLE responses. |
static Route.Handler |
FAVICON
Favicon handler as a silent 404 error.
|
static Route.Handler |
METHOD_NOT_ALLOWED
Handler for
StatusCode.METHOD_NOT_ALLOWED responses. |
static Route.Handler |
NOT_FOUND
Handler for
StatusCode.NOT_FOUND responses. |
static Route.Before |
SUPPORT_MEDIA_TYPE
Handler for
StatusCode.UNSUPPORTED_MEDIA_TYPE responses. |
Constructor and Description |
---|
Route(String method,
String pattern,
Route.Handler handler)
Creates a new route.
|
Modifier and Type | Method and Description |
---|---|
Route |
addTag(String tag)
Add a tag to this route.
|
<T> T |
attribute(String name)
Retrieve value of this specific Attribute set to this route.
|
Route |
attribute(String name,
Object value)
Add one or more attributes applied to this route.
|
Route |
consumes(MediaType... consumes)
Add one or more request types (format) consumed by this route.
|
MessageDecoder |
decoder(MediaType contentType)
MessageDecoder for given media type.
|
Route |
description(String description)
Route description useful for documentation purpose from openAPI generator.
|
Route.After |
getAfter()
After filter or
null . |
Map<String,Object> |
getAttributes()
Attributes set to this route.
|
Route.Before |
getBefore()
Before pipeline or
null . |
List<MediaType> |
getConsumes()
Request types (format) consumed by this route.
|
Map<String,MessageDecoder> |
getDecoders()
Route message decoder.
|
Route.Decorator |
getDecorator()
Decorator or
null . |
String |
getDescription()
Route description useful for documentation purpose from openAPI generator.
|
MessageEncoder |
getEncoder()
Route encoder.
|
String |
getExecutorKey()
Specify the name of the executor where the route is going to run.
|
Object |
getHandle()
Handler instance which might or might not be the same as
getHandler() . |
Route.Handler |
getHandler()
Route handler.
|
String |
getMethod()
HTTP method.
|
List<String> |
getPathKeys()
Path keys.
|
String |
getPattern()
Path pattern.
|
Route.Handler |
getPipeline()
Route pipeline.
|
List<MediaType> |
getProduces()
Response types (format) produces by this route.
|
Type |
getReturnType()
Return return type.
|
String |
getSummary()
Route summary useful for documentation purpose from openAPI generator.
|
List<String> |
getTags()
Route tags.
|
boolean |
isHttpHead()
True if route support HTTP HEAD.
|
boolean |
isHttpOptions()
True if route support HTTP OPTIONS.
|
boolean |
isHttpTrace()
True if route support HTTP TRACE.
|
Route |
produces(MediaType... produces)
Add one or more response types (format) produces by this route.
|
String |
reverse(Map<String,Object> keys)
Recreate a path pattern using the given variables.
|
String |
reverse(Object... values)
Recreate a path pattern using the given variables.
|
Route |
setAfter(Route.After after)
Set after filter.
|
Route |
setAttributes(Map<String,Object> attributes)
Add one or more attributes applied to this route.
|
Route |
setBefore(Route.Before before)
Set before filter.
|
Route |
setConsumes(Collection<MediaType> consumes)
Add one or more request types (format) consumed by this route.
|
Route |
setDecoders(Map<String,MessageDecoder> decoders)
Set message decoders.
|
Route |
setDecorator(Route.Decorator decorator)
Set route decorator.
|
Route |
setDescription(String description)
Route description useful for documentation purpose from openAPI generator.
|
Route |
setEncoder(MessageEncoder encoder)
Set encoder.
|
Route |
setExecutorKey(String executorKey)
Set executor key.
|
Route |
setHandle(Object handle)
Set route handle instance, required when handle is different from
getHandler() . |
Route |
setHttpHead(boolean enabled)
Enabled or disabled HTTP HEAD.
|
Route |
setHttpOptions(boolean enabled)
Enabled or disabled HTTP Options.
|
Route |
setHttpTrace(boolean enabled)
Enabled or disabled HTTP TRACE.
|
Route |
setPathKeys(List<String> pathKeys)
Set path keys.
|
Route |
setPipeline(Route.Handler pipeline)
Set route pipeline.
|
Route |
setProduces(Collection<MediaType> produces)
Add one or more response types (format) produces by this route.
|
Route |
setReturnType(Type returnType)
Set route return type.
|
Route |
setSummary(String summary)
Route summary useful for documentation purpose from openAPI generator.
|
Route |
setTags(List<String> tags)
Tag this route.
|
Route |
summary(String summary)
Route summary useful for documentation purpose from openAPI generator.
|
Route |
tags(String... tags)
Tag this route.
|
String |
toString() |
public static final Route.Handler NOT_FOUND
StatusCode.NOT_FOUND
responses.public static final Route.Handler METHOD_NOT_ALLOWED
StatusCode.METHOD_NOT_ALLOWED
responses.public static final Route.Before ACCEPT
StatusCode.NOT_ACCEPTABLE
responses.public static final Route.Before SUPPORT_MEDIA_TYPE
StatusCode.UNSUPPORTED_MEDIA_TYPE
responses.public static final Route.Handler FAVICON
@Nonnull public Route setPathKeys(@Nonnull List<String> pathKeys)
pathKeys
- Path keys or empty list.@Nonnull public Route.Handler getHandler()
@Nonnull public Route.Handler getPipeline()
@Nonnull public String reverse(@Nonnull Map<String,Object> keys)
reserve(/{k1}/{k2}, {"k1": ""foo", "k2": "bar"}) => /foo/bar
keys
- Path keys.@Nonnull public String reverse(Object... values)
reserve(/{k1}/{k2}, "foo", "bar") => /foo/bar
values
- Values.@Nonnull public Object getHandle()
getHandler()
.
The handle is required to extract correct metadata.@Nullable public Route.Before getBefore()
null
.null
.@Nonnull public Route setBefore(@Nullable Route.Before before)
before
- Before filter.@Nullable public Route.After getAfter()
null
.null
.@Nonnull public Route setAfter(@Nonnull Route.After after)
after
- After filter.@Nullable public Route.Decorator getDecorator()
null
.null
.@Nonnull public Route setDecorator(@Nullable Route.Decorator decorator)
decorator
- Decorator.@Nonnull public Route setHandle(@Nonnull Object handle)
getHandler()
.handle
- Handle instance.@Nonnull public Route setPipeline(Route.Handler pipeline)
pipeline
- Pipeline.@Nonnull public MessageEncoder getEncoder()
@Nonnull public Route setEncoder(@Nonnull MessageEncoder encoder)
encoder
- MessageEncoder.@Nonnull public Route setReturnType(@Nullable Type returnType)
returnType
- Return type.@Nonnull public List<MediaType> getProduces()
Accept
header. If none matches, we send a StatusCode.NOT_ACCEPTABLE
response.@Nonnull public Route produces(@Nonnull MediaType... produces)
produces
- Produce types.@Nonnull public Route setProduces(@Nonnull Collection<MediaType> produces)
produces
- Produce types.@Nonnull public List<MediaType> getConsumes()
Content-Type
header
is checked against these values. If none matches we send a
StatusCode.UNSUPPORTED_MEDIA_TYPE
exception.@Nonnull public Route consumes(@Nonnull MediaType... consumes)
consumes
- Consume types.@Nonnull public Route setConsumes(@Nonnull Collection<MediaType> consumes)
consumes
- Consume types.@Nonnull public Map<String,Object> getAttributes()
@Nullable public <T> T attribute(@Nonnull String name)
T
- Generic type.name
- of the attribute to retrieve.@Nonnull public Route setAttributes(@Nonnull Map<String,Object> attributes)
attributes
- .@Nonnull public Route attribute(@Nonnull String name, @Nonnull Object value)
name
- attribute namevalue
- attribute value@Nonnull public MessageDecoder decoder(@Nonnull MediaType contentType)
contentType
- Media type.@Nonnull public Map<String,MessageDecoder> getDecoders()
@Nonnull public Route setDecoders(@Nonnull Map<String,MessageDecoder> decoders)
decoders
- message decoder.public boolean isHttpOptions()
public boolean isHttpTrace()
public boolean isHttpHead()
@Nonnull public Route setHttpOptions(boolean enabled)
enabled
- Enabled or disabled HTTP Options.@Nonnull public Route setHttpTrace(boolean enabled)
enabled
- Enabled or disabled HTTP TRACE.@Nonnull public Route setHttpHead(boolean enabled)
enabled
- Enabled or disabled HTTP HEAD.@Nullable public String getExecutorKey()
null
.@Nonnull public Route setExecutorKey(@Nullable String executorKey)
null
: no specific executor, uses the default Jooby logic to choose one, based
on the value of ExecutionMode
;
- worker
: use the executor provided by the server.
- arbitrary name
: use an named executor which as registered using
Router.executor(String, Executor)
.executorKey
- Executor key.@Nonnull public Route setTags(@Nonnull List<String> tags)
tags
- Tags.@Nonnull public Route addTag(@Nonnull String tag)
tag
- Tag.@Nonnull public Route tags(@Nonnull String... tags)
tags
- Tags.@Nullable public String getSummary()
@Nonnull public Route summary(@Nullable String summary)
summary
- Summary.@Nonnull public Route setSummary(@Nullable String summary)
summary
- Summary.@Nullable public String getDescription()
@Nonnull public Route setDescription(@Nullable String description)
description
- Description.@Nonnull public Route description(@Nullable String description)
description
- Description.Copyright © 2020. All rights reserved.