cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1414277 - in /cxf/trunk: rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/ rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ rt/frontend/jaxrs/src/main/java/org/a...
Date Tue, 27 Nov 2012 17:33:01 GMT
Author: sergeyb
Date: Tue Nov 27 17:32:57 2012
New Revision: 1414277

URL: http://svn.apache.org/viewvc?rev=1414277&view=rev
Log:
Support for JAX-RS 2.0 BeanParam

Modified:
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/AbstractJAXRSFactoryBean.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/ClassResourceInfo.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/ParameterType.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ProviderFactory.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/AnnotationUtils.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/ResourceUtils.java
    cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java
    cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/AbstractJAXRSFactoryBean.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/AbstractJAXRSFactoryBean.java?rev=1414277&r1=1414276&r2=1414277&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/AbstractJAXRSFactoryBean.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/AbstractJAXRSFactoryBean.java
Tue Nov 27 17:32:57 2012
@@ -26,6 +26,7 @@ import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 import java.util.ResourceBundle;
+import java.util.Set;
 import java.util.logging.Logger;
 
 import javax.ws.rs.NotFoundException;
@@ -45,7 +46,11 @@ import org.apache.cxf.endpoint.AbstractE
 import org.apache.cxf.endpoint.Endpoint;
 import org.apache.cxf.endpoint.EndpointException;
 import org.apache.cxf.endpoint.EndpointImpl;
+import org.apache.cxf.jaxrs.model.BeanParamInfo;
 import org.apache.cxf.jaxrs.model.ClassResourceInfo;
+import org.apache.cxf.jaxrs.model.OperationResourceInfo;
+import org.apache.cxf.jaxrs.model.Parameter;
+import org.apache.cxf.jaxrs.model.ParameterType;
 import org.apache.cxf.jaxrs.model.UserResource;
 import org.apache.cxf.jaxrs.provider.DataBindingProvider;
 import org.apache.cxf.jaxrs.provider.ProviderFactory;
@@ -327,11 +332,32 @@ public class AbstractJAXRSFactoryBean ex
         if (schemaLocations != null) {
             factory.setSchemaLocations(schemaLocations);
         }
+        
+        setBeanInfo(factory);
+        
         ep.put(ProviderFactory.class.getName(), factory);
         getBus().setProperty(ProviderFactory.class.getName(), factory);
         return factory;
     }
 
