This is an automated email from the ASF dual-hosted git repository.

jamesbognar pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/juneau.git


The following commit(s) were added to refs/heads/master by this push:
     new 31dceb4  RestClient tests.
31dceb4 is described below

commit 31dceb4882e1a576efb61801c16dfabd7ecac66c
Author: JamesBognar <[email protected]>
AuthorDate: Sat Jun 13 14:55:01 2020 -0400

    RestClient tests.
---
 .../apache/juneau/http/remote/RemoteMethod.java    |  5 ++-
 .../juneau/httppart/bean/RequestBeanMeta.java      | 10 ++---
 .../09.juneau-rest-client/01.RestProxies.html      | 24 ++++++++++--
 .../apache/juneau/rest/client2/RemotesTest.java    | 44 ++++++++++++++++++++++
 .../org/apache/juneau/rest/client/RestClient.java  | 10 +----
 .../rest/client/remote/RemoteMethodMeta.java       | 25 ++----------
 .../org/apache/juneau/rest/client2/RestClient.java | 13 +------
 .../apache/juneau/rest/mock2/MockRestClient.java   |  1 -
 8 files changed, 78 insertions(+), 54 deletions(-)

diff --git 
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/http/remote/RemoteMethod.java
 
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/http/remote/RemoteMethod.java
index 064489e..5b06fa5 100644
--- 
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/http/remote/RemoteMethod.java
+++ 
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/http/remote/RemoteMethod.java
@@ -21,7 +21,10 @@ import java.lang.annotation.*;
 import org.apache.juneau.http.annotation.*;
 
 /**
- * Annotation applied to Java methods on REST proxy.
+ * Annotation applied to Java methods on REST proxy interface classes.
+ *
+ * <p>
+ * Note that this annotation is optional if you do not need to override any of 
the values.
  *
  * <ul class='seealso'>
  *     <li class='link'>{@doc juneau-rest-client.RestProxies}
diff --git 
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/httppart/bean/RequestBeanMeta.java
 
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/httppart/bean/RequestBeanMeta.java
index 395724d..e176cc7 100644
--- 
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/httppart/bean/RequestBeanMeta.java
+++ 
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/httppart/bean/RequestBeanMeta.java
@@ -102,11 +102,7 @@ public class RequestBeanMeta {
                                if (m.isPublic()) {
                                        assertNoInvalidAnnotations(m, 
ResponseHeader.class, ResponseBody.class, ResponseStatus.class);
                                        String n = m.getSimpleName();
-                                       if (m.hasAnnotation(Body.class)) {
-                                               assertNoArgs(m, Body.class);
-                                               assertReturnNotVoid(m, 
Body.class);
-                                               properties.put(n, 
RequestBeanPropertyMeta.create(BODY, Body.class, m));
-                                       } else if 
(m.hasAnnotation(Header.class)) {
+                                       if (m.hasAnnotation(Header.class)) {
                                                assertNoArgs(m, Header.class);
                                                assertReturnNotVoid(m, 
Header.class);
                                                properties.put(n, 
RequestBeanPropertyMeta.create(HEADER, Header.class, m));
@@ -122,6 +118,10 @@ public class RequestBeanMeta {
                                                assertNoArgs(m, Path.class);
                                                assertReturnNotVoid(m, 
Path.class);
                                                properties.put(n, 
RequestBeanPropertyMeta.create(PATH, Path.class, m));
+                                       } else if (m.hasAnnotation(Body.class)) 
{
+                                               assertNoArgs(m, Body.class);
+                                               assertReturnNotVoid(m, 
Body.class);
+                                               properties.put(n, 
RequestBeanPropertyMeta.create(BODY, Body.class, m));
                                        }
                                }
                        }
diff --git a/juneau-doc/docs/Topics/09.juneau-rest-client/01.RestProxies.html 
b/juneau-doc/docs/Topics/09.juneau-rest-client/01.RestProxies.html
index 5e84350..42279c2 100644
--- a/juneau-doc/docs/Topics/09.juneau-rest-client/01.RestProxies.html
+++ b/juneau-doc/docs/Topics/09.juneau-rest-client/01.RestProxies.html
@@ -13,7 +13,8 @@
  
***************************************************************************************************************************/
  -->
 
-REST Proxies
+{8.1.4-updated} 
+Remote REST Proxies
 
 <p>
        The <c>juneau-rest-client</c> library can also be used to define 
interface proxies against 3rd-party REST interfaces.
@@ -38,8 +39,8 @@ REST Proxies
 <ul class='javatree'>
        <li class='jp'>{@link oaj.http.remote}
        <ul>
