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..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 @@ -69,6 +69,12 @@ public interface MyResourceIfc { @Produces({MediaType.APPLICATION_XML}) List postIt(List entity); + @POST + @Path("valid") + @Consumes({MediaType.APPLICATION_XML}) + @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..eea58029e0 --- /dev/null +++ b/ext/proxy-client/src/test/java/org/glassfish/jersey/client/proxy/Valid.java @@ -0,0 +1,43 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * 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 + * 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 { +} 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"));