001// *************************************************************************************************************************** 002// * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file * 003// * distributed with this work for additional information regarding copyright ownership. The ASF licenses this file * 004// * to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance * 005// * with the License. You may obtain a copy of the License at * 006// * * 007// * http://www.apache.org/licenses/LICENSE-2.0 * 008// * * 009// * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an * 010// * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the * 011// * specific language governing permissions and limitations under the License. * 012// *************************************************************************************************************************** 013package org.apache.juneau.rest.annotation; 014 015import static java.lang.annotation.ElementType.*; 016import static java.lang.annotation.RetentionPolicy.*; 017 018import java.lang.annotation.*; 019 020import org.apache.juneau.httppart.*; 021 022/** 023 * Annotation that can be applied to a parameter of a {@link RestMethod @RestMethod} annotated method to identify it as a HTTP 024 * request header converted to a POJO. 025 * 026 * <h5 class='section'>Example:</h5> 027 * <p class='bcode'> 028 * <ja>@RestMethod</ja>(name=<jsf>GET</jsf>) 029 * <jk>public void</jk> doGet(RestRequest req, RestResponse res, <ja>@Header</ja>(<js>"ETag"</js>) UUID etag) { 030 * ... 031 * } 032 * </p> 033 * 034 * <p> 035 * This is functionally equivalent to the following code... 036 * <p class='bcode'> 037 * <ja>@RestMethod</ja>(name=<jsf>GET</jsf>) 038 * <jk>public void</jk> doPostPerson(RestRequest req, RestResponse res) { 039 * UUID etag = req.getHeader(UUID.<jk>class</jk>, "ETag"); 040 * ... 041 * } 042 * </p> 043 * 044 * <h5 class='section'>See Also:</h5> 045 * <ul> 046 * <li class='link'><a class="doclink" href="../../../../../overview-summary.html#juneau-rest-server.Header">Overview > juneau-rest-server > @Header</a> 047 * </ul> 048 */ 049@Documented 050@Target(PARAMETER) 051@Retention(RUNTIME) 052@Inherited 053public @interface Header { 054 055 /** 056 * The default value for this header if it's not present in the request. 057 */ 058 String def() default ""; 059 060 /** 061 * HTTP header name. 062 */ 063 String name() default ""; 064 065 /** 066 * Specifies the {@link HttpPartParser} class used for parsing values from strings. 067 * 068 * <p> 069 * The default value for this parser is inherited from the servlet/method which defaults to {@link UonPartParser}. 070 * <br>You can use {@link SimplePartParser} to parse POJOs that are directly convertible from <code>Strings</code>. 071 */ 072 Class<? extends HttpPartParser> parser() default HttpPartParser.Null.class; 073 074 /** 075 * A synonym for {@link #name()}. 076 * 077 * <p> 078 * Allows you to use shortened notation if you're only specifying the name. 079 */ 080 String value() default ""; 081}