cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r899614 - in /cxf/trunk/rt/frontend/jaxrs/src: main/java/org/apache/cxf/jaxrs/model/ test/java/org/apache/cxf/jaxrs/ test/java/org/apache/cxf/jaxrs/utils/
Date Fri, 15 Jan 2010 12:50:37 GMT
Author: sergeyb
Date: Fri Jan 15 12:50:37 2010
New Revision: 899614

URL: http://svn.apache.org/viewvc?rev=899614&view=rev
Log:
JAX-RS : minor changes to do with the injection of contexts

Modified:
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/AbstractResourceInfo.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/ClassResourceInfo.java
    cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/AbstractCustomer.java
    cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/CustomerInfo.java
    cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/JAXRSUtilsTest.java

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/AbstractResourceInfo.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/AbstractResourceInfo.java?rev=899614&r1=899613&r2=899614&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/AbstractResourceInfo.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/AbstractResourceInfo.java
Fri Jan 15 12:50:37 2010
@@ -56,9 +56,9 @@
         this.serviceClass = serviceClass;
         this.resourceClass = resourceClass;
         root = isRoot;
-        if (root) {
-            initContextFields();
-            initContextSetterMethods();
+        if (root && resourceClass != null) {
+            findContextFields(serviceClass);
+            findContextSetterMethods(serviceClass);
         }
     }
     
@@ -70,13 +70,6 @@
         return serviceClass;
     }
     
