001/* 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017package org.apache.juneau.http; 018 019import static java.lang.annotation.ElementType.*; 020import static java.lang.annotation.RetentionPolicy.*; 021 022import java.lang.annotation.*; 023 024import org.apache.juneau.commons.*; 025 026/** 027 * REST request header annotation. 028 * 029 * <p> 030 * Identifies a POJO to be used as the header of an HTTP request. 031 * 032 * <p> 033 * Can be used in the following locations: 034 * <ul> 035 * <li>Arguments and argument-types of server-side <ja>@RestOp</ja>-annotated methods. 036 * <li>Arguments and argument-types of client-side <ja>@RemoteResource</ja>-annotated interfaces. 037 * <li>Methods and return types of server-side and client-side <ja>@Request</ja>-annotated interfaces. 038 * </ul> 039 * 040 * <h5 class='topic'>Arguments and argument-types of server-side @RestOp-annotated methods</h5> 041 * <p> 042 * Annotation that can be applied to a parameter of a <ja>@RestOp</ja>-annotated method to identify it as a HTTP 043 * request header. 044 * 045 * <h5 class='section'>Example:</h5> 046 * <p class='bjava'> 047 * <ja>@RestGet</ja> 048 * <jk>public void</jk> doGet(<ja>@Header</ja>(<js>"ETag"</js>) UUID <jv>etag</jv>) {...} 049 * </p> 050 * 051 * <p> 052 * This is functionally equivalent to the following code... 053 * <p class='bjava'> 054 * <ja>@RestGet</ja> 055 * <jk>public void</jk> doGet(RestRequest <jv>req</jv>, RestResponse <jv>res</jv>) { 056 * UUID <jv>etag</jv> = <jv>req</jv>.getHeader(<js>"ETag"</js>).as(UUID.<jk>class</jk>).orElse(<jk>null</jk>); 057 * ... 058 * } 059 * </p> 060 * 061 * <h5 class='section'>See Also:</h5><ul> 062 * <li class='link'><a class="doclink" href="https://juneau.apache.org/docs/topics/JuneauBeanSwagger2">juneau-bean-swagger-v2</a> 063 * <li class='extlink'><a class='doclink' href='https://swagger.io/specification/v2#parameterObject'>Swagger Parameter Object</a> 064 * </ul> 065 * 066 * <h5 class='topic'>Arguments and argument-types of client-side @RemoteResource-annotated interfaces</h5> 067 * <p> 068 * Annotation applied to Java method arguments of interface proxies to denote that they are serialized as an HTTP 069 * header value. 070 * 071 * <h5 class='section'>See Also:</h5><ul> 072 * <li class='link'><a class="doclink" href="https://juneau.apache.org/docs/topics/Header">@Header</a> 073 * </ul> 074 * 075 * <h5 class='topic'>Methods and return types of server-side and client-side @Request-annotated interfaces</h5> 076 * <p> 077 * <h5 class='section'>See Also:</h5><ul> 078 * <li class='link'><a class="doclink" href="https://juneau.apache.org/docs/topics/Request">@Request</a> 079 * </ul> 080 * <p> 081 */ 082@Documented 083@Target({ PARAMETER, METHOD, TYPE, FIELD }) 084@Retention(RUNTIME) 085@Inherited 086public @interface Header { 087 088 /** 089 * Default value for this parameter. 090 * 091 * @return The annotation value. 092 */ 093 String def() default ""; 094 095 /** 096 * Optional description for the exposed API. 097 * 098 * @return The annotation value. 099 * @since 9.2.0 100 */ 101 String[] description() default {}; 102 103 /** 104 * Short, concise summary of the exposed API. 105 * 106 * <p> 107 * Intended as a brief, single-line description suitable for AI/LLM consumption, compact documentation, 108 * or any context where brevity matters. See {@link Schema#summary()} 109 * for the canonical definition. 110 * 111 * @return The annotation value. 112 * @since 10.0.0 113 */ 114 String summary() default ""; 115 116 /** 117 * HTTP header name. 118 * <p> 119 * A blank value (the default) indicates to reuse the bean property name when used on a request bean property. 120 * 121 * <p> 122 * The value should be either a valid HTTP header name, or <js>"*"</js> to represent multiple name/value pairs 123 * 124 * <p> 125 * A blank value (the default) has the following behavior: 126 * <ul class='spaced-list'> 127 * <li> 128 * If the data type is <c>NameValuePairs</c>, <c>Map</c>, or a bean, 129 * then it's the equivalent to <js>"*"</js> which will cause the value to be serialized as name/value pairs. 130 * 131 * <h5 class='figure'>Examples:</h5> 132 * <p class='bjava'> 133 * <jc>// When used on a REST method</jc> 134 * <ja>@RestPost</ja>(<js>"/addPet"</js>) 135 * <jk>public void</jk> addPet(<ja>@Header</ja> JsonMap <jv>allHeaderParameters</jv>) {...} 136 * </p> 137 * <p class='bjava'> 138 * <jc>// When used on a remote method parameter</jc> 139 * <ja>@RemoteResource</ja>(path=<js>"/myproxy"</js>) 140 * <jk>public interface</jk> MyProxy { 141 * 142 * <jc>// Equivalent to @Header("*")</jc> 143 * <ja>@RemoteGet</ja>(<js>"/mymethod"</js>) 144 * String myProxyMethod1(<ja>@Header</ja> Map<String,Object> <jv>allHeaderParameters</jv>); 145 * } 146 * </p> 147 * <p class='bjava'> 148 * <jc>// When used on a request bean method</jc> 149 * <jk>public interface</jk> MyRequest { 150 * 151 * <jc>// Equivalent to @Header("*")</jc> 152 * <ja>@Header</ja> 153 * Map<String,Object> getFoo(); 154 * } 155 * </p> 156 * </li> 157 * <li> 158 * If used on a request bean method, uses the bean property name. 159 * 160 * <h5 class='figure'>Example:</h5> 161 * <p class='bjava'> 162 * <jk>public interface</jk> MyRequest { 163 * 164 * <jc>// Equivalent to @Header("Foo")</jc> 165 * <ja>@Header</ja> 166 * <ja>@BeanProp</ja>(<js>"Foo"</js>) 167 * String getFoo(); 168 * } 169 * </p> 170 * </li> 171 * </ul> 172 * 173 * @return The annotation value. 174 */ 175 String name() default ""; 176 177 /** 178 * <mk>schema</mk> field of the <a class='doclink' href='https://swagger.io/specification/v2#parameterObject'>Swagger Parameter Object</a>. 179 * 180 * <p> 181 * The schema defining the type used for parameter. 182 * 183 * <p> 184 * The {@link Schema @Schema} annotation can also be used standalone on the parameter or type. 185 * Values specified on this field override values specified on the type, and values specified on child types override values 186 * specified on parent types. 187 * 188 * <h5 class='section'>Used for:</h5> 189 * <ul class='spaced-list'> 190 * <li> 191 * Server-side schema-based parsing and parsing validation. 192 * <li> 193 * Server-side generated Swagger documentation. 194 * <li> 195 * Client-side schema-based serializing and serializing validation. 196 * </ul> 197 * 198 * @return The annotation value. 199 */ 200 Schema schema() default @Schema; 201 202 /** 203 * A synonym for {@link #name()}. 204 * 205 * <p> 206 * Allows you to use shortened notation if you're only specifying the name. 207 * 208 * <p> 209 * The following are completely equivalent ways of defining a header entry: 210 * <p class='bjava'> 211 * <jk>public</jk> Order placeOrder(<ja>@Header</ja>(name=<js>"api_key"</js>) String <jv>apiKey</jv>) {...} 212 * </p> 213 * <p class='bjava'> 214 * <jk>public</jk> Order placeOrder(<ja>@Header</ja>(<js>"api_key"</js>) String <jv>apiKey</jv>) {...} 215 * </p> 216 * 217 * @return The annotation value. 218 */ 219 String value() default ""; 220}