Repository: cxf Updated Branches: refs/heads/master d9a1164c3 -> 635578a9d
Updating JAXRS ClientProxy to use bean parameter annotations Project: http://git-wip-us.apache.org/repos/asf/cxf/repo Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/635578a9 Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/635578a9 Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/635578a9 Branch: refs/heads/master Commit: 635578a9d0a4cc1087795c26479585998d4a828f Parents: d9a1164 Author: Sergey Beryozkin <[email protected]> Authored: Mon Mar 10 22:10:40 2014 +0000 Committer: Sergey Beryozkin <[email protected]> Committed: Mon Mar 10 22:10:40 2014 +0000 ---------------------------------------------------------------------- .../cxf/jaxrs/client/ClientProxyImpl.java | 51 +++++++++++++------- 1 file changed, 33 insertions(+), 18 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cxf/blob/635578a9/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/ClientProxyImpl.java ---------------------------------------------------------------------- diff --git a/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/ClientProxyImpl.java b/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/ClientProxyImpl.java index 0d1f148..e6690e8 100644 --- a/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/ClientProxyImpl.java +++ b/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/ClientProxyImpl.java @@ -460,18 +460,18 @@ public class ClientProxyImpl extends AbstractClient implements } } for (Parameter p : beanParams) { - Map<String, Object> values = getValuesFromBeanParam(params[p.getIndex()], QueryParam.class); - for (Map.Entry<String, Object> entry : values.entrySet()) { + Map<String, BeanPair> values = getValuesFromBeanParam(params[p.getIndex()], QueryParam.class); + for (Map.Entry<String, BeanPair> entry : values.entrySet()) { if (entry.getValue() != null) { addMatrixQueryParamsToBuilder(ub, entry.getKey(), ParameterType.QUERY, - null, entry.getValue()); + entry.getValue().getAnns(), entry.getValue().getValue()); } } } } - private Map<String, Object> getValuesFromBeanParam(Object bean, Class<? extends Annotation> annClass) { - Map<String, Object> values = new HashMap<String, Object>(); + private Map<String, BeanPair> getValuesFromBeanParam(Object bean, Class<? extends Annotation> annClass) { + Map<String, BeanPair> values = new HashMap<String, BeanPair>(); for (Method m : bean.getClass().getMethods()) { Annotation annotation = m.getAnnotation(annClass); @@ -481,7 +481,7 @@ public class ClientProxyImpl extends AbstractClient implements Method getter = bean.getClass().getMethod("get" + propertyName, new Class[]{}); Object value = getter.invoke(bean, new Object[]{}); String annotationValue = AnnotationUtils.getAnnotationValue(annotation); - values.put(annotationValue, value); + values.put(annotationValue, new BeanPair(value, m.getParameterAnnotations()[0])); } catch (Throwable t) { // ignore } @@ -503,11 +503,11 @@ public class ClientProxyImpl extends AbstractClient implements } } for (Parameter p : beanParams) { - Map<String, Object> values = getValuesFromBeanParam(params[p.getIndex()], MatrixParam.class); - for (Map.Entry<String, Object> entry : values.entrySet()) { + Map<String, BeanPair> values = getValuesFromBeanParam(params[p.getIndex()], MatrixParam.class); + for (Map.Entry<String, BeanPair> entry : values.entrySet()) { if (entry.getValue() != null) { addMatrixQueryParamsToBuilder(ub, entry.getKey(), ParameterType.MATRIX, - null, entry.getValue()); + entry.getValue().getAnns(), entry.getValue().getValue()); } } } @@ -525,9 +525,9 @@ public class ClientProxyImpl extends AbstractClient implements addFormValue(form, p.getName(), params[p.getIndex()], getParamAnnotations(m, p)); } for (Parameter p : beanParams) { - Map<String, Object> values = getValuesFromBeanParam(params[p.getIndex()], FormParam.class); - for (Map.Entry<String, Object> entry : values.entrySet()) { - addFormValue(form, entry.getKey(), entry.getValue(), null); + Map<String, BeanPair> values = getValuesFromBeanParam(params[p.getIndex()], FormParam.class); + for (Map.Entry<String, BeanPair> entry : values.entrySet()) { + addFormValue(form, entry.getKey(), entry.getValue().getValue(), entry.getValue().getAnns()); } } @@ -579,11 +579,11 @@ public class ClientProxyImpl extends AbstractClient implements } } for (Parameter p : beanParams) { - Map<String, Object> values = getValuesFromBeanParam(params[p.getIndex()], HeaderParam.class); - for (Map.Entry<String, Object> entry : values.entrySet()) { + Map<String, BeanPair> values = getValuesFromBeanParam(params[p.getIndex()], HeaderParam.class); + for (Map.Entry<String, BeanPair> entry : values.entrySet()) { if (entry.getValue() != null) { headers.add(entry.getKey(), - convertParamValue(entry.getValue(), getParamAnnotations(m, p))); + convertParamValue(entry.getValue().getValue(), entry.getValue().getAnns())); } } } @@ -609,12 +609,13 @@ public class ClientProxyImpl extends AbstractClient implements } } for (Parameter p : beanParams) { - Map<String, Object> values = getValuesFromBeanParam(params[p.getIndex()], CookieParam.class); - for (Map.Entry<String, Object> entry : values.entrySet()) { + Map<String, BeanPair> values = getValuesFromBeanParam(params[p.getIndex()], CookieParam.class); + for (Map.Entry<String, BeanPair> entry : values.entrySet()) { if (entry.getValue() != null) { headers.add(HttpHeaders.COOKIE, entry.getKey() + "=" - + convertParamValue(entry.getValue(), getParamAnnotations(m, p))); + + convertParamValue(entry.getValue().getValue(), + entry.getValue().getAnns())); } } } @@ -805,4 +806,18 @@ public class ClientProxyImpl extends AbstractClient implements } + private static class BeanPair { + private Object value; + private Annotation[] anns; + public BeanPair(Object value, Annotation[] anns) { + this.value = value; + this.anns = anns; + } + public Object getValue() { + return value; + } + public Annotation[] getAnns() { + return anns; + } + } }