-    private void initContextFields() {
-        if (resourceClass == null || !root) {
-            return;
-        }
-        findContextFields(serviceClass);
-    }
-    
     private void findContextFields(Class<?> cls) {
         if (cls == Object.class || cls == null) {
             return;
@@ -108,9 +101,9 @@
         findContextFields(cls.getSuperclass());
     }
     
-    private void initContextSetterMethods() {
+    private void findContextSetterMethods(Class<?> cls) {
         
-        for (Method m : getServiceClass().getMethods()) {
+        for (Method m : cls.getMethods()) {
         
             if (!m.getName().startsWith("set") || m.getParameterTypes().length != 1) {
                 continue;
@@ -122,6 +115,10 @@
                 }
             }
         }
+        Class<?>[] interfaces = cls.getInterfaces();
+        for (Class<?> i : interfaces) {
+            findContextSetterMethods(i);
+        }
     }
     
     private void checkContextMethod(Method m) {

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=899614&r1=899613&r2=899614&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
Fri Jan 15 12:50:37 2010
@@ -93,20 +93,15 @@
                              boolean theRoot, boolean enableStatic) {
         super(theResourceClass, theServiceClass, theRoot);
         this.enableStatic = enableStatic;
-        if (theRoot) {
-            initParamFields();
-            initParamMethods();
+        if (root && resourceClass != null) {
+            setParamField(serviceClass);
+            setParamMethods(serviceClass);
         }
     }
     
     public ClassResourceInfo(Class<?> theResourceClass, Class<?> theServiceClass,

                              boolean theRoot, boolean enableStatic, boolean createdFromModel)
{
-        super(theResourceClass, theServiceClass, theRoot);
-        this.enableStatic = enableStatic;
-        if (theRoot) {
-            initParamFields();
-            initParamMethods();
-        }
+        this(theResourceClass, theServiceClass, theRoot, enableStatic);
         this.createdFromModel = createdFromModel;
     }
     
@@ -154,13 +149,11 @@
         return methods;
     }
     
-    private void initParamFields() {
-        if (getResourceClass() == null || !isRoot()) {
+    private void setParamField(Class<?> cls) {
+        if (Object.class == cls || cls == null) {
             return;
         }
-        
-        
-        for (Field f : getServiceClass().getDeclaredFields()) {
+        for (Field f : cls.getDeclaredFields()) {
             for (Annotation a : f.getAnnotations()) {
                 if (AnnotationUtils.isParamAnnotationClass(a.annotationType())) {
                     if (paramFields == null) {
@@ -170,11 +163,12 @@
                 }
             }
         }
+        setParamField(cls.getSuperclass());
     }
     
-    private void initParamMethods() {
+    private void setParamMethods(Class<?> cls) {
         
-        for (Method m : getServiceClass().getMethods()) {
+        for (Method m : cls.getMethods()) {
         
             if (!m.getName().startsWith("set") || m.getParameterTypes().length != 1) {
                 continue;
@@ -186,6 +180,10 @@
                 }
             }
         }
+        Class<?>[] interfaces = cls.getInterfaces();
+        for (Class<?> i : interfaces) {
+            setParamMethods(i);
+        }
     }
 
     public URITemplate getURITemplate() {

Modified: cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/AbstractCustomer.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/AbstractCustomer.java?rev=899614&r1=899613&r2=899614&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/AbstractCustomer.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/AbstractCustomer.java Fri
Jan 15 12:50:37 2010
@@ -19,14 +19,57 @@
 
 package org.apache.cxf.jaxrs;
 
+import javax.servlet.ServletConfig;
 import javax.servlet.ServletContext;
+import javax.servlet.http.HttpServletRequest;
+import javax.ws.rs.HeaderParam;
 import javax.ws.rs.core.Context;
 
 public class AbstractCustomer {
+    
+    @HeaderParam("AHeader")
+    private String aHeaderValue;
+    
+    private String aHeaderValue2;
+    
     @Context 
     private ServletContext sContext;
     
+    private ServletConfig sConfig;
+    private HttpServletRequest request;
+    
     public ServletContext getSuperServletContext() {
         return sContext;
     }
+    
+    @Context
+    public void setServletConfig(ServletConfig context) {
+        sConfig = context;
+    }
+    
+    public ServletConfig getSuperServletConfig() {
+        return sConfig;
+    }
+    
+    public String getAHeader() {
+        return aHeaderValue;
+    }
+    
+    @HeaderParam("AHeader2")
+    public void setAHeader2(String value) {
+        this.aHeaderValue2 = value;
+    }
+        
+    public String getAHeader2() {
+        return aHeaderValue2;
+    }
+    
+    public void setHttpServletRequest(HttpServletRequest r) {
+        request = r;    
+    }
+    
+    public HttpServletRequest getHttpServletRequest() {
+        return request;
+    }
+    
 };

Modified: cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/CustomerInfo.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/CustomerInfo.java?rev=899614&r1=899613&r2=899614&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/CustomerInfo.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/CustomerInfo.java Fri Jan
15 12:50:37 2010
@@ -19,6 +19,7 @@
 
 package org.apache.cxf.jaxrs;
 
+import javax.servlet.http.HttpServletRequest;
 import javax.ws.rs.core.Context;
 import javax.ws.rs.core.UriInfo;
 import javax.ws.rs.ext.ContextResolver;
@@ -26,4 +27,8 @@
 public interface CustomerInfo {
     void setUriInfoContext(@Context UriInfo uriInfo);
     ContextResolver getContextResolver();
+    
+    @Context 
+    void setHttpServletRequest(HttpServletRequest request);
+    
 }

Modified: cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/JAXRSUtilsTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/JAXRSUtilsTest.java?rev=899614&r1=899613&r2=899614&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/JAXRSUtilsTest.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/JAXRSUtilsTest.java
Fri Jan 15 12:50:37 2010
@@ -61,7 +61,9 @@
 import org.apache.cxf.jaxrs.impl.RequestImpl;
 import org.apache.cxf.jaxrs.impl.SecurityContextImpl;
 import org.apache.cxf.jaxrs.impl.UriInfoImpl;
+import org.apache.cxf.jaxrs.impl.tl.ThreadLocalHttpServletRequest;
 import org.apache.cxf.jaxrs.impl.tl.ThreadLocalProxy;
+import org.apache.cxf.jaxrs.impl.tl.ThreadLocalServletConfig;
 import org.apache.cxf.jaxrs.impl.tl.ThreadLocalUriInfo;
 import org.apache.cxf.jaxrs.lifecycle.PerRequestResourceProvider;
 import org.apache.cxf.jaxrs.lifecycle.SingletonResourceProvider;
@@ -1212,13 +1214,14 @@
         
         OperationResourceInfo ori = new OperationResourceInfo(Customer.class.getMethods()[0],
                                                               cri); 
-        
-        
-        JAXRSUtils.handleSetters(ori, c, new MessageImpl());
+        Message message = new MessageImpl();
+        JAXRSUtils.handleSetters(ori, c, message);
         assertNotNull(c.getUriInfo());
         assertSame(ThreadLocalUriInfo.class, c.getUriInfo().getClass());
         assertSame(UriInfoImpl.class, 
                    ((ThreadLocalProxy)c.getUriInfo()).get().getClass());
+        assertSame(ThreadLocalServletConfig.class, c.getSuperServletConfig().getClass());
+        assertSame(ThreadLocalHttpServletRequest.class, c.getHttpServletRequest().getClass());
     }
     
     @Test
@@ -1229,10 +1232,13 @@
         OperationResourceInfo ori = new OperationResourceInfo(Customer.class.getMethods()[0],
                                                               cri);
         Message m = new MessageImpl();
+        MultivaluedMap<String, String> headers = new MetadataMap<String, String>();
+        headers.add("AHeader2", "theAHeader2");
+        m.put(Message.PROTOCOL_HEADERS, headers);
         m.put(Message.QUERY_STRING, "a=aValue&query2=b");
         JAXRSUtils.handleSetters(ori, c, m);
         assertEquals("aValue", c.getQueryParam());
-        
+        assertEquals("theAHeader2", c.getAHeader2());
     }
     
     @Test
@@ -1243,10 +1249,13 @@
         OperationResourceInfo ori = new OperationResourceInfo(Customer.class.getMethods()[0],
                                                               cri);
         Message m = new MessageImpl();
+        MultivaluedMap<String, String> headers = new MetadataMap<String, String>();
+        headers.add("AHeader", "theAHeader");
+        m.put(Message.PROTOCOL_HEADERS, headers);
         m.put(Message.QUERY_STRING, "b=bValue");
         JAXRSUtils.handleSetters(ori, c, m);
         assertEquals("bValue", c.getB());
-        
+        assertEquals("theAHeader", c.getAHeader());
     }
 
     @Test



Mime
View raw message