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&lt;String,Object&gt; 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 * <ul class='seealso'>
087 *    <li class='link'>{@doc RestRequestAnnotation}
088 * </ul>
089 *
090 * <h5 class='topic'>Arguments and argument-types of client-side @RemoteResource-annotated interfaces</h5>
091 *
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='bcode w800'>
096 *    <ja>@RemoteResource</ja>(path=<js>"/myproxy"</js>)
097 *    <jk>public interface</jk> MyProxy {
098 *
099 *       <ja>@RemoteMethod</ja>(path=<js>"/mymethod/{p1}/{p2}"</js>)
100 *       String myProxyMethod(<ja>@Request</ja> MyRequest bean);
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 *          collectionFormat=<js>"pipes"</js>
120 *          items=<ja>@Items</ja>(
121 *             items=<ja>@SubItems</ja>(
122 *                collectionFormat=<js>"csv"</js>
123 *                type=<js>"integer"</js>
124 *             )
125 *          )
126 *       )
127 *       <jk>public</jk> <jk>int</jk>[][] getQ3() {...}
128 *
129 *       <ja>@Header</ja>(<js>"*"</js>)
130 *       <jk>public</jk> Map&lt;String,Object&gt; getHeaders() {...}
131 *    }
132 * </p>
133 *
134 * <ul class='seealso'>
135 *    <li class='link'>{@doc RestcRequest}
136 * </ul>
137 */
138@Documented
139@Target({PARAMETER,TYPE})
140@Retention(RUNTIME)
141@Inherited
142public @interface Request {
143
144   /**
145    * Specifies the {@link HttpPartSerializer} class used for serializing values to strings.
146    *
147    * <p>
148    * Overrides for this part the part serializer defined on the REST client which by default is {@link OpenApiSerializer}.
149    */
150   Class<? extends HttpPartSerializer> serializer() default HttpPartSerializer.Null.class;
151
152   /**
153    * Specifies the {@link HttpPartParser} class used for parsing strings to values.
154    *
155    * <p>
156    * Overrides for this part the part parser defined on the REST resource which by default is {@link OpenApiParser}.
157    */
158   Class<? extends HttpPartParser> parser() default HttpPartParser.Null.class;
159}