cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1515807 - in /cxf/trunk: 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/java/org/apache/c...
Date Tue, 20 Aug 2013 12:55:06 GMT
Author: sergeyb
Date: Tue Aug 20 12:55:06 2013
New Revision: 1515807

URL: http://svn.apache.org/r1515807
Log:
[CXF-5214] Better support for BeanParams

Modified:
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSServerFactoryBean.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ResourceContextImpl.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/ClassResourceInfo.java
    cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/Book2.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/JAXRSServerFactoryBean.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSServerFactoryBean.java?rev=1515807&r1=1515806&r2=1515807&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSServerFactoryBean.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSServerFactoryBean.java
Tue Aug 20 12:55:06 2013
@@ -43,11 +43,7 @@ import org.apache.cxf.jaxrs.ext.Resource
 import org.apache.cxf.jaxrs.impl.RequestPreprocessor;
 import org.apache.cxf.jaxrs.lifecycle.PerRequestResourceProvider;
 import org.apache.cxf.jaxrs.lifecycle.ResourceProvider;
-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.ProviderInfo;
 import org.apache.cxf.jaxrs.provider.ServerProviderFactory;
 import org.apache.cxf.jaxrs.utils.AnnotationUtils;
@@ -232,17 +228,7 @@ public class JAXRSServerFactoryBean exte
     protected void setBeanInfo(ServerProviderFactory 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/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ResourceContextImpl.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ResourceContextImpl.java?rev=1515807&r1=1515806&r2=1515807&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ResourceContextImpl.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ResourceContextImpl.java
Tue Aug 20 12:55:06 2013
@@ -23,6 +23,7 @@ import javax.ws.rs.container.ResourceCon
 import org.apache.cxf.jaxrs.lifecycle.PerRequestResourceProvider;
 import org.apache.cxf.jaxrs.model.ClassResourceInfo;
 import org.apache.cxf.jaxrs.model.OperationResourceInfo;
+import org.apache.cxf.jaxrs.provider.ServerProviderFactory;
 import org.apache.cxf.message.Message;
 
 public class ResourceContextImpl implements ResourceContext {
@@ -47,7 +48,8 @@ public class ResourceContextImpl impleme
     }
 
     private <T> T doInitResource(Class<?> cls, T resource) {
-        cri.getSubResource(subClass, cls, resource, true, m);
+        ClassResourceInfo sub = cri.getSubResource(subClass, cls, resource, true, m);
+        sub.initBeanParamInfo(ServerProviderFactory.getInstance(m));
         return resource;
     }
 }

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=1515807&r1=1515806&r2=1515807&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 Aug 20 12:55:06 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;
@@ -35,6 +38,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.ServerProviderFactory;
 import org.apache.cxf.jaxrs.utils.AnnotationUtils;
 import org.apache.cxf.jaxrs.utils.InjectionUtils;
 import org.apache.cxf.jaxrs.utils.JAXRSUtils;
@@ -290,4 +294,32 @@ public class ClassResourceInfo extends B
     public ClassResourceInfo getParent() {
         return parent;
     }
+    
+    public void initBeanParamInfo(ServerProviderFactory 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/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/Book2.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/Book2.java?rev=1515807&r1=1515806&r2=1515807&view=diff
==============================================================================
--- cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/Book2.java (original)
+++ cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/Book2.java Tue Aug
20 12:55:06 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/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=1515807&r1=1515806&r2=1515807&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
Aug 20 12:55:06 2013
@@ -92,7 +92,6 @@ import org.apache.cxf.jaxrs.ext.search.S
 import org.apache.cxf.jaxrs.ext.search.SearchContext;
 import org.apache.cxf.jaxrs.ext.xml.XMLInstruction;
 import org.apache.cxf.jaxrs.ext.xml.XSISchemaLocation;
-import org.apache.cxf.jaxrs.impl.ResourceContextImpl;
 import org.apache.cxf.jaxrs.utils.InjectionUtils;
 import org.apache.cxf.phase.PhaseInterceptorChain;
 import org.apache.cxf.systest.jaxrs.BookServer20.CustomHeaderAdded;
@@ -1046,8 +1045,7 @@ public class BookStore {
     
     @Path("/booksubresource/instance/context")
     public Book2 getBookSubResourceInstanceRC(@Context ResourceContext rc) {
-        // This cast is temporarily
-        return ((ResourceContextImpl)rc).initResource(book2Sub);
+        return rc.initResource(book2Sub);
     }
     
     @Path("/booksubresourceobject/{bookId}/")

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=1515807&r1=1515806&r2=1515807&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 Aug 20 12:55:06 2013
@@ -1775,6 +1775,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