-               <li class='ja'>{@link oaj.http.remote.Remote}
-               <li class='ja'>{@link oaj.http.remote.RemoteMethod}
+               <li class='ja'>{@link oaj.http.remote.Remote} - Applied to 
interface class.
+               <li class='ja'>{@link oaj.http.remote.RemoteMethod} - Applied 
to interface methods.
        </ul>
        <li class='jp'>{@link oaj.http.annotation}
        <ul>
@@ -58,7 +59,7 @@ REST Proxies
        <ja>@Remote</ja>(path=<js>"/petstore"</js>)
        <jk>public interface</jk> PetStore {
                
-               <ja>@RemoteMethod</ja>(httpMethod=<jsf>POST</jsf>, 
path=<js>"/pets"</js>)
+               <ja>@RemoteMethod</ja>(method=<jsf>POST</jsf>, 
path=<js>"/pets"</js>)
                String addPet(
                        <ja>@Body</ja> CreatePet pet, 
                        <ja>@Header</ja>(<js>"E-Tag"</js>) UUID etag, 
@@ -88,3 +89,18 @@ REST Proxies
                price: 9.99 
        }
 </p>
+
+<p>
+       The <ja>@RemoteMethod</ja> annotations can be eliminated if you use 
specific naming conventions on your 
+       method names to identify the HTTP method and path. 
+</p>
+
+<h5 class='figure'>Example:</h5>
+<p class='bpcode w800'>        
+       <ja>@Remote</ja>(path=<js>"/petstore"</js>)
+       <jk>public interface</jk> PetStore {
+               
+               <jc>// @RemoteMethod optional since method and path is inferred 
from method name.</jc> 
+               String postPets(<ja>@Body</ja> CreatePet pet);
+       }
+</p>
diff --git 
a/juneau-rest/juneau-rest-client-utest/src/test/java/org/apache/juneau/rest/client2/RemotesTest.java
 
b/juneau-rest/juneau-rest-client-utest/src/test/java/org/apache/juneau/rest/client2/RemotesTest.java
index b9aa946..7322a57 100644
--- 
a/juneau-rest/juneau-rest-client-utest/src/test/java/org/apache/juneau/rest/client2/RemotesTest.java
+++ 
b/juneau-rest/juneau-rest-client-utest/src/test/java/org/apache/juneau/rest/client2/RemotesTest.java
@@ -16,8 +16,10 @@ import static org.junit.Assert.*;
 import static org.junit.runners.MethodSorters.*;
 
 import org.apache.juneau.rest.annotation.*;
+import org.apache.juneau.rest.client.remote.*;
 import org.apache.juneau.rest.config.*;
 import org.apache.juneau.http.remote.*;
+import org.apache.juneau.http.remote.RemoteMethod;
 import org.apache.juneau.rest.mock2.*;
 import org.junit.*;
 
@@ -286,12 +288,26 @@ public class RemotesTest {
                public String c01() {
                        return "foo";
                }
+
+               @RestMethod(path="c02")
+               public String c02() {
+                       return "bar";
+               }
+
+               @RestMethod(path="c03")
+               public String c03() {
+                       return "baz";
+               }
        }
 
        @Remote(path="/")
        public static interface C01i {
                @RemoteMethod
                public String c01();
+
+               public String c02();
+
+               public String getC03();
        }
 
        @Test
@@ -305,4 +321,32 @@ public class RemotesTest {
                assertEquals("foo", x.c01());
        }
 
+       @Test
+       public void c02_methodNotAnnotated() throws Exception {
+               C01i x = MockRestClient
+                       .create(C01.class)
+                       .json()
+                       .build()
+                       .getRemote(C01i.class, "http://localhost/C01";);
+
+               assertEquals("bar", x.c02());
+               assertEquals("baz", x.getC03());
+       }
+
+       @Test
+       public void c03_rootUriNotSpecified() throws Exception {
+               C01i x = MockRestClient
+                       .create(C01.class)
+                       .json()
+                       .rootUrl("")
+                       .build()
+                       .getRemote(C01i.class);
+
+               try {
+                       x.c01();
+                       fail();
+               } catch (RemoteMetadataException e) {
+                       assertEquals("Invalid remote definition found on class 
org.apache.juneau.rest.client2.RemotesTest$C01i. Root URI has not been 
specified.  Cannot construct absolute path to remote resource.", 
e.getLocalizedMessage());
+               }
+       }
 }
diff --git 
a/juneau-rest/juneau-rest-client/src/main/java/org/apache/juneau/rest/client/RestClient.java
 
