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

Commit 59c4293

Browse files
author
Adam Walczak
committed
JERSEY-2721 | fixed entity handling in proxy client
1 parent 99ab6ef commit 59c4293

File tree

5 files changed

+34
-1
lines changed

5 files changed

+34
-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: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,10 @@ public interface MyResourceIfc {
6969
@Produces({MediaType.APPLICATION_XML})
7070
List<MyBean> postIt(List<MyBean> entity);
7171

72+
@POST
73+
@Produces({MediaType.APPLICATION_XML})
74+
MyBean postValid(@Valid MyBean entity);
75+
7276
@Path("{id}")
7377
@GET
7478
@Produces(MediaType.TEXT_PLAIN)
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
package org.glassfish.jersey.client.proxy;
2+
3+
public @interface Valid {
4+
}

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)