public interface MvcContext
This class provides contextual information such as context and application
paths as well as access to the JAX-RS application configuration object.
In addition, it provides access to the security-related beans Csrf
and Encoders
.
Implementations of this class are injectable, must be
RequestScoped
and accessible from EL using
the name mvc
. For example, the CSRF token name and value can be
accessed in EL using the expressions mvc.csrf.name
and mvc.csrf.token
, respectively.
Configuration
Modifier and Type | Method and Description |
---|---|
String |
getApplicationPath()
Get the application's path which was set using the
ApplicationPath
annotation. |
String |
getBasePath()
Get the application's base path which is defined as the concatenation of context
and application paths.
|
javax.ws.rs.core.Configuration |
getConfig()
Get the JAX-RS application configuration object.
|
String |
getContextPath()
Get the application's context path.
|
Csrf |
getCsrf()
Get the CSRF object.
|
Encoders |
getEncoders()
Get the built-in encoders.
|
Locale |
getLocale()
Returns the locale of the current request.
|
URI |
uri(String identifier)
Creates an URI to be matched by a controller method.
|
URI |
uri(String identifier,
Map<String,Object> params)
Creates an URI to be matched by a controller method.
|
MvcUriBuilder |
uriBuilder(String identifier)
Returns a
MvcUriBuilder for building URIs to be matched
by a controller method. |
javax.ws.rs.core.Configuration getConfig()
String getContextPath()
Get the application's context path. The value returned must be normalized
to start with a slash ('/'
) but not end with one. Thus, the path returned by
this method can be prepended to that returned by getApplicationPath()
.
For example, given the URI http://host:port/myapp/resources/hello
,
this method returns /myapp
.
ServletContext.getContextPath()
String getApplicationPath()
Get the application's path which was set using the ApplicationPath
annotation. The value returned must be normalized to start with a slash ('/'
) but
not end with one. Thus, the path returned by this method can be appended to that
returned by getContextPath()
.
If the application path is empty or was set to /*
, then an empty string is
returned to ensure concatenation with getContextPath()
results in a well-formed
path. If a JAX-RS application subclass is not found, null
may be returned.
For example, given the URI http://host:port/myapp/resources/hello
,
this method returns /resources
.
null
if not found.String getBasePath()
Get the application's base path which is defined as the concatenation of context and application paths. It follows that the value returned by this method always starts with a slash but never ends with one.
If a JAX-RS application subclass is not found, causing getApplicationPath()
to return null
, then the value returned is the same as getContextPath()
.
Csrf getCsrf()
Encoders getEncoders()
Locale getLocale()
URI uri(String identifier)
Creates an URI to be matched by a controller method. This is aimed primarily
for use in view rendering technologies to avoid duplicating the values of the
Path
annotations.
The controller method can either be identified by the simple name of the controller class
and the method name separated by '#' (MyController#myMethod) or by the value
of the UriRef
annotation.
The created URI includes context- and application path.
This method assumes that there is no parameter in the URI-template.
For example:
${mvc.uri('MyController#myMethod')}
identifier
- for the controller method.URI uri(String identifier, Map<String,Object> params)
Creates an URI to be matched by a controller method. This is aimed primarily
for use in view rendering technologies to avoid duplicating the values of the
Path
annotations.
The controller method can either be identified by the simple name of the controller class
and the method name separated by '#' (MyController#myMethod) or by the value
of the UriRef
annotation.
The created URI includes context- and application path.
Any PathParam
, QueryParam
and MatrixParam
which could apply for given target
method will be replaced if a matching key is found in the supplied Map.
Please note that the map must contain values for all path parameters
as they are required for building the URI. All other parameters are optional.
For example:
${mvc.uri('MyController#myMethod' {'foo': 'bar', 'id': 42})}
identifier
- for the controller method.params
- a map of path-, query- and matrix parameters.IllegalArgumentException
- if there are any URI template parameters without a supplied value, or if a value is null
.MvcUriBuilder uriBuilder(String identifier)
Returns a MvcUriBuilder
for building URIs to be matched
by a controller method. This is aimed primarily for use in Java classes.
The controller method can either be identified by the simple name of the controller class
and the method name separated by '#' (MyController#myMethod) or by the value
of the UriRef
annotation.
identifier
- for the controller method.MvcUriBuilder
.Copyright © 2017 Ivar Grimstad. All rights reserved.