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.remoteable;
014
015import static java.lang.annotation.ElementType.*;
016import static java.lang.annotation.RetentionPolicy.*;
017
018import java.io.*;
019import java.lang.annotation.*;
020
021/**
022 * Annotation applied to Java methods on interface proxy classes.
023 * 
024 * <p>
025 * The return type on the Java method can be any of the following:
026 * <ul>
027 *    <li><jk>void</jk> - Don't parse any response.  Note that the method will still throw an exception if an error
028 *       HTTP status is returned.
029 *    <li>Any parsable POJO - The body of the response will be converted to the POJO using the parser defined on the
030 *       <code>RestClient</code>.
031 *    <li><code>HttpResponse</code> - Returns the raw <code>HttpResponse</code> returned by the inner
032 *       <code>HttpClient</code>.
033 *    <li>{@link Reader} - Returns access to the raw reader of the response.
034 *    <li>{@link InputStream} - Returns access to the raw input stream of the response.
035 * </ul>
036 * 
037 * <h5 class='section'>See Also:</h5>
038 * <ul class='doctree'>
039 *    <li class='link'><a class='doclink' href='../../../../overview-summary.html#juneau-rest-client.3rdPartyProxies'>Overview &gt; juneau-rest-client &gt; Interface Proxies Against 3rd-party REST Interfaces</a>
040 * </ul>
041 */
042@Documented
043@Target(METHOD)
044@Retention(RUNTIME)
045@Inherited
046public @interface RemoteMethod {
047
048   /**
049    * The path to the REST service for this Java method relative to the parent proxy interface URL.
050    * 
051    * <p>
052    * The default value is the Java method name (e.g. <js>"http://localhost/root-url/org.foo.MyInterface/myMethod"</js>)
053    * if {@link Remoteable#methodPaths() @Remoteable.methodPaths()} is <js>"NAME"</js>, or the Java method signature
054    * (e.g. <js>"http://localhost/root-url/org.foo.MyInterface/myMethod(int,boolean,java.lang.String)"</js>) if
055    * it's <js>"SIGNATURE"</js>.
056    */
057   String path() default "";
058
059   /**
060    * Defines the HTTP method to use for REST calls.
061    * 
062    * <p>
063    * Possible values:
064    * <ul>
065    *    <li><jsf>POST</jsf> (default) - Parameters are serialized using the serializer registered with the RestClient.
066    *    <li><jsf>GET</jsf> - Parameters are serialized using the UrlEncodingSerializer registered with the RestClient.
067    * </ul>
068    * 
069    * <p>
070    * The default value is <js>"POST"</js>.
071    */
072   String httpMethod() default "POST";
073
074   /**
075    * The value the remoteable method returns.
076    * 
077    * <p>
078    * Possible values:
079    * <ul>
080    *    <li>
081    *       {@link ReturnValue#BODY} (default) - The body of the HTTP response converted to a POJO.
082    *       <br>The return type on the Java method can be any of the following:
083    *       <ul>
084    *          <li><jk>void</jk> - Don't parse any response.  Note that the method will still throw an exception if an
085    *                error HTTP status is returned.
086    *          <li>Any parsable POJO - The body of the response will be converted to the POJO using the parser defined
087    *                on the <code>RestClient</code>.
088    *          <li><code>HttpResponse</code> - Returns the raw <code>HttpResponse</code> returned by the inner
089    *                <code>HttpClient</code>.
090    *          <li>{@link Reader} - Returns access to the raw reader of the response.
091    *          <li>{@link InputStream} - Returns access to the raw input stream of the response.
092    *       </ul>
093    *    <li>
094    *       {@link ReturnValue#HTTP_STATUS} - The HTTP status code on the response.
095    *       <br>The return type on the Java method can be any of the following:
096    *       <ul>
097    *          <li><jk>int</jk>/<code>Integer</code> - The HTTP response code.
098    *          <li><jk>boolean</jk>/<code>Boolean</code> - <jk>true</jk> if the response code is <code>&lt;400</code>
099    *       </ul>
100    * </ul>
101    */
102   ReturnValue returns() default ReturnValue.BODY;
103}