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.httppart.*; 021import org.apache.juneau.oapi.*; 022 023/** 024 * Request bean annotation. 025 * 026 * <p> 027 * Identifies an interface to use to interact with HTTP parts of an HTTP request through a bean. 028 * 029 * <p> 030 * Can be used in the following locations: 031 * <ul> 032 * <li>Arguments and argument-types of server-side <ja>@RestMethod</ja>-annotated methods. 033 * <li>Arguments and argument-types of client-side <ja>@RemoteResource</ja>-annotated interfaces. 034 * </ul> 035 * 036 * <h5 class='topic'>Arguments and argument-types of server-side @RestMethod-annotated methods</h5> 037 * 038 * Annotation that can be applied to a parameter of a <ja>@RestMethod</ja>-annotated method to identify it as an interface for retrieving HTTP parts through a bean interface. 039 * 040 * <h5 class='section'>Example:</h5> 041 * <p class='bcode w800'> 042 * <ja>@RestMethod</ja>(path=<js>"/mypath/{p1}/{p2}/*"</js>) 043 * <jk>public void</jk> myMethod(<ja>@Request</ja> MyRequest rb) {...} 044 * 045 * <jk>public interface</jk> MyRequest { 046 * 047 * <ja>@Path</ja> <jc>// Path variable name inferred from getter.</jc> 048 * String getP1(); 049 * 050 * <ja>@Path</ja>(<js>"p2"</js>) 051 * String getX(); 052 * 053 * <ja>@Path</ja>(<js>"/*"</js>) 054 * String getRemainder(); 055 * 056 * <ja>@Query</ja> 057 * String getQ1(); 058 * 059 * <jc>// Schema-based query parameter: Pipe-delimited lists of comma-delimited lists of integers.</jc> 060 * <ja>@Query</ja>( 061 * collectionFormat=<js>"pipes"</js> 062 * items=<ja>@Items</ja>( 063 * items=<ja>@SubItems</ja>( 064 * collectionFormat=<js>"csv"</js> 065 * type=<js>"integer"</js> 066 * ) 067 * ) 068 * ) 069 * <jk>int</jk>[][] getQ3(); 070 * 071 * <ja>@Header</ja>(<js>"*"</js>) 072 * Map<String,Object> getHeaders(); 073 * </p> 074 * <p class='bcode w800'> 075 * <jc>// Same as above but annotation defined on interface.</jc> 076 * <ja>@RestMethod</ja>(path=<js>"/mypath/{p1}/{p2}/*"</js>) 077 * <jk>public void</jk> myMethod(MyRequest rb) {...} 078 * 079 * <ja>@Request</ja> 080 * <jk>public interface</jk> MyRequest {...} 081 * 082 * <p> 083 * The return types of the getters must be the supported parameter types for the HTTP-part annotation used. 084 * <br>Schema-based serialization and parsing is allowed just as if used as individual parameter types. 085 * 086 * <h5 class='section'>See Also:</h5> 087 * <ul> 088 * <li class='link'>{@doc juneau-rest-server.HttpPartAnnotations.Request} 089 * </ul> 090 * 091 * <h5 class='topic'>Arguments and argument-types of client-side @RemoteResource-annotated interfaces</h5> 092 * 093 * Annotation applied to Java method arguments of interface proxies to denote a bean with remote resource annotations. 094 095 * <h5 class='section'>Example:</h5> 096 * <p class='bcode w800'> 097 * <ja>@RemoteResource</ja>(path=<js>"/myproxy"</js>) 098 * <jk>public interface</jk> MyProxy { 099 * 100 * <ja>@RemoteMethod</ja>(path=<js>"/mymethod/{p1}/{p2}"</js>) 101 * String myProxyMethod(<ja>@Request</ja> MyRequest bean); 102 * } 103 * 104 * <jk>public class</jk> MyRequest { 105 * 106 * <ja>@Path</ja> <jc>// Path variable name inferred from getter.</jc> 107 * <jk>public</jk> String getP1() {...} 108 * 109 * <ja>@Path</ja>(<js>"p2"</js>) 110 * <jk>public</jk> String getX() {...} 111 * 112 * <ja>@Path</ja>(<js>"/*"</js>) 113 * <jk>public</jk> String getRemainder() {...} 114 * 115 * <ja>@Query</ja> 116 * <jk>public</jk> String getQ1() {...} 117 * 118 * <jc>// Schema-based query parameter: Pipe-delimited lists of comma-delimited lists of integers.</jc> 119 * <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 * <jk>public</jk> <jk>int</jk>[][] getQ3() {...} 129 * 130 * <ja>@Header</ja>(<js>"*"</js>) 131 * <jk>public</jk> Map<String,Object> getHeaders() {...} 132 * } 133 * </p> 134 * 135 * <h5 class='section'>See Also:</h5> 136 * <ul class='doctree'> 137 * <li class='link'>{@doc juneau-rest-client.RestProxies.Request} 138 * </ul> 139 */ 140@Documented 141@Target({PARAMETER,TYPE}) 142@Retention(RUNTIME) 143@Inherited 144public @interface Request { 145 146 /** 147 * Specifies the {@link HttpPartSerializer} class used for serializing values to strings. 148 * 149 * <p> 150 * Overrides for this part the part serializer defined on the REST client which by default is {@link OpenApiSerializer}. 151 */ 152 Class<? extends HttpPartSerializer> partSerializer() default HttpPartSerializer.Null.class; 153 154 /** 155 * Specifies the {@link HttpPartParser} class used for parsing strings to values. 156 * 157 * <p> 158 * Overrides for this part the part parser defined on the REST resource which by default is {@link OpenApiParser}. 159 */ 160 Class<? extends HttpPartParser> partParser() default HttpPartParser.Null.class; 161}