cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1515818 - in /cxf/branches/2.7.x-fixes: ./ rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/ systests/jaxrs/src/test...
Date Tue, 20 Aug 2013 13:15:46 GMT
Author: sergeyb
Date: Tue Aug 20 13:15:46 2013
New Revision: 1515818

URL: http://svn.apache.org/r1515818
Log:
Merged revisions 1515807 via svnmerge from 
https://svn.apache.org/repos/asf/cxf/trunk

........
  r1515807 | sergeyb | 2013-08-20 15:55:06 +0300 (Tue, 20 Aug 2013) | 1 line
  
  [CXF-5214] Better support for BeanParams
........

Modified:
    cxf/branches/2.7.x-fixes/   (props changed)
    cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/AbstractJAXRSFactoryBean.java
    cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSServerFactoryBean.java
    cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ResourceContextImpl.java
    cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/ClassResourceInfo.java
    cxf/branches/2.7.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/Book2.java
    cxf/branches/2.7.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java

Propchange: cxf/branches/2.7.x-fixes/
------------------------------------------------------------------------------
  Merged /cxf/trunk:r1515807

Propchange: cxf/branches/2.7.x-fixes/
------------------------------------------------------------------------------
Binary property 'svnmerge-integrated' - no diff available.

Modified: cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/AbstractJAXRSFactoryBean.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/AbstractJAXRSFactoryBean.java?rev=1515818&r1=1515817&r2=1515818&view=diff
==============================================================================
--- cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/AbstractJAXRSFactoryBean.java
(original)
+++ cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/AbstractJAXRSFactoryBean.java
Tue Aug 20 13:15:46 2013
@@ -27,7 +27,6 @@ import java.util.LinkedList;
 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;
@@ -47,11 +46,7 @@ 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;
@@ -344,17 +339,7 @@ public class AbstractJAXRSFactoryBean ex
     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);
-                    }
-                }
-            }
+            cri.initBeanParamInfo(factory);
         }
         
     }

Modified: cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSServerFactoryBean.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSServerFactoryBean.java?rev=1515818&r1=1515817&r2=1515818&view=diff
==============================================================================
--- cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSServerFactoryBean.java
(original)
+++ cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSServerFactoryBean.java
Tue Aug 20 13:15:46 2013
@@ -217,6 +217,15 @@ public class JAXRSServerFactoryBean exte
         return server;
     }
 
+
+    protected void setBeanInfo(ProviderFactory factory) {
+        List<ClassResourceInfo> cris = serviceFactory.getClassResourceInfo();
+        for (ClassResourceInfo cri : cris) {
+            cri.initBeanParamInfo(factory);
+        }
+        
+    }
+    
     protected void applyFeatures() {
         if (getFeatures() != null) {
             for (Feature feature : getFeatures()) {

Modified: cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ResourceContextImpl.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ResourceContextImpl.java?rev=1515818&r1=1515817&r2=1515818&view=diff
==============================================================================
--- cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ResourceContextImpl.java
(original)
+++ cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ResourceContextImpl.java
Tue Aug 20 13:15:46 2013
@@ -26,6 +26,9 @@ import javax.ws.rs.core.UriInfo;
 
 import org.apache.cxf.jaxrs.model.ClassResourceInfo;
 import org.apache.cxf.jaxrs.model.OperationResourceInfo;
+import org.apache.cxf.jaxrs.provider.ProviderFactory;
+import org.apache.cxf.message.Message;
+import org.apache.cxf.phase.PhaseInterceptorChain;
 
 public class ResourceContextImpl implements ResourceContext {
 
@@ -53,7 +56,11 @@ public class ResourceContextImpl impleme
     }
 
     private <T> T doInitResource(Class<?> cls, T resource) {
-        cri.getSubResource(subClass, cls, resource, true);
+        ClassResourceInfo sub = cri.getSubResource(subClass, cls, resource, true);
+        Message m = PhaseInterceptorChain.getCurrentMessage();
+        if (m != null) {
+            sub.initBeanParamInfo(ProviderFactory.getInstance(m));
+        } 
         return resource;
     }
 

Modified: cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/ClassResourceInfo.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/ClassResourceInfo.java?rev=1515818&r1=1515817&r2=1515818&view=diff
==============================================================================
--- cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/ClassResourceInfo.java
(original)
+++ cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/ClassResourceInfo.java
Tue Aug 20 13:15:46 2013
@@ -19,6 +19,8 @@
 
 package org.apache.cxf.jaxrs.model;
 
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.HashSet;
@@ -26,6 +28,7 @@ import java.util.List;
 import java.util.Set;
 import java.util.concurrent.ConcurrentHashMap;
 
+import javax.ws.rs.BeanParam;
 import javax.ws.rs.Consumes;
 import javax.ws.rs.Path;
 import javax.ws.rs.Produces;
@@ -34,6 +37,7 @@ import javax.ws.rs.core.MediaType;
 import org.apache.cxf.Bus;
 import org.apache.cxf.BusFactory;
 import org.apache.cxf.jaxrs.lifecycle.ResourceProvider;
+import org.apache.cxf.jaxrs.provider.ProviderFactory;
 import org.apache.cxf.jaxrs.utils.AnnotationUtils;
 import org.apache.cxf.jaxrs.utils.InjectionUtils;
 import org.apache.cxf.jaxrs.utils.JAXRSUtils;
@@ -279,4 +283,32 @@ public class ClassResourceInfo extends B
     public ClassResourceInfo getParent() {
         return parent;
     }
+    
+    public void initBeanParamInfo(ProviderFactory factory) {
+        Set<OperationResourceInfo> oris = 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);
+                }
+            }
+        }
+        List<Method> methods =  super.getParameterMethods();
+        for (Method m : methods) {
+            if (m.getAnnotation(BeanParam.class) != null) {
+                BeanParamInfo bpi = new BeanParamInfo(m.getParameterTypes()[0], getBus());
+                factory.addBeanParamInfo(bpi);
+            }
+        }
+        List<Field> fields = super.getParameterFields();
+        for (Field f : fields) {
+            if (f.getAnnotation(BeanParam.class) != null) {
+                BeanParamInfo bpi = new BeanParamInfo(f.getType(), getBus());
+                factory.addBeanParamInfo(bpi);
+            }
+        }
+    }
 }

