public class ContextHandlerBuilder extends Object implements MuHandlerBuilder<ContextHandler>
Constructor and Description |
---|
ContextHandlerBuilder() |
Modifier and Type | Method and Description |
---|---|
ContextHandlerBuilder |
addHandler(Method method,
String uriTemplate,
RouteHandler handler)
Registers a new handler that will only be called if it matches the given route info (relative to the current context).
|
ContextHandlerBuilder |
addHandler(MuHandler handler)
Adds a request handler relative to the context of this builder.
|
ContextHandlerBuilder |
addHandler(MuHandlerBuilder handler)
Adds a request handler relative to the context of this builder.
|
ContextHandler |
build() |
static ContextHandlerBuilder |
context(String path)
Create a new base path.
|
static ContextHandlerBuilder |
context(String path,
MuHandler... handlers)
Deprecated.
Use
context(String) and then add handlers on to that. |
static ContextHandlerBuilder |
context(String path,
MuHandlerBuilder... handlers)
Deprecated.
Use
context(String) and then add handlers on to that. |
ContextHandlerBuilder |
withPath(String path)
Sets the path to serve from.
|
public ContextHandlerBuilder withPath(String path)
If a null or empty path is given, then it is as if the child handlers are not added to a context.
path
- The path, such as api
or /api/
etcpublic static ContextHandlerBuilder context(String path)
Create a new base path. Any handlers added with addHandler(MuHandler)
, addHandler(MuHandlerBuilder)
or
addHandler(Method, String, RouteHandler)
will be served relative to the path given.
Request handlers can get the context they are served from by using the MuRequest.contextPath()
and
can get the path relative to handler with MuRequest.relativePath()
.
If a null or empty path is given, then it is as if the child handlers are not added to a context.
path
- The path to serve handlers from, for example api
or /api/
(which are equivalent).@Deprecated public static ContextHandlerBuilder context(String path, MuHandler... handlers)
context(String)
and then add handlers on to that.path
- The pathhandlers
- The handler@Deprecated public static ContextHandlerBuilder context(String path, MuHandlerBuilder... handlers)
context(String)
and then add handlers on to that.path
- The pathhandlers
- The handlerpublic ContextHandlerBuilder addHandler(MuHandlerBuilder handler)
Adds a request handler relative to the context of this builder.
Note that handlers are executed in the order added to the builder, but all async handlers are executed before synchronous handlers.
handler
- A handler builder. The build()
method will be called on this
to create the handler.addHandler(Method, String, RouteHandler)
public ContextHandlerBuilder addHandler(MuHandler handler)
Adds a request handler relative to the context of this builder.
Note that handlers are executed in the order added to the builder, but all async handlers are executed before synchronous handlers.
handler
- The handler to add.addHandler(Method, String, RouteHandler)
public ContextHandlerBuilder addHandler(Method method, String uriTemplate, RouteHandler handler)
method
- The method to match, or null
to accept any method.uriTemplate
- A URL template, relative to the context. Supports plain URLs like /abc
or paths
with named parameters such as /abc/{id}
or named parameters
with regexes such as /abc/{id : [0-9]+}
where the named
parameter values can be accessed with the pathParams
parameter in the route handler.handler
- The handler to invoke if the method and URI matches.public ContextHandler build()
build
in interface MuHandlerBuilder<ContextHandler>
MuHandler
Copyright © 2017–2021. All rights reserved.