001/*
002 * Copyright 2002-2015 the original author or authors.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *      https://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016
017package org.springframework.web.bind.annotation;
018
019import java.lang.annotation.Documented;
020import java.lang.annotation.ElementType;
021import java.lang.annotation.Retention;
022import java.lang.annotation.RetentionPolicy;
023import java.lang.annotation.Target;
024
025import org.springframework.core.annotation.AliasFor;
026
027/**
028 * Annotation which indicates that a method parameter should be bound to an HTTP cookie.
029 *
030 * <p>Supported for annotated handler methods in Servlet and Portlet environments.
031 *
032 * <p>The method parameter may be declared as type {@link javax.servlet.http.Cookie}
033 * or as cookie value type (String, int, etc.).
034 *
035 * @author Juergen Hoeller
036 * @author Sam Brannen
037 * @since 3.0
038 * @see RequestMapping
039 * @see RequestParam
040 * @see RequestHeader
041 * @see org.springframework.web.bind.annotation.RequestMapping
042 * @see org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter
043 * @see org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter
044 * @see org.springframework.web.portlet.mvc.annotation.AnnotationMethodHandlerAdapter
045 */
046@Target(ElementType.PARAMETER)
047@Retention(RetentionPolicy.RUNTIME)
048@Documented
049public @interface CookieValue {
050
051        /**
052         * Alias for {@link #name}.
053         */
054        @AliasFor("name")
055        String value() default "";
056
057        /**
058         * The name of the cookie to bind to.
059         * @since 4.2
060         */
061        @AliasFor("value")
062        String name() default "";
063
064        /**
065         * Whether the cookie is required.
066         * <p>Defaults to {@code true}, leading to an exception being thrown
067         * if the cookie is missing in the request. Switch this to
068         * {@code false} if you prefer a {@code null} value if the cookie is
069         * not present in the request.
070         * <p>Alternatively, provide a {@link #defaultValue}, which implicitly
071         * sets this flag to {@code false}.
072         */
073        boolean required() default true;
074
075        /**
076         * The default value to use as a fallback.
077         * <p>Supplying a default value implicitly sets {@link #required} to
078         * {@code false}.
079         */
080        String defaultValue() default ValueConstants.DEFAULT_NONE;
081
082}