Skip to content
This repository was archived by the owner on May 28, 2018. It is now read-only.

Commit 3909277

Browse files
committed
Merge pull request #129 from walec51/bugfix/JERSEY-2721
JERSEY-2721 Fixed proxy client handling of entity method parameter annotations.
2 parents 05108f4 + 5eb6654 commit 3909277

File tree

5 files changed

+75
-1
lines changed

5 files changed

+75
-1
lines changed

ext/proxy-client/src/main/java/org/glassfish/jersey/client/proxy/WebResourceFactory.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
import java.lang.reflect.Proxy;
4848
import java.lang.reflect.Type;
4949
import java.security.AccessController;
50+
import java.util.Arrays;
5051
import java.util.Collection;
5152
import java.util.Collections;
5253
import java.util.HashMap;
@@ -96,6 +97,9 @@ public final class WebResourceFactory implements InvocationHandler {
9697

9798
private static final MultivaluedMap<String, Object> EMPTY_HEADERS = new MultivaluedHashMap<String, Object>();
9899
private static final Form EMPTY_FORM = new Form();
100+
private static final List<Class> PARAM_ANNOTATION_CLASSES = Arrays.<Class>asList(
101+
PathParam.class, QueryParam.class, HeaderParam.class, CookieParam.class, MatrixParam.class, FormParam.class
102+
);
99103

100104
/**
101105
* 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
201205
}
202206
Annotation ann;
203207
Object value = args[i];
204-
if (anns.isEmpty()) {
208+
if (!hasAnyParamAnnotation(anns)) {
205209
entityType = method.getGenericParameterTypes()[i];
206210
entity = value;
207211
} else {
@@ -335,6 +339,15 @@ public Object invoke(final Object proxy, final Method method, final Object[] arg
335339
return result;
336340
}
337341

342+
private boolean hasAnyParamAnnotation(Map<Class, Annotation> anns) {
343+
for (Class paramAnnotationClass : PARAM_ANNOTATION_CLASSES) {
344+
if (anns.containsKey(paramAnnotationClass)) {
345+
return true;
346+
}
347+
}
348+
return false;
349+
}
350+
338351
private Object[] convert(final Collection value) {
339352
return value.toArray();
340353
}

ext/proxy-client/src/test/java/org/glassfish/jersey/client/proxy/MyResource.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,11 @@ public List<MyBean> postIt(List<MyBean> entity) {
5757
return entity;
5858
}
5959

60+
@Override
61+
public MyBean postValid(@Valid MyBean entity) {
62+
return entity;
63+
}
64+
6065
@Override
6166
public String getId(String id) {
6267
return id;

ext/proxy-client/src/test/java/org/glassfish/jersey/client/proxy/MyResourceIfc.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,12 @@ public interface MyResourceIfc {
6969
@Produces({MediaType.APPLICATION_XML})
7070
List<MyBean> postIt(List<MyBean> entity);
7171

72+
@POST
73+
@Path("valid")
74+
@Consumes({MediaType.APPLICATION_XML})
75+
@Produces({MediaType.APPLICATION_XML})
76+
MyBean postValid(@Valid MyBean entity);
77+
7278
@Path("{id}")
7379
@GET
7480
@Produces(MediaType.TEXT_PLAIN)
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3+
*
4+
* Copyright (c) 2012-2014 Oracle and/or its affiliates. All rights reserved.
5+
*
6+
* The contents of this file are subject to the terms of either the GNU
7+
* General Public License Version 2 only ("GPL") or the Common Development
8+
* and Distribution License("CDDL") (collectively, the "License"). You
9+
* may not use this file except in compliance with the License. You can
10+
* obtain a copy of the License at
11+
* http://glassfish.java.net/public/CDDL+GPL_1_1.html
12+
* or packager/legal/LICENSE.txt. See the License for the specific
13+
* language governing permissions and limitations under the License.
14+
*
15+
* When distributing the software, include this License Header Notice in each
16+
* file and include the License file at packager/legal/LICENSE.txt.
17+
*
18+
* GPL Classpath Exception:
19+
* Oracle designates this particular file as subject to the "Classpath"
20+
* exception as provided by Oracle in the GPL Version 2 section of the License
21+
* file that accompanied this code.
22+
*
23+
* Modifications:
24+
* If applicable, add the following below the License Header, with the fields
25+
* enclosed by brackets [] replaced by your own identifying information:
26+
* "Portions Copyright [year] [name of copyright owner]"
27+
*
28+
* Contributor(s):
29+
* If you wish your version of this file to be governed by only the CDDL or
30+
* only the GPL Version 2, indicate your decision by adding "[Contributor]
31+
* elects to include this software in this distribution under the [CDDL or GPL
32+
* Version 2] license." If you don't indicate a single choice of license, a
33+
* recipient has the option to distribute your version of this file under
34+
* either the CDDL, the GPL Version 2 or to extend the choice of license to
35+
* its licensees as provided above. However, if you add GPL Version 2 code
36+
* and therefore, elected the GPL Version 2 license, then the option applies
37+
* only if the new code is made subject to such option by the copyright
38+
* holder.
39+
*/
40+
package org.glassfish.jersey.client.proxy;
41+
42+
public @interface Valid {
43+
}

ext/proxy-client/src/test/java/org/glassfish/jersey/client/proxy/WebResourceFactoryTest.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,13 @@ public void testPostIt() {
8888
assertEquals("Ahoj", resource.postIt(Collections.singletonList(bean)).get(0).name);
8989
}
9090

91+
@Test
92+
public void testPostValid() {
93+
MyBean bean = new MyBean();
94+
bean.name = "Ahoj";
95+
assertEquals("Ahoj", resource.postValid(bean).name);
96+
}
97+
9198
@Test
9299
public void testPathParam() {
93100
assertEquals("jouda", resource.getId("jouda"));

0 commit comments

Comments
 (0)