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.remote;
014
015import static java.lang.annotation.ElementType.*;
016import static java.lang.annotation.RetentionPolicy.*;
017
018import java.io.*;
019import java.lang.annotation.*;
020import org.apache.juneau.annotation.*;
021import org.apache.juneau.http.annotation.*;
022
023/**
024 * Annotation applied to Java methods on REST proxy interface classes.
025 *
026 * <p>
027 * Note that this annotation is optional if you do not need to override any of the values.
028 *
029 * <h5 class='section'>See Also:</h5><ul>
030 *    <li class='link'><a class="doclink" href="../../../../../index.html#jrc.Proxies">REST Proxies</a>
031 * </ul>
032 */
033@Documented
034@Target(METHOD)
035@Retention(RUNTIME)
036@Inherited
037@AnnotationGroup(RemoteOp.class)
038public @interface RemoteOp {
039
040   /**
041    * REST service path.
042    *
043    * <p>
044    * If you do not specify a path, then the path is inferred from the Java method name.
045    *
046    * <h5 class='figure'>Example:</h5>
047    * <p class='bjava'>
048    *    <ja>@RemotePost</ja>
049    *    <jk>public void</jk> postPet(...);
050    * </p>
051    *
052    * <p>
053    * Note that you can also use {@link #value()} to specify the method name and path in shortened form.
054    *
055    * <ul class='values'>
056    *    <li>An absolute URL.
057    *    <li>A relative URL interpreted as relative to the root URL defined on the <c>RestClient</c> and/or {@link Remote#path()}.
058    *    <li>No path.
059    * </ul>
060    *
061    * @return The annotation value.
062    */
063   String path() default "";
064
065   /**
066    * Defines the HTTP method to use for REST calls.
067    *
068    * <p>
069    * If not specified, then the method is inferred from the Java method name.
070    *
071    * <h5 class='figure'>Example:</h5>
072    * <p class='bjava'>
073    *    <ja>@RemotePost</ja>
074    *    <jk>public void</jk> postPet(...);
075    * </p>
076    *
077    * <br>If the method cannot be inferred, then the default is <js>"GET"</js>.
078    *
079    * <p>
080    * Note that you can also use {@link #value()} to specify the method name and path in shortened form.
081    *
082    * @return The annotation value.
083    */
084   String method() default "";
085
086   /**
087    * The value the remote method returns.
088    *
089    * <ul class='values'>
090    *    <li>
091    *       {@link RemoteReturn#BODY} (default) - The body of the HTTP response converted to a POJO.
092    *       <br>The return type on the Java method can be any of the following:
093    *       <ul class='spaced-list'>
094    *          <li>
095    *             <jk>void</jk> - Don't parse any response.  Note that the method will still throw an exception if an
096    *             error HTTP status is returned.
097    *          <li>
098    *             Any parsable POJO - The body of the response will be converted to the POJO using the parser defined
099    *             on the <c>RestClient</c>.
100    *          <li>
101    *             Any POJO annotated with the {@link Response @Response} annotation.
102    *             This allows for response beans to be used which also allows for OpenAPI-based parsing and validation.
103    *          <li>
104    *             <c>HttpResponse</c> - Returns the raw <c>HttpResponse</c> returned by the inner
105    *             <c>HttpClient</c>.
106    *          <li>
107    *             {@link Reader} - Returns access to the raw reader of the response.
108    *          <li>
109    *             {@link InputStream} - Returns access to the raw input stream of the response.
110    *       </ul>
111    *    <li>
112    *       {@link RemoteReturn#STATUS} - The HTTP status code on the response.
113    *       <br>The return type on the Java method can be any of the following:
114    *       <ul>
115    *          <li><jk>int</jk>/<c>Integer</c> - The HTTP response code.
116    *          <li><jk>boolean</jk>/<c>Boolean</c> - <jk>true</jk> if the response code is <c>&lt;400</c>
117    *       </ul>
118    * </ul>
119    *
120    * @return The annotation value.
121    */
122   RemoteReturn returns() default RemoteReturn.BODY;
123
124   /**
125    * REST method name and path.
126    *
127    * <p>
128    * Can be used to provide a shortened combined form for the {@link #method()} and {@link #path()} values.
129    *
130    * <p>
131    * The following examples are considered equivalent.
132    * <p class='bjava'>
133    *    <jc>// Normal form</jc>
134    *    <ja>@RemoteOp</ja>(method=<jsf>PUT</jsf>, path=<js>"/{propertyName}"</js>)
135    *
136    *    <jc>// Shortened form</jc>
137    *    <ja>@RemoteOp</ja>(<js>"PUT /{propertyName}"</js>)
138    * </p>
139    *
140    * <h5 class='section'>Notes:</h5><ul>
141    *    <li class='note'>
142    *       The path portion is optional.
143    * </ul>
144    *
145    * @return The annotation value.
146    */
147   String value() default "";
148}