cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1354442 - in /cxf/trunk/rt/frontend/jaxrs/src: main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java main/java/org/apache/cxf/jaxrs/utils/JAXBUtils.java test/java/org/apache/cxf/jaxrs/utils/InjectionUtilsTest.java
Date Wed, 27 Jun 2012 11:45:34 GMT
Author: sergeyb
Date: Wed Jun 27 11:45:33 2012
New Revision: 1354442

URL: http://svn.apache.org/viewvc?rev=1354442&view=rev
Log:
[CXF-4379] Passing corect type for adapters bound to interfaces to be discoverd

Modified:
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXBUtils.java
    cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/InjectionUtilsTest.java

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java?rev=1354442&r1=1354441&r2=1354442&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java
Wed Jun 27 11:45:33 2012
@@ -367,10 +367,14 @@ public final class InjectionUtils {
             result = createFromParameterHandler(value, cls, message);
         }
         
-        if (result != null && adapterHasToBeUsed) {
+        if (adapterHasToBeUsed) {
             // as the last resort, try XmlJavaTypeAdapters
+            Object valueToReplace = result != null ? result : value;
             try {
-                result = JAXBUtils.convertWithAdapter(result, paramAnns);
+                result = JAXBUtils.useAdapter(valueToReplace, 
+                                              JAXBUtils.getAdapter(pClass, paramAnns),
+                                              false, 
+                                              result);
             } catch (Throwable ex) {
                 result = null; 
             }

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXBUtils.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXBUtils.java?rev=1354442&r1=1354441&r2=1354442&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXBUtils.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXBUtils.java Wed
Jun 27 11:45:33 2012
@@ -29,10 +29,11 @@ public final class JAXBUtils {
         
     }
     
-    public static Object convertWithAdapter(Object obj, 
+    public static Object convertWithAdapter(Object obj,
+                                            Class<?> adapterClass,
                                             Annotation[] anns) {
         return useAdapter(obj, 
-                          getAdapter(obj.getClass(), anns),
+                          getAdapter(adapterClass, anns),
                           false, 
                           obj);
     }

Modified: cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/InjectionUtilsTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/InjectionUtilsTest.java?rev=1354442&r1=1354441&r2=1354442&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/InjectionUtilsTest.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/InjectionUtilsTest.java
Wed Jun 27 11:45:33 2012
@@ -18,6 +18,7 @@
  */
 package org.apache.cxf.jaxrs.utils;
 
+import java.lang.annotation.Annotation;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.HashSet;
@@ -27,13 +28,44 @@ import java.util.Set;
 import java.util.SortedSet;
 import java.util.TreeSet;
 
+import javax.ws.rs.core.Application;
 import javax.ws.rs.core.MultivaluedMap;
+import javax.xml.bind.annotation.adapters.XmlAdapter;
+import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
+
+import org.apache.cxf.endpoint.Endpoint;
+import org.apache.cxf.jaxrs.model.ParameterType;
+import org.apache.cxf.jaxrs.provider.ProviderFactory;
+import org.apache.cxf.message.Exchange;
+import org.apache.cxf.message.ExchangeImpl;
+import org.apache.cxf.message.Message;
+import org.apache.cxf.message.MessageImpl;
+import org.easymock.EasyMock;
 
 import org.junit.Assert;
 import org.junit.Test;
 
 public class InjectionUtilsTest extends Assert {
     
+    
+    @Test
+    public void testHandleParameterWithXmlAdapterOnInterface() throws Exception {
+        // Arrange
+        String value = "1.1";
+
+        // Act
+        Object id = InjectionUtils.handleParameter(value, 
+                                                   true, 
+                                                   Id.class, 
+                                                   new Annotation[] {}, 
+                                                   ParameterType.PATH,  
+                                                   createMessage());
+
+        // Assert
+        assertTrue(id instanceof Id);
+        assertEquals(value, ((Id)id).getId());
+    }
+    
     public void testCollectionTypeFromArray() {
         assertNull(InjectionUtils.getCollectionType(String[].class));
     }
@@ -179,4 +211,62 @@ public class InjectionUtilsTest extends 
         }
     }
     
+    private Message createMessage() {
+        ProviderFactory factory = ProviderFactory.getInstance();
+        Message m = new MessageImpl();
+        m.put("org.apache.cxf.http.case_insensitive_queries", false);
+        Exchange e = new ExchangeImpl();
+        m.setExchange(e);
+        e.setInMessage(m);
+        Endpoint endpoint = EasyMock.createMock(Endpoint.class);
+        endpoint.getEndpointInfo();
+        EasyMock.expectLastCall().andReturn(null).anyTimes();
+        endpoint.get(Application.class.getName());
+        EasyMock.expectLastCall().andReturn(null);
+        endpoint.size();
+        EasyMock.expectLastCall().andReturn(0).anyTimes();
+        endpoint.isEmpty();
+        EasyMock.expectLastCall().andReturn(true).anyTimes();
+        endpoint.get(ProviderFactory.class.getName());
+        EasyMock.expectLastCall().andReturn(factory).anyTimes();
+        EasyMock.replay(endpoint);
+        e.put(Endpoint.class, endpoint);
+        return m;
+    }
+    
+    public static class Adapter extends XmlAdapter<String, Id> {
+
+        @Override
+        public String marshal(final Id id) throws Exception {
+            return id.getId();
+        }
+
+        @Override
+        public Id unmarshal(final String idStr) throws Exception {
+            Id id = new DelegatingId();
+            id.setId(idStr);
+            return id;
+        }
+    }
+    
+    @XmlJavaTypeAdapter(Adapter.class)
+    public interface Id {
+        String getId();
+
+        void setId(String id);
+    }
+    
+    public static class DelegatingId implements Id {
+    
+        private String id;
+
+        public String getId() {
+            return this.id;
+        }
+    
+        public void setId(String id) {
+            this.id = id;
+        }
+    
+    }
 }



Mime
View raw message