Annotation Type RestOptions
RestServlet
implementation class.
This is a specialized subtype of @RestOp
(method=
See Also:
-
Optional Element Summary
Optional ElementsModifier and TypeOptional ElementDescriptionSpecifies whether this method can be called based on the client version.Class<? extends RestConverter>[]
Class-level response converters.Enable debug mode.DefaultAccept header.Default character encoding.String[]
Default request attributes.String[]
Default request headers.String[]
Specifies default values for query parameters.String[]
Default response headers.String[]
Optional description for the exposed API.Specifies the compression encoders for this method.Method-level guards.Class<? extends RestMatcher>[]
Method matchers.String[]
Dynamically apply this annotation to the specified methods.String[]
Optional path pattern for the specified method.String[]
Supported accept media types.Role guard.Declared roles.Class<? extends Serializer>[]
Specifies the serializers for marshalling POJOs into response bodies for this method.Optional summary for the exposed API.Provides swagger-specific metadata on this method.REST method path.
-
Element Details
-
clientVersion
Specifies whether this method can be called based on the client version.The client version is identified via the HTTP request header identified by
@Rest(clientVersionHeader)
which by default is"Client-Version" .This is a specialized kind of
RestMatcher
that allows you to invoke different Java methods for the same method/path based on the client version.The format of the client version range is similar to that of OSGi versions.
In the following example, the Java methods are mapped to the same HTTP method and URL
"/foobar" .// Call this method if Client-Version is at least 2.0. // Note that this also matches 2.0.1. @RestOptions (path="/foobar" , clientVersion="2.0" )public Object method1() {...}// Call this method if Client-Version is at least 1.1, but less than 2.0. @RestOptions (path="/foobar" , clientVersion="[1.1,2.0)" )public Object method2() {...}// Call this method if Client-Version is less than 1.1. @RestOptions (path="/foobar" , clientVersion="[0,1.1)" )public Object method3() {...}It's common to combine the client version with transforms that will convert new POJOs into older POJOs for backwards compatibility.
// Call this method if Client-Version is at least 2.0. @RestOptions (path="/foobar" , clientVersion="2.0" )public NewPojo newMethod() {...}// Call this method if Client-Version is at least 1.1, but less than 2.0. @RestOptions (path="/foobar" , clientVersion="[1.1,2.0)" )@BeanConfig(swaps=NewToOldSwap. class )public NewPojo oldMethod() {return newMethod(); }Note that in the previous example, we're returning the exact same POJO, but using a transform to convert it into an older form. The old method could also just return back a completely different object. The range can be any of the following:
"[0,1.0)" = Less than 1.0. 1.0 and 1.0.0 does not match."[0,1.0]" = Less than or equal to 1.0. Note that 1.0.1 will match."1.0" = At least 1.0. 1.0 and 2.0 will match.
See Also:
- Returns:
- The annotation value.
- Default:
- ""
-
converters
Class<? extends RestConverter>[] convertersClass-level response converters.Associates one or more
converters
with this method.See Also:
RestOpContext.Builder.converters()
- Registering converters with REST resources.
- Returns:
- The annotation value.
- Default:
- {}
-
debug
Enable debug mode.Enables the following:
- HTTP request/response bodies are cached in memory for logging purposes.
- Request/response messages are automatically logged.
"true" - Debug is enabled for all requests."false" - Debug is disabled for all requests."conditional" - Debug is enabled only for requests that have aDebug: true header."" (or anything else) - Debug mode is inherited from class.
Notes:
-
Supports SVL Variables
(e.g.
"$L{my.localized.variable}" ).
See Also:
- Returns:
- The annotation value.
- Default:
- ""
-
defaultAccept
DefaultAccept header.The default value for the
Accept header if not specified on a request.This is a shortcut for using
defaultRequestHeaders()
for just this specific header.- Returns:
- The annotation value.
- Default:
- ""
-
defaultCharset
Default character encoding.The default character encoding for the request and response if not specified on the request.
Notes:
-
Supports SVL Variables
(e.g.
"$S{mySystemProperty}" ).
See Also:
- Returns:
- The annotation value.
- Default:
- ""
-
Supports SVL Variables
(e.g.
-
defaultRequestQueryData
Specifies default values for query parameters.Strings are of the format
"name=value" .Affects values returned by
RestRequest.getQueryParam(String)
when the parameter is not present on the request.Example:
@RestOptions (path="/*" , defaultRequestQueryData={"foo=bar" })public String doGet(@Query ("foo" ) Stringfoo ) {...}Notes:
-
You can use either
':' or'=' as the key/value delimiter. - Key and value is trimmed of whitespace.
-
Supports SVL Variables
(e.g.
"$S{mySystemProperty}" ).
- Returns:
- The annotation value.
- Default:
- {}
-
You can use either
-
defaultRequestAttributes
Default request attributes.Specifies default values for request attributes if they're not already set on the request.
Affects values returned by the following methods:
Example:
// Defined via annotation resolving to a config file setting with default value. @Rest (defaultRequestAttributes={"Foo=bar" ,"Baz: $C{REST/myAttributeValue}" })public class MyResource {// Override at the method level. @RestOptions (defaultRequestAttributes={"Foo: bar" })public Object myMethod() {...} }
Notes:
-
Supports SVL Variables
(e.g.
"$L{my.localized.variable}" ).
See Also:
-