+    protected void setBeanInfo(ProviderFactory factory) {
+        List<ClassResourceInfo> cris = serviceFactory.getClassResourceInfo();
+        for (ClassResourceInfo cri : cris) {
+            Set<OperationResourceInfo> oris = cri.getMethodDispatcher().getOperationResourceInfos();
+            for (OperationResourceInfo ori : oris) {
+                List<Parameter> params = ori.getParameters();
+                for (Parameter param : params) {
+                    if (param.getType() == ParameterType.BEAN) {
+                        Class<?> cls = ori.getMethodToInvoke().getParameterTypes()[param.getIndex()];
+                        BeanParamInfo bpi = new BeanParamInfo(cls, getBus());
+                        factory.addBeanParamInfo(bpi);
+                    }
+                }
+            }
+        }
+        
+    }
+    
     protected void setDataBindingProvider(ProviderFactory factory, Service s) {
         
         List<ClassResourceInfo> cris = serviceFactory.getRealClassResourceInfo();

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/ClassResourceInfo.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/ClassResourceInfo.java?rev=1414277&r1=1414276&r2=1414277&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/ClassResourceInfo.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/ClassResourceInfo.java
Tue Nov 27 17:32:57 2012
@@ -19,10 +19,6 @@
 
 package org.apache.cxf.jaxrs.model;
 
-import java.lang.annotation.Annotation;
-import java.lang.reflect.Field;
-import java.lang.reflect.Method;
-import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.HashSet;
@@ -43,7 +39,7 @@ import org.apache.cxf.jaxrs.utils.Inject
 import org.apache.cxf.jaxrs.utils.JAXRSUtils;
 import org.apache.cxf.jaxrs.utils.ResourceUtils;
 
-public class ClassResourceInfo extends AbstractResourceInfo {
+public class ClassResourceInfo extends BeanResourceInfo {
     
     private URITemplate uriTemplate;
     private MethodDispatcher methodDispatcher;
@@ -51,8 +47,6 @@ public class ClassResourceInfo extends A
     private ConcurrentHashMap<SubresourceKey, ClassResourceInfo> subResources 
         = new ConcurrentHashMap<SubresourceKey, ClassResourceInfo>();
    
-    private List<Field> paramFields;
-    private List<Method> paramMethods;
     private boolean enableStatic;
     private boolean createdFromModel; 
     private String consumesTypes;
@@ -68,8 +62,10 @@ public class ClassResourceInfo extends A
             this.uriTemplate = cri.uriTemplate;    
             this.methodDispatcher = new MethodDispatcher(cri.methodDispatcher, this);
             this.subResources = cri.subResources;
+            //CHECKSTYLE:OFF
             this.paramFields = cri.paramFields;
             this.paramMethods = cri.paramMethods;
+            //CHECKSTYLE:ON
             this.enableStatic = true;
             this.nameBindings = cri.nameBindings;
             this.parent = cri.parent;
@@ -84,8 +80,6 @@ public class ClassResourceInfo extends A
         super(theResourceClass, theServiceClass, theRoot, bus);
         this.enableStatic = enableStatic;
         if (root && resourceClass != null) {
-            setParamField(serviceClass);
-            setParamMethods(serviceClass);
             nameBindings = AnnotationUtils.getNameBindings(serviceClass.getAnnotations());
         }
     }
@@ -186,42 +180,7 @@ public class ClassResourceInfo extends A
         return methods;
     }
     
-    private void setParamField(Class<?> cls) {
-        if (Object.class == cls || cls == null) {
-            return;
-        }
-        for (Field f : cls.getDeclaredFields()) {
-            for (Annotation a : f.getAnnotations()) {
-                if (AnnotationUtils.isParamAnnotationClass(a.annotationType())) {
-                    if (paramFields == null) {
-                        paramFields = new ArrayList<Field>();
-                    }
-                    paramFields.add(f);
-                }
-            }
-        }
-        setParamField(cls.getSuperclass());
-    }
     
-    private void setParamMethods(Class<?> cls) {
-        
-        for (Method m : cls.getMethods()) {
-        
-            if (!m.getName().startsWith("set") || m.getParameterTypes().length != 1) {
-                continue;
-            }
-            for (Annotation a : m.getAnnotations()) {
-                if (AnnotationUtils.isParamAnnotationClass(a.annotationType())) {
-                    checkParamMethod(m, AnnotationUtils.getAnnotationValue(a));
-                    break;
-                }
-            }
-        }
-        Class<?>[] interfaces = cls.getInterfaces();
-        for (Class<?> i : interfaces) {
-            setParamMethods(i);
-        }
-    }
 
     public URITemplate getURITemplate() {
         return uriTemplate;
@@ -284,31 +243,6 @@ public class ClassResourceInfo extends A
         return AnnotationUtils.getClassAnnotation(getServiceClass(), Path.class);
     }
     
-    private void addParamMethod(Method m) {
-        if (paramMethods == null) {
-            paramMethods = new ArrayList<Method>();
-        }
-        paramMethods.add(m);
-    }
-    
-    @SuppressWarnings("unchecked")
-    public List<Method> getParameterMethods() {
-        return paramMethods == null ? Collections.EMPTY_LIST 
-                                    : Collections.unmodifiableList(paramMethods);
-    }
-    
-    @SuppressWarnings("unchecked")
-    public List<Field> getParameterFields() {
-        return paramFields == null ? Collections.EMPTY_LIST 
-                                    : Collections.unmodifiableList(paramFields);
-    }
-    
-    private void checkParamMethod(Method m, String value) {
-        if (m.getName().equalsIgnoreCase("set" + value)) {
-            addParamMethod(m);
-        }
-    }
-    
     @Override
     public boolean isSingleton() {
         return resourceProvider != null && resourceProvider.isSingleton();

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/ParameterType.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/ParameterType.java?rev=1414277&r1=1414276&r2=1414277&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/ParameterType.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/ParameterType.java
Tue Nov 27 17:32:57 2012
@@ -26,6 +26,7 @@ public enum ParameterType {
     HEADER,
     COOKIE,
     FORM,
+    BEAN,
     
     REQUEST_BODY,
     CONTEXT,

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ProviderFactory.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ProviderFactory.java?rev=1414277&r1=1414276&r2=1414277&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ProviderFactory.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ProviderFactory.java
Tue Nov 27 17:32:57 2012
@@ -28,6 +28,7 @@ import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.Comparator;
+import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Iterator;
 import java.util.LinkedHashMap;
@@ -77,6 +78,7 @@ import org.apache.cxf.jaxrs.impl.Request
 import org.apache.cxf.jaxrs.impl.ResourceInfoImpl;
 import org.apache.cxf.jaxrs.impl.WebApplicationExceptionMapper;
 import org.apache.cxf.jaxrs.impl.WriterInterceptorMBW;
+import org.apache.cxf.jaxrs.model.BeanParamInfo;
 import org.apache.cxf.jaxrs.model.ClassResourceInfo;
 import org.apache.cxf.jaxrs.model.OperationResourceInfo;
 import org.apache.cxf.jaxrs.model.ProviderInfo;
@@ -157,6 +159,10 @@ public final class ProviderFactory {
     private ProviderInfo<Application> application;
     private List<DynamicFeature> dynamicFeatures = new LinkedList<DynamicFeature>();
     
+    // This may be better be kept at OperationResourceInfo ? Though we may have many methods
+    // across different resources that use the same BeanParam. 
+    private Map<Class<?>, BeanParamInfo> beanParams = new HashMap<Class<?>,
BeanParamInfo>();
+    
     // List of injected providers
     private Collection<ProviderInfo<?>> injectedProviders = 
         new LinkedList<ProviderInfo<?>>();
@@ -236,6 +242,14 @@ public final class ProviderFactory {
         return SHARED_FACTORY;
     }
     
+    public void addBeanParamInfo(BeanParamInfo bpi) {
+        beanParams.put(bpi.getResourceClass(), bpi);
+    }
+    
+    public BeanParamInfo getBeanParamInfo(Class<?> beanClass) {
+        return beanParams.get(beanClass);
+    }
+    
     public <T> ContextResolver<T> createContextResolver(Type contextType, 
                                                         Message m) {
         boolean isRequestor = MessageUtils.isRequestor(m);

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/AnnotationUtils.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/AnnotationUtils.java?rev=1414277&r1=1414276&r2=1414277&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/AnnotationUtils.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/AnnotationUtils.java
Tue Nov 27 17:32:57 2012
@@ -33,6 +33,7 @@ import javax.servlet.ServletConfig;
 import javax.servlet.ServletContext;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
+import javax.ws.rs.BeanParam;
 import javax.ws.rs.BindingPriority;
 import javax.ws.rs.Consumes;
 import javax.ws.rs.CookieParam;
@@ -113,6 +114,7 @@ public final class AnnotationUtils {
         classes.add(HeaderParam.class);
         classes.add(CookieParam.class);
         classes.add(FormParam.class);
+        classes.add(BeanParam.class);
         return classes;
     }
 

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java?rev=1414277&r1=1414276&r2=1414277&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java Tue
Nov 27 17:32:57 2012
@@ -90,6 +90,7 @@ import javax.ws.rs.ext.WriterInterceptor
 import javax.ws.rs.ext.WriterInterceptorContext;
 import javax.xml.namespace.QName;
 
+import org.apache.cxf.common.classloader.ClassLoaderUtils;
 import org.apache.cxf.common.i18n.BundleUtils;
 import org.apache.cxf.common.logging.LogUtils;
 import org.apache.cxf.common.util.PackageUtils;
@@ -117,6 +118,8 @@ import org.apache.cxf.jaxrs.impl.Securit
 import org.apache.cxf.jaxrs.impl.UriInfoImpl;
 import org.apache.cxf.jaxrs.impl.WriterInterceptorContextImpl;
 import org.apache.cxf.jaxrs.impl.WriterInterceptorMBW;
+import org.apache.cxf.jaxrs.model.BeanParamInfo;
+import org.apache.cxf.jaxrs.model.BeanResourceInfo;
 import org.apache.cxf.jaxrs.model.ClassResourceInfo;
 import org.apache.cxf.jaxrs.model.ClassResourceInfoComparator;
 import org.apache.cxf.jaxrs.model.OperationResourceInfo;
@@ -228,42 +231,60 @@ public final class JAXRSUtils {
         return supportedMimeTypes;
     }
     
+    public static void injectParameters(OperationResourceInfo ori,
+                                        Object requestObject,
+                                        Message message) {
+        injectParameters(ori, ori.getClassResourceInfo(), requestObject, message);    
+    }
+    
     @SuppressWarnings("unchecked")
     public static void injectParameters(OperationResourceInfo ori,
+                                        BeanResourceInfo bri,
                                         Object requestObject,
                                         Message message) {
-        ClassResourceInfo cri = ori.getClassResourceInfo();
                 
-        if (cri.isSingleton() 
-            && (!cri.getParameterMethods().isEmpty() || !cri.getParameterFields().isEmpty()))
{
+        if (bri.isSingleton() 
+            && (!bri.getParameterMethods().isEmpty() || !bri.getParameterFields().isEmpty()))
{
             LOG.fine("Injecting request parameters into singleton resource is not thread-safe");
         }
         // Param methods
         MultivaluedMap<String, String> values = 
             (MultivaluedMap<String, String>)message.get(URITemplate.TEMPLATE_PARAMETERS);
-        for (Method m : cri.getParameterMethods()) {
+        for (Method m : bri.getParameterMethods()) {
             Parameter p = ResourceUtils.getParameter(0, m.getAnnotations(), 
                                                      m.getParameterTypes()[0]);
-            Object o = createHttpParameterValue(p, 
+            Object o;
+            
+            if (p.getType() == ParameterType.BEAN && bri instanceof ClassResourceInfo)
{
+                o = createBeanParamValue(message, m.getParameterTypes()[0], ori);    
+            } else {
+                o = createHttpParameterValue(p, 
                                                 m.getParameterTypes()[0],
                                                 m.getGenericParameterTypes()[0],
                                                 m.getParameterAnnotations()[0],
                                                 message,
                                                 values,
                                                 ori);
+            }
             InjectionUtils.injectThroughMethod(requestObject, m, o);
         }
         // Param fields
-        for (Field f : cri.getParameterFields()) {
+        for (Field f : bri.getParameterFields()) {
             Parameter p = ResourceUtils.getParameter(0, f.getAnnotations(), 
                                                      f.getType());
-            Object o = createHttpParameterValue(p, 
+            Object o = null;
+            
+            if (p.getType() == ParameterType.BEAN && bri instanceof ClassResourceInfo)
{
+                o = createBeanParamValue(message, f.getType(), ori);    
+            } else {
+                o = createHttpParameterValue(p, 
                                                 f.getType(),
                                                 f.getGenericType(),
                                                 f.getAnnotations(),
                                                 message,
                                                 values,
                                                 ori);
+            }
             InjectionUtils.injectFieldValue(f, requestObject, o);
         }
         
@@ -668,6 +689,8 @@ public final class JAXRSUtils {
                                        message);
         } else if (parameter.getType() == ParameterType.CONTEXT) {
             return createContextValue(message, parameterType, parameterClass);
+        } else if (parameter.getType() == ParameterType.BEAN) {
+            return createBeanParamValue(message, parameterClass, ori);
         } else {
             
             return createHttpParameterValue(parameter,
@@ -870,6 +893,28 @@ public final class JAXRSUtils {
                                               ParameterType.COOKIE, m);
     }
     
+    public static Object createBeanParamValue(Message m, Class<?> clazz, OperationResourceInfo
ori) {
+        BeanParamInfo bmi = ProviderFactory.getInstance(m).getBeanParamInfo(clazz);
+        if (bmi == null) {
+            // we could've started introspecting now but the fact no bean info 
+            // is available indicates that the one created at start up has been 
+            // lost and hence it is 500
+            LOG.warning("Bean parameter info is not available");
+            throw new InternalServerErrorException();
+        }
+        Object instance;
+        try {
+            instance = ClassLoaderUtils.loadClass(clazz.getName(), JAXRSUtils.class).newInstance();
+        } catch (Throwable t) {
+            throw new InternalServerErrorException(t);
+        }
+        JAXRSUtils.injectParameters(ori, bmi, instance, m);
+        
+        InjectionUtils.injectContexts(instance, bmi, m);
+        
+        return instance;
+    }
+    
     public static <T> T createContextValue(Message m, Type genericType, Class<T>
clazz) {
  
         Message contextMessage = m.getExchange() != null ? m.getExchange().getInMessage()
: m;

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/ResourceUtils.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/ResourceUtils.java?rev=1414277&r1=1414276&r2=1414277&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/ResourceUtils.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/ResourceUtils.java
Tue Nov 27 17:32:57 2012
@@ -43,6 +43,7 @@ import java.util.logging.Logger;
 import javax.annotation.PostConstruct;
 import javax.annotation.PreDestroy;
 import javax.ws.rs.ApplicationPath;
+import javax.ws.rs.BeanParam;
 import javax.ws.rs.CookieParam;
 import javax.ws.rs.Encoded;
 import javax.ws.rs.FormParam;
@@ -305,6 +306,7 @@ public final class ResourceUtils {
         return params;
     }
     
+    //CHECKSTYLE:OFF
     public static Parameter getParameter(int index, Annotation[] anns, Class<?> type)
{
         
         Context ctx = AnnotationUtils.getAnnotation(anns, Context.class);
@@ -313,24 +315,22 @@ public final class ResourceUtils {
         }
         
         boolean isEncoded = AnnotationUtils.getAnnotation(anns, Encoded.class) != null;
-        String dValue = AnnotationUtils.getDefaultParameterValue(anns);
         
-        Parameter p = null;
+        BeanParam bp = AnnotationUtils.getAnnotation(anns, BeanParam.class);
+        if (bp != null) {
+            return new Parameter(ParameterType.BEAN, index, null, isEncoded, null);
+        }
+        
+        String dValue = AnnotationUtils.getDefaultParameterValue(anns);
         
         PathParam a = AnnotationUtils.getAnnotation(anns, PathParam.class); 
         if (a != null) {
-            p = new Parameter(ParameterType.PATH, index, a.value(), isEncoded, dValue);
+            return new Parameter(ParameterType.PATH, index, a.value(), isEncoded, dValue);
         } 
-        if (p == null) {
-            QueryParam q = AnnotationUtils.getAnnotation(anns, QueryParam.class);
-            if (q != null) {
-                p = new Parameter(ParameterType.QUERY, index, q.value(), isEncoded, dValue);
-            }
+        QueryParam q = AnnotationUtils.getAnnotation(anns, QueryParam.class);
+        if (q != null) {
+            return new Parameter(ParameterType.QUERY, index, q.value(), isEncoded, dValue);
         }
-        if (p != null) {
-            return p;
-        }
-        
         MatrixParam m = AnnotationUtils.getAnnotation(anns, MatrixParam.class);
         if (m != null) {
             return new Parameter(ParameterType.MATRIX, index, m.value(), isEncoded, dValue);
@@ -346,17 +346,15 @@ public final class ResourceUtils {
             return new Parameter(ParameterType.HEADER, index, h.value(), isEncoded, dValue);
         }  
         
-        p = null;
         CookieParam c = AnnotationUtils.getAnnotation(anns, CookieParam.class);
         if (c != null) {
-            p = new Parameter(ParameterType.COOKIE, index, c.value(), isEncoded, dValue);
-        } else {
-            p = new Parameter(ParameterType.REQUEST_BODY, index, null); 
+            return new Parameter(ParameterType.COOKIE, index, c.value(), isEncoded, dValue);
         }
         
-        return p;
+        return new Parameter(ParameterType.REQUEST_BODY, index, null); 
+        
     }
-    
+    //CHECKSTYLE:ON
     
     private static OperationResourceInfo createOperationInfo(Method m, Method annotatedMethod,

                                                       ClassResourceInfo cri, Path path, String
httpMethod) {

Modified: cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java?rev=1414277&r1=1414276&r2=1414277&view=diff
==============================================================================
--- cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java (original)
+++ cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java Tue
Nov 27 17:32:57 2012
@@ -38,6 +38,7 @@ import java.util.Map;
 import javax.annotation.PostConstruct;
 import javax.annotation.PreDestroy;
 import javax.servlet.http.HttpServletResponse;
+import javax.ws.rs.BeanParam;
 import javax.ws.rs.Consumes;
 import javax.ws.rs.DELETE;
 import javax.ws.rs.DefaultValue;
@@ -108,6 +109,9 @@ public class BookStore {
     @Context 
     private UriInfo ui;
     
+    @BeanParam
+    private BookBean theBookBean;
+    
     public BookStore() {
         init();
     }
@@ -123,6 +127,23 @@ public class BookStore {
     }
 
     @GET
+    @Path("/beanparam")
+    @Produces("application/xml")
+    public Book getBeanParamBook(@BeanParam BookBean bean) {
+        
+        long id = bean.getId() + bean.getId1(); 
+        
+        return books.get(id);
+    }
+    
+    @GET
+    @Path("/beanparam2")
+    @Produces("application/xml")
+    public Book getBeanParamBook2() {
+        return getBeanParamBook(theBookBean);
+    }
+    
+    @GET
     @Path("emptybook")
     @Produces({"application/xml", "application/json" })
     public Book getEmptyBook() {
@@ -1268,6 +1289,32 @@ public class BookStore {
                                     new Class[]{Book.class}, 
                                     handler);
     }
+    
+    public static class BookBean {
+        private long id;
+        private long id1;
+
+        public long getId() {
+            return id;
+        }
+
+        @QueryParam("id")
+        public void setId(long id) {
+            this.id = id;
+        }
+        
+        @Context
+        public void setUriInfo(UriInfo ui) {
+            String id1Value = ui.getQueryParameters().getFirst("id1");
+            if (id1Value != null) {
+                this.id1 = Long.valueOf(id1Value);
+            }
+        }
+
+        public long getId1() {
+            return id1;
+        }
+    }
 }
 
 

Modified: cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java?rev=1414277&r1=1414276&r2=1414277&view=diff
==============================================================================
--- cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java
(original)
+++ cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java
Tue Nov 27 17:32:57 2012
@@ -90,6 +90,28 @@ public class JAXRSClientServerBookTest e
     }
     
     @Test
+    public void testUseParamBeanWebClient() {
+        String address = "http://localhost:" + PORT + "/bookstore/beanparam";
+        doTestUseParamBeanWebClient(address);
+    }
+    
+    @Test
+    public void testUseParamBeanWebClient2() {
+        String address = "http://localhost:" + PORT + "/bookstore/beanparam2";
+        doTestUseParamBeanWebClient(address);
+    }
+    
+    private void doTestUseParamBeanWebClient(String address) {
+        WebClient wc = WebClient.create(address);
+        WebClient.getConfig(wc).getHttpConduit().getClient().setReceiveTimeout(1000000);
+        wc.query("id", "120");
+        wc.query("id1", "3");
+        Book book = wc.get(Book.class);
+        assertEquals(123L, book.getId());
+    }
+    
+    
+    @Test
     public void testGetIntroChapterFromSelectedBook() {
         String address = "http://localhost:" + PORT + "/bookstore/books(id=le=123)/chapter";
         doTestGetChapterFromSelectedBook(address);



Mime
View raw message