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.annotation; 018 019import static java.lang.annotation.ElementType.*; 020import static java.lang.annotation.RetentionPolicy.*; 021 022import java.lang.annotation.*; 023 024import org.apache.juneau.annotation.*; 025import org.apache.juneau.httppart.*; 026import org.apache.juneau.oapi.*; 027 028/** 029 * Request bean annotation. 030 * 031 * <p> 032 * Identifies an interface to use to interact with HTTP parts of an HTTP request through a bean. 033 * 034 * <p> 035 * Can be used in the following locations: 036 * <ul> 037 * <li>Arguments and argument-types of server-side <ja>@RestOp</ja>-annotated methods. 038 * <li>Arguments and argument-types of client-side <ja>@RemoteResource</ja>-annotated interfaces. 039 * </ul> 040 * 041 * <h5 class='topic'>Arguments and argument-types of server-side @RestOp-annotated methods</h5> 042 * <p> 043 * Annotation that can be applied to a parameter of a <ja>@RestOp</ja>-annotated method to identify it as an interface for retrieving HTTP parts through a bean interface. 044 * 045 * <h5 class='section'>Example:</h5> 046 * <p class='bjava'> 047 * <ja>@RestGet</ja>(<js>"/mypath/{p1}/{p2}/*"</js>) 048 * <jk>public void</jk> myMethod(<ja>@Request</ja> MyRequest <jv>requestBean</jv>) {...} 049 * 050 * <jk>public interface</jk> MyRequest { 051 * 052 * <ja>@Path</ja> <jc>// Path variable name inferred from getter.</jc> 053 * String getP1(); 054 * 055 * <ja>@Path</ja>(<js>"p2"</js>) 056 * String getX(); 057 * 058 * <ja>@Path</ja>(<js>"/*"</js>) 059 * String getRemainder(); 060 * 061 * <ja>@Query</ja> 062 * String getQ1(); 063 * 064 * <jc>// Schema-based query parameter: Pipe-delimited lists of comma-delimited lists of integers.</jc> 065 * <ja>@Query</ja>( 066 * collectionFormat=<js>"pipes"</js> 067 * items=<ja>@Items</ja>( 068 * items=<ja>@SubItems</ja>( 069 * collectionFormat=<js>"csv"</js> 070 * type=<js>"integer"</js> 071 * ) 072 * ) 073 * ) 074 * <jk>int</jk>[][] getQ3(); 075 * 076 * <ja>@Header</ja>(<js>"*"</js>) 077 * Map<String,Object> getHeaders(); 078 * </p> 079 * <p class='bjava'> 080 * <jc>// Same as above but annotation defined on interface.</jc> 081 * <ja>@RestGet</ja>(path=<js>"/mypath/{p1}/{p2}/*"</js>) 082 * <jk>public void</jk> myMethod(MyRequest <jv>requestBean</jv>) {...} 083 * 084 * <ja>@Request</ja> 085 * <jk>public interface</jk> MyRequest {...} 086 * 087 * <p> 088 * The return types of the getters must be the supported parameter types for the HTTP-part annotation used. 089 * <br>Schema-based serialization and parsing is allowed just as if used as individual parameter types. 090 * 091 * <h5 class='section'>See Also:</h5><ul> 092 * </ul> 093 * 094 * <h5 class='topic'>Arguments and argument-types of client-side @RemoteResource-annotated interfaces</h5> 095 * <p> 096 * Annotation applied to Java method arguments of interface proxies to denote a bean with remote resource annotations. 097 * 098 * <h5 class='section'>Example:</h5> 099 * <p class='bjava'> 100 * <ja>@RemoteResource</ja>(path=<js>"/myproxy"</js>) 101 * <jk>public interface</jk> MyProxy { 102 * 103 * <ja>@RemoteGet</ja>(<js>"/mymethod/{p1}/{p2}"</js>) 104 * String myProxyMethod(<ja>@Request</ja> MyRequest <jv>requestBean</jv>); 105 * } 106 * 107 * <jk>public class</jk> MyRequest { 108 * 109 * <ja>@Path</ja> <jc>// Path variable name inferred from getter.</jc> 110 * <jk>public</jk> String getP1() {...} 111 * 112 * <ja>@Path</ja>(<js>"p2"</js>) 113 * <jk>public</jk> String getX() {...} 114 * 115 * <ja>@Path</ja>(<js>"/*"</js>) 116 * <jk>public</jk> String getRemainder() {...} 117 * 118 * <ja>@Query</ja> 119 * <jk>public</jk> String getQ1() {...} 120 * 121 * <jc>// Schema-based query parameter: Pipe-delimited lists of comma-delimited lists of integers.</jc> 122 * <ja>@Query</ja>( 123 * schema=<ja>@Query</ja>( 124 * collectionFormat=<js>"pipes"</js> 125 * items=<ja>@Items</ja>( 126 * items=<ja>@SubItems</ja>( 127 * collectionFormat=<js>"csv"</js> 128 * type=<js>"integer"</js> 129 * ) 130 * ) 131 * ) 132 * ) 133 * <jk>public</jk> <jk>int</jk>[][] getQ3() {...} 134 * 135 * <ja>@Header</ja>(<js>"*"</js>) 136 * <jk>public</jk> Map<String,Object> getHeaders() {...} 137 * } 138 * </p> 139 * 140 * <h5 class='section'>See Also:</h5><ul> 141 * <li class='link'><a class="doclink" href="https://juneau.apache.org/docs/topics/Request">@Request</a> 142 * </ul> 143 * <p> 144 * <h5 class='section'>See Also:</h5><ul> 145 146 * </ul> 147 */ 148@Documented 149@Target({PARAMETER,TYPE,METHOD}) 150@Retention(RUNTIME) 151@Inherited 152@Repeatable(RequestAnnotation.Array.class) 153@ContextApply(RequestAnnotation.Applier.class) 154public @interface Request { 155 156 /** 157 * Optional description for the exposed API. 158 * 159 * @return The annotation value. 160 * @since 9.2.0 161 */ 162 String[] description() default {}; 163 164 /** 165 * Dynamically apply this annotation to the specified classes. 166 * 167 * <h5 class='section'>See Also:</h5><ul> 168 * <li class='link'><a class="doclink" href="https://juneau.apache.org/docs/topics/DynamicallyAppliedAnnotations">Dynamically Applied Annotations</a> 169 * </ul> 170 * 171 * @return The annotation value. 172 */ 173 String[] on() default {}; 174 175 /** 176 * Dynamically apply this annotation to the specified classes. 177 * 178 * <p> 179 * Identical to {@link #on()} except allows you to specify class objects instead of a strings. 180 * 181 * <h5 class='section'>See Also:</h5><ul> 182 * <li class='link'><a class="doclink" href="https://juneau.apache.org/docs/topics/DynamicallyAppliedAnnotations">Dynamically Applied Annotations</a> 183 * </ul> 184 * 185 * @return The annotation value. 186 */ 187 Class<?>[] onClass() default {}; 188 189 /** 190 * Specifies the {@link HttpPartParser} class used for parsing strings to values. 191 * 192 * <p> 193 * Overrides for this part the part parser defined on the REST resource which by default is {@link OpenApiParser}. 194 * 195 * @return The annotation value. 196 */ 197 Class<? extends HttpPartParser> parser() default HttpPartParser.Void.class; 198 199 /** 200 * Specifies the {@link HttpPartSerializer} class used for serializing values to strings. 201 * 202 * <p> 203 * Overrides for this part the part serializer defined on the REST client which by default is {@link OpenApiSerializer}. 204 * 205 * @return The annotation value. 206 */ 207 Class<? extends HttpPartSerializer> serializer() default HttpPartSerializer.Void.class; 208}