From 59c4293c387181e8ff83af2b1d53fb86c1b34353 Mon Sep 17 00:00:00 2001 From: Adam Walczak Date: Wed, 3 Dec 2014 19:14:45 +0100 Subject: [PATCH 1/4] JERSEY-2721 | fixed entity handling in proxy client --- .../jersey/client/proxy/WebResourceFactory.java | 15 ++++++++++++++- .../glassfish/jersey/client/proxy/MyResource.java | 5 +++++ .../jersey/client/proxy/MyResourceIfc.java | 4 ++++ .../org/glassfish/jersey/client/proxy/Valid.java | 4 ++++ .../client/proxy/WebResourceFactoryTest.java | 7 +++++++ 5 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 ext/proxy-client/src/test/java/org/glassfish/jersey/client/proxy/Valid.java diff --git a/ext/proxy-client/src/main/java/org/glassfish/jersey/client/proxy/WebResourceFactory.java b/ext/proxy-client/src/main/java/org/glassfish/jersey/client/proxy/WebResourceFactory.java index 343adb60e7..4df8ef89e5 100755 --- a/ext/proxy-client/src/main/java/org/glassfish/jersey/client/proxy/WebResourceFactory.java +++ b/ext/proxy-client/src/main/java/org/glassfish/jersey/client/proxy/WebResourceFactory.java @@ -47,6 +47,7 @@ import java.lang.reflect.Proxy; import java.lang.reflect.Type; import java.security.AccessController; +import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.HashMap; @@ -96,6 +97,9 @@ public final class WebResourceFactory implements InvocationHandler { private static final MultivaluedMap EMPTY_HEADERS = new MultivaluedHashMap(); private static final Form EMPTY_FORM = new Form(); + private static final List PARAM_ANNOTATION_CLASSES = Arrays.asList( + PathParam.class, QueryParam.class, HeaderParam.class, CookieParam.class, MatrixParam.class, FormParam.class + ); /** * Creates a new client-side representation of a resource described by @@ -201,7 +205,7 @@ public Object invoke(final Object proxy, final Method method, final Object[] arg } Annotation ann; Object value = args[i]; - if (anns.isEmpty()) { + if (!hasAnyParamAnnotation(anns)) { entityType = method.getGenericParameterTypes()[i]; entity = value; } else { @@ -335,6 +339,15 @@ public Object invoke(final Object proxy, final Method method, final Object[] arg return result; } + private boolean hasAnyParamAnnotation(Map anns) { + for (Class paramAnnotationClass : PARAM_ANNOTATION_CLASSES) { + if (anns.containsKey(paramAnnotationClass)) { + return true; + } + } + return false; + } + private Object[] convert(final Collection value) { return value.toArray(); } diff --git a/ext/proxy-client/src/test/java/org/glassfish/jersey/client/proxy/MyResource.java b/ext/proxy-client/src/test/java/org/glassfish/jersey/client/proxy/MyResource.java index b768ba41a4..dc56efbfab 100755 --- a/ext/proxy-client/src/test/java/org/glassfish/jersey/client/proxy/MyResource.java +++ b/ext/proxy-client/src/test/java/org/glassfish/jersey/client/proxy/MyResource.java @@ -57,6 +57,11 @@ public List postIt(List entity) { return entity; } + @Override + public MyBean postValid(@Valid MyBean entity) { + return entity; + } + @Override public String getId(String id) { return id; diff --git a/ext/proxy-client/src/test/java/org/glassfish/jersey/client/proxy/MyResourceIfc.java b/ext/proxy-client/src/test/java/org/glassfish/jersey/client/proxy/MyResourceIfc.java index 2203a00ae0..388780b8da 100755 --- a/ext/proxy-client/src/test/java/org/glassfish/jersey/client/proxy/MyResourceIfc.java +++ b/ext/proxy-client/src/test/java/org/glassfish/jersey/client/proxy/MyResourceIfc.java @@ -69,6 +69,10 @@ public interface MyResourceIfc { @Produces({MediaType.APPLICATION_XML}) List postIt(List entity); + @POST + @Produces({MediaType.APPLICATION_XML}) + MyBean postValid(@Valid MyBean entity); + @Path("{id}") @GET @Produces(MediaType.TEXT_PLAIN) diff --git a/ext/proxy-client/src/test/java/org/glassfish/jersey/client/proxy/Valid.java b/ext/proxy-client/src/test/java/org/glassfish/jersey/client/proxy/Valid.java new file mode 100644 index 0000000000..aacc1457ce --- /dev/null +++ b/ext/proxy-client/src/test/java/org/glassfish/jersey/client/proxy/Valid.java @@ -0,0 +1,4 @@ +package org.glassfish.jersey.client.proxy; + +public @interface Valid { +} diff --git a/ext/proxy-client/src/test/java/org/glassfish/jersey/client/proxy/WebResourceFactoryTest.java b/ext/proxy-client/src/test/java/org/glassfish/jersey/client/proxy/WebResourceFactoryTest.java index c3eeef0529..9cb2006164 100755 --- a/ext/proxy-client/src/test/java/org/glassfish/jersey/client/proxy/WebResourceFactoryTest.java +++ b/ext/proxy-client/src/test/java/org/glassfish/jersey/client/proxy/WebResourceFactoryTest.java @@ -88,6 +88,13 @@ public void testPostIt() { assertEquals("Ahoj", resource.postIt(Collections.singletonList(bean)).get(0).name); } + @Test + public void testPostValid() { + MyBean bean = new MyBean(); + bean.name = "Ahoj"; + assertEquals("Ahoj", resource.postValid(bean).name); + } + @Test public void testPathParam() { assertEquals("jouda", resource.getId("jouda")); From a676897b42d8caef92d56c6d9c71bc5dcd344464 Mon Sep 17 00:00:00 2001 From: Adam Walczak Date: Wed, 3 Dec 2014 19:19:45 +0100 Subject: [PATCH 2/4] JERSEY-2721 | test fix --- .../java/org/glassfish/jersey/client/proxy/MyResourceIfc.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ext/proxy-client/src/test/java/org/glassfish/jersey/client/proxy/MyResourceIfc.java b/ext/proxy-client/src/test/java/org/glassfish/jersey/client/proxy/MyResourceIfc.java index 388780b8da..9b92cb7347 100755 --- a/ext/proxy-client/src/test/java/org/glassfish/jersey/client/proxy/MyResourceIfc.java +++ b/ext/proxy-client/src/test/java/org/glassfish/jersey/client/proxy/MyResourceIfc.java @@ -70,6 +70,8 @@ public interface MyResourceIfc { List postIt(List entity); @POST + @Path("valid") + @Consumes({MediaType.APPLICATION_XML}) @Produces({MediaType.APPLICATION_XML}) MyBean postValid(@Valid MyBean entity); From db6fd2aa4e33a05f232e0250656f23aa65438ac7 Mon Sep 17 00:00:00 2001 From: Adam Walczak Date: Mon, 8 Dec 2014 09:36:31 +0100 Subject: [PATCH 3/4] JERSEY-2721 | licence info --- .../glassfish/jersey/client/proxy/Valid.java | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/ext/proxy-client/src/test/java/org/glassfish/jersey/client/proxy/Valid.java b/ext/proxy-client/src/test/java/org/glassfish/jersey/client/proxy/Valid.java index aacc1457ce..f74e21b976 100644 --- a/ext/proxy-client/src/test/java/org/glassfish/jersey/client/proxy/Valid.java +++ b/ext/proxy-client/src/test/java/org/glassfish/jersey/client/proxy/Valid.java @@ -1,3 +1,42 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 2012 Oracle and/or its affiliates. All rights reserved. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common Development + * and Distribution License("CDDL") (collectively, the "License"). You + * may not use this file except in compliance with the License. You can + * obtain a copy of the License at + * http://glassfish.java.net/public/CDDL+GPL_1_1.html + * or packager/legal/LICENSE.txt. See the License for the specific + * language governing permissions and limitations under the License. + * + * When distributing the software, include this License Header Notice in each + * file and include the License file at packager/legal/LICENSE.txt. + * + * GPL Classpath Exception: + * Oracle designates this particular file as subject to the "Classpath" + * exception as provided by Oracle in the GPL Version 2 section of the License + * file that accompanied this code. + * + * Modifications: + * If applicable, add the following below the License Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyright [year] [name of copyright owner]" + * + * Contributor(s): + * If you wish your version of this file to be governed by only the CDDL or + * only the GPL Version 2, indicate your decision by adding "[Contributor] + * elects to include this software in this distribution under the [CDDL or GPL + * Version 2] license." If you don't indicate a single choice of license, a + * recipient has the option to distribute your version of this file under + * either the CDDL, the GPL Version 2 or to extend the choice of license to + * its licensees as provided above. However, if you add GPL Version 2 code + * and therefore, elected the GPL Version 2 license, then the option applies + * only if the new code is made subject to such option by the copyright + * holder. + */ package org.glassfish.jersey.client.proxy; public @interface Valid { From 5eb6654894fc3f717d2dab97ab215a9fd51c84ad Mon Sep 17 00:00:00 2001 From: Adam Walczak Date: Mon, 8 Dec 2014 09:44:09 +0100 Subject: [PATCH 4/4] JERSEY-2721 | licence info --- .../src/test/java/org/glassfish/jersey/client/proxy/Valid.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ext/proxy-client/src/test/java/org/glassfish/jersey/client/proxy/Valid.java b/ext/proxy-client/src/test/java/org/glassfish/jersey/client/proxy/Valid.java index f74e21b976..eea58029e0 100644 --- a/ext/proxy-client/src/test/java/org/glassfish/jersey/client/proxy/Valid.java +++ b/ext/proxy-client/src/test/java/org/glassfish/jersey/client/proxy/Valid.java @@ -1,7 +1,7 @@ /* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. * - * Copyright (c) 2012 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2012-2014 Oracle and/or its affiliates. All rights reserved. * * The contents of this file are subject to the terms of either the GNU * General Public License Version 2 only ("GPL") or the Common Development