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