b/juneau-rest/juneau-rest-client/src/main/java/org/apache/juneau/rest/client/RestClient.java
index 5861799..5eed9a6 100644
--- 
a/juneau-rest/juneau-rest-client/src/main/java/org/apache/juneau/rest/client/RestClient.java
+++ 
b/juneau-rest/juneau-rest-client/src/main/java/org/apache/juneau/rest/client/RestClient.java
@@ -1257,7 +1257,7 @@ public class RestClient extends BeanContext implements 
Closeable {
                                                                                
                        rc.formData(pn, val, sie, ps, schema);
                                                                                
                else if (pt == HEADER)
                                                                                
                        rc.header(pn, val, sie, ps, schema);
-                                                                               
                else if (pt == HttpPartType.BODY)
+                                                                               
                else
                                                                                
                        rc.requestBodySchema(schema).body(val);
                                                                                
        }
                                                                                
}
@@ -1265,14 +1265,6 @@ public class RestClient extends BeanContext implements 
Closeable {
                                                                }
                                                        }
 
-                                                       if 
(rmm.getOtherArgs().length > 0) {
-                                                               Object[] 
otherArgs = new Object[rmm.getOtherArgs().length];
-                                                               int i = 0;
-                                                               for 
(RemoteMethodArg a : rmm.getOtherArgs())
-                                                                       
otherArgs[i++] = args[a.getIndex()];
-                                                               
rc.body(otherArgs);
-                                                       }
-
                                                        RemoteMethodReturn rmr 
= rmm.getReturns();
                                                        if 
(rmr.getReturnValue() == RemoteReturn.NONE) {
                                                                rc.run();
diff --git 
a/juneau-rest/juneau-rest-client/src/main/java/org/apache/juneau/rest/client/remote/RemoteMethodMeta.java
 
b/juneau-rest/juneau-rest-client/src/main/java/org/apache/juneau/rest/client/remote/RemoteMethodMeta.java
index a3524db..9b17cf3 100644
--- 
a/juneau-rest/juneau-rest-client/src/main/java/org/apache/juneau/rest/client/remote/RemoteMethodMeta.java
+++ 
b/juneau-rest/juneau-rest-client/src/main/java/org/apache/juneau/rest/client/remote/RemoteMethodMeta.java
@@ -40,7 +40,7 @@ public class RemoteMethodMeta {
 
        private final String httpMethod;
        private final String fullPath, path;
-       private final RemoteMethodArg[] pathArgs, queryArgs, headerArgs, 
formDataArgs, otherArgs;
+       private final RemoteMethodArg[] pathArgs, queryArgs, headerArgs, 
formDataArgs;
        private final RemoteMethodBeanArg[] requestArgs;
        private final RemoteMethodArg bodyArg;
        private final RemoteMethodReturn methodReturn;
@@ -66,7 +66,6 @@ public class RemoteMethodMeta {
                this.formDataArgs = b.formDataArgs.toArray(new 
RemoteMethodArg[b.formDataArgs.size()]);
                this.headerArgs = b.headerArgs.toArray(new 
RemoteMethodArg[b.headerArgs.size()]);
                this.requestArgs = b.requestArgs.toArray(new 
RemoteMethodBeanArg[b.requestArgs.size()]);
-               this.otherArgs = b.otherArgs.toArray(new 
RemoteMethodArg[b.otherArgs.size()]);
                this.bodyArg = b.bodyArg;
                this.methodReturn = b.methodReturn;
                this.exceptions = m.getExceptionTypes();
@@ -78,8 +77,7 @@ public class RemoteMethodMeta {
                        pathArgs = new LinkedList<>(),
                        queryArgs = new LinkedList<>(),
                        headerArgs = new LinkedList<>(),
-                       formDataArgs = new LinkedList<>(),
-                       otherArgs = new LinkedList<>();
+                       formDataArgs = new LinkedList<>();
                List<RemoteMethodBeanArg>
                        requestArgs = new LinkedList<>();
                RemoteMethodArg bodyArg;
@@ -120,9 +118,7 @@ public class RemoteMethodMeta {
 
                        for (ParamInfo mpi : mi.getParams()) {
                                RemoteMethodArg rma = 
RemoteMethodArg.create(mpi);
-                               boolean annotated = false;
                                if (rma != null) {
-                                       annotated = true;
                                        HttpPartType pt = rma.getPartType();
                                        if (pt == HEADER)
                                                headerArgs.add(rma);
@@ -132,19 +128,13 @@ public class RemoteMethodMeta {
                                                formDataArgs.add(rma);
                                        else if (pt == PATH)
                                                pathArgs.add(rma);
-                                       else if (pt == BODY)
-                                               bodyArg = rma;
                                        else
-                                               annotated = false;
+                                               bodyArg = rma;
                                }
                                RequestBeanMeta rmba = 
RequestBeanMeta.create(mpi, PropertyStore.DEFAULT);
                                if (rmba != null) {
-                                       annotated = true;
                                        requestArgs.add(new 
RemoteMethodBeanArg(mpi.getIndex(), null, rmba));
                                }
-                               if (! annotated) {
-                                       otherArgs.add(new 
RemoteMethodArg(mpi.getIndex(), BODY, null));
-                               }
                        }
                }
        }
@@ -213,15 +203,6 @@ public class RemoteMethodMeta {
        }
 
        /**
-        * Returns the remaining non-annotated arguments on this Java method.
-        *
-        * @return A list of zero-indexed argument indices.
-        */
-       public RemoteMethodArg[] getOtherArgs() {
-               return otherArgs;
-       }
-
-       /**
         * Returns the argument annotated with {@link Body @Body}.
         *
         * @return A index of the argument with the {@link Body @Body} 
annotation, or <jk>null</jk> if no argument exists.
diff --git 
a/juneau-rest/juneau-rest-client/src/main/java/org/apache/juneau/rest/client2/RestClient.java
 
b/juneau-rest/juneau-rest-client/src/main/java/org/apache/juneau/rest/client2/RestClient.java
index cd77c8a..ae2edec 100644
--- 
a/juneau-rest/juneau-rest-client/src/main/java/org/apache/juneau/rest/client2/RestClient.java
+++ 
b/juneau-rest/juneau-rest-client/src/main/java/org/apache/juneau/rest/client2/RestClient.java
@@ -2960,9 +2960,6 @@ public class RestClient extends BeanContext implements 
HttpClient, Closeable, Re
                                        public Object invoke(Object proxy, 
Method method, Object[] args) throws Throwable {
                                                RemoteMethodMeta rmm = 
rm.getMethodMeta(method);
 
-                                               if (rmm == null)
-                                                       throw new 
RuntimeException("Method is not exposed as a remote method.");
-
                                                String url = rmm.getFullPath();
                                                if (url.indexOf("://") == -1)
                                                        url = restUrl2 + '/' + 
url;
@@ -3015,7 +3012,7 @@ public class RestClient extends BeanContext implements 
HttpClient, Closeable, Re
                                                                                
                        rc.formData(sie ? SKIP_IF_EMPTY_FLAGS : DEFAULT_FLAGS, 
pn, val, schema, ps);
                                                                                
                else if (pt == HEADER)
                                                                                
                        rc.header(sie ? SKIP_IF_EMPTY_FLAGS : DEFAULT_FLAGS, 
pn, val, schema, ps);
-                                                                               
                else if (pt == HttpPartType.BODY)
+                                                                               
                else /* (pt == HttpPartType.BODY) */
                                                                                
                        rc.body(val, schema);
                                                                                
        }
                                                                                
}
@@ -3023,14 +3020,6 @@ public class RestClient extends BeanContext implements 
HttpClient, Closeable, Re
                                                                }
                                                        }
 
-                                                       if 
(rmm.getOtherArgs().length > 0) {
-                                                               Object[] 
otherArgs = new Object[rmm.getOtherArgs().length];
-                                                               int i = 0;
-                                                               for 
(RemoteMethodArg a : rmm.getOtherArgs())
-                                                                       
otherArgs[i++] = args[a.getIndex()];
-                                                               
rc.body(otherArgs);
-                                                       }
-
                                                        RemoteMethodReturn rmr 
= rmm.getReturns();
                                                        if (rmr.isFuture()) {
                                                                return 
getExecutorService(true).submit(new Callable<Object>() {
diff --git 
a/juneau-rest/juneau-rest-mock/src/main/java/org/apache/juneau/rest/mock2/MockRestClient.java
 
b/juneau-rest/juneau-rest-mock/src/main/java/org/apache/juneau/rest/mock2/MockRestClient.java
index 5cdc6df..bd44843 100644
--- 
a/juneau-rest/juneau-rest-mock/src/main/java/org/apache/juneau/rest/mock2/MockRestClient.java
+++ 
b/juneau-rest/juneau-rest-mock/src/main/java/org/apache/juneau/rest/mock2/MockRestClient.java
@@ -300,7 +300,6 @@ public class MockRestClient extends RestClient implements 
HttpClientConnection {
                        psb.set(RESTCLIENT_rootUri, rootUrl);
                        return psb.build();
                } catch (Exception e) {
-                       e.printStackTrace();
                        throw new ConfigException(e, "Could not initialize 
MockRestClient");
                }
        }

Reply via email to