Annotation Type RestOptions


Identifies a REST OPTIONS operation Java method on a RestServlet implementation class.

This is a specialized subtype of @RestOp(method=OPTIONS).

See Also:
  • 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-level response converters.

      Associates one or more converters with this method.

      See Also:
      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 a Debug: true header.
      • "" (or anything else) - Debug mode is inherited from class.
      Notes:
      See Also:
      Returns:
      The annotation value.
      Default:
      ""
    • defaultAccept

      Default Accept 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:
      See Also:
      Returns:
      The annotation value.
      Default:
      ""
    • 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") String foo) {...}

      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:
      {}
    • 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:
    See Also: