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.*;
020
021import org.apache.juneau.http.annotation.*;
022
023/**
024 * Annotation applied to Java methods on REST proxy.
025 *
026 * <ul class='seealso'>
027 *    <li class='link'>{@doc juneau-rest-client.RestProxies}
028 * </ul>
029 */
030@Documented
031@Target(METHOD)
032@Retention(RUNTIME)
033@Inherited
034public @interface RemoteMethod {
035
036   /**
037    * REST service path.
038    *
039    * <p>
040    * The possible values are:
041    * <ul class='spaced-list'>
042    *    <li>An absolute URL.
043    *    <li>A relative URL interpreted as relative to the root URL defined on the <c>RestClient</c> and/or {@link Remote#path()}.
044    *    <li>No path.
045    * </ul>
046    *
047    * <p>
048    * If you do not specify a path, then the path is inferred from the Java method name.
049    *
050    * <h5 class='figure'>Example:</h5>
051    * <p class='bcode'>
052    *    <jc>// POST /pet</jc>
053    *    <ja>@RestMethod</ja>
054    *    <jk>public void</jk> postPet(...) {...}
055    * </p>
056    */
057   String path() default "";
058
059   /**
060    * Defines the HTTP method to use for REST calls.
061    *
062    * <p>
063    * If not specified, then the method is inferred from the Java method name.
064    *
065    * <h5 class='figure'>Example:</h5>
066    * <p class='bcode'>
067    *    <jc>// POST /pet</jc>
068    *    <ja>@RestMethod</ja>
069    *    <jk>public void</jk> postPet(...) {...}
070    * </p>
071    *
072    * <br>If the method cannot be inferred, then the default is <js>"GET"</js>.
073    */
074   String method() default "";
075
076   /**
077    * The value the remote method returns.
078    *
079    * <p>
080    * Possible values:
081    * <ul class='spaced-list'>
082    *    <li>
083    *       {@link RemoteReturn#BODY} (default) - The body of the HTTP response converted to a POJO.
084    *       <br>The return type on the Java method can be any of the following:
085    *       <ul class='spaced-list'>
086    *          <li>
087    *             <jk>void</jk> - Don't parse any response.  Note that the method will still throw an exception if an
088    *             error HTTP status is returned.
089    *          <li>
090    *             Any parsable POJO - The body of the response will be converted to the POJO using the parser defined
091    *             on the <c>RestClient</c>.
092    *          <li>
093    *             Any POJO annotated with the {@link Response @Response} annotation.
094    *             This allows for response beans to be used which also allows for OpenAPI-based parsing and validation.
095    *          <li>
096    *             <c>HttpResponse</c> - Returns the raw <c>HttpResponse</c> returned by the inner
097    *             <c>HttpClient</c>.
098    *          <li>
099    *             {@link Reader} - Returns access to the raw reader of the response.
100    *          <li>
101    *             {@link InputStream} - Returns access to the raw input stream of the response.
102    *       </ul>
103    *    <li>
104    *       {@link RemoteReturn#STATUS} - The HTTP status code on the response.
105    *       <br>The return type on the Java method can be any of the following:
106    *       <ul>
107    *          <li><jk>int</jk>/<c>Integer</c> - The HTTP response code.
108    *          <li><jk>boolean</jk>/<c>Boolean</c> - <jk>true</jk> if the response code is <c>&lt;400</c>
109    *       </ul>
110    * </ul>
111    */
112   RemoteReturn returns() default RemoteReturn.BODY;
113}