Modified: cxf/branches/2.7.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/Book2.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.7.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/Book2.java?rev=1515818&r1=1515817&r2=1515818&view=diff
==============================================================================
--- cxf/branches/2.7.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/Book2.java
(original)
+++ cxf/branches/2.7.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/Book2.java
Tue Aug 20 13:15:46 2013
@@ -19,9 +19,11 @@
 
 package org.apache.cxf.systest.jaxrs;
 
+import javax.ws.rs.BeanParam;
 import javax.ws.rs.GET;
 import javax.ws.rs.Path;
 import javax.ws.rs.Produces;
+import javax.ws.rs.QueryParam;
 import javax.ws.rs.core.Context;
 import javax.ws.rs.core.MultivaluedMap;
 import javax.ws.rs.core.UriInfo;
@@ -46,6 +48,10 @@ public class Book2 {
     @XmlTransient
     private UriInfo uriInfo; 
     
+    @BeanParam
+    @XmlTransient
+    private QueryBean2 queryBean;
+    
     public Book2() {
     }
     
@@ -78,5 +84,50 @@ public class Book2 {
         name = params.getFirst("bookname");
         return this;
     }
+    
+    @GET
+    @Path("rc/bean")
+    @Produces("application/xml")
+    public Book2 initFromQueryBean(@BeanParam QueryBean bean) {
+        id = bean.getBookid();
+        name = bean.getBookname();
+        return this;
+    }
+    
+    @GET
+    @Path("rc/bean2")
+    @Produces("application/xml")
+    public Book2 initFromQueryBean2() {
+        id = queryBean.getBookid();
+        name = queryBean.getBookname();
+        return this;
+    }
 
+    public static class QueryBean {
+        private long id;
+        private String name;
+
+        public long getBookid() {
+            return id;
+        }
+
+        @QueryParam("bookid")
+        public void setBookid(long i) {
+            this.id = i;
+        }
+        
+        public String getBookname() {
+            return name;
+        }
+
+        @QueryParam("bookname")
+        public void setBookname(String bookname) {
+            this.name = bookname;
+        }
+        
+    }
+    
+    public static class QueryBean2 extends QueryBean {
+        
+    }
 }

Modified: cxf/branches/2.7.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.7.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java?rev=1515818&r1=1515817&r2=1515818&view=diff
==============================================================================
--- cxf/branches/2.7.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java
(original)
+++ cxf/branches/2.7.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java
Tue Aug 20 13:15:46 2013
@@ -1772,6 +1772,18 @@ public class JAXRSClientServerBookTest e
     }
     
     @Test
+    public void testGetBookWithResourceContextBeanParam() throws Exception {
+        String address = "http://localhost:" + PORT + "/bookstore/booksubresource/context/rc/bean";
+        doTestGetBookWithResourceContext(address);
+    }
+    
+    @Test
+    public void testGetBookWithResourceContextBeanParam2() throws Exception {
+        String address = "http://localhost:" + PORT + "/bookstore/booksubresource/context/rc/bean2";
+        doTestGetBookWithResourceContext(address);
+    }
+    
+    @Test
     public void testGetBookWithResourceContextInstance() throws Exception {
         String address = "http://localhost:" + PORT + "/bookstore/booksubresource/instance/context/rc";
         doTestGetBookWithResourceContext(address);



Mime
View raw message