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 a web request header. 029 * 030 * <p>Supported for annotated handler methods in Servlet and Portlet environments. 031 * 032 * <p>If the method parameter is {@link java.util.Map Map<String, String>}, 033 * {@link org.springframework.util.MultiValueMap MultiValueMap<String, String>}, 034 * or {@link org.springframework.http.HttpHeaders HttpHeaders} then the map is 035 * populated with all header names and values. 036 * 037 * @author Juergen Hoeller 038 * @author Sam Brannen 039 * @since 3.0 040 * @see RequestMapping 041 * @see RequestParam 042 * @see CookieValue 043 * @see org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter 044 * @see org.springframework.web.portlet.mvc.annotation.AnnotationMethodHandlerAdapter 045 */ 046@Target(ElementType.PARAMETER) 047@Retention(RetentionPolicy.RUNTIME) 048@Documented 049public @interface RequestHeader { 050 051 /** 052 * Alias for {@link #name}. 053 */ 054 @AliasFor("name") 055 String value() default ""; 056 057 /** 058 * The name of the request header to bind to. 059 * @since 4.2 060 */ 061 @AliasFor("value") 062 String name() default ""; 063 064 /** 065 * Whether the header is required. 066 * <p>Defaults to {@code true}, leading to an exception being thrown 067 * if the header is missing in the request. Switch this to 068 * {@code false} if you prefer a {@code null} value if the header 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}