Annotation Interface CookieParam


@Documented @Retention(SOURCE) @Target(PARAMETER) public @interface CookieParam

Binds the value of an HTTP cookie to a Web route method parameter whose name indicates the name of the cookie.

The annotated parameter can be of any type as long as it can be decoded by a parameter converter.

When specifying a Web server route, a cookie parameter can be defined as optional when the method parameter is an Optional, it is otherwise considered as required and a MissingRequiredParameterException will be thrown if the route is invoked with the parameter missing.

If a request is received containing multiple cookies with the same name, the first one is bound unless the method parameter is an array, a Collection, a List or a Set in which case all values are bound. A parameter converter may also split raw values around a value separator (eg. value 1,2,3,4 can be bound to a list of integers).


 @WebRoute( ... )
 void route(@CookieParam int requiredCookie)

 @WebRoute( ... )
 void route(@CookieParam Optional<Integer> optionalCookie)

 @WebRoute( ... )
 void handler(@CookieParam List<Integer> multiValueCookie)
 
Since:
1.0
Author:
Jeremy Kuhn
See Also:
  • Optional Element Summary

    Optional Elements
    Modifier and Type
    Optional Element
    Description
    The cookie parameter name.
  • Element Details

    • name

      String name

      The cookie parameter name.

      This allows to override the name which is otherwise the Web route method parameter name, typically when the actual parameter name is not a valid Java identifier.

      Returns:
      a parameter name
      Default:
      ""