cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1354452 - in /cxf/branches/2.4.x-fixes: ./ rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/ rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/
Date Wed, 27 Jun 2012 11:58:33 GMT
Author: sergeyb
Date: Wed Jun 27 11:58:32 2012
New Revision: 1354452

URL: http://svn.apache.org/viewvc?rev=1354452&view=rev
Log:
Merged revisions 1354451 via svnmerge from 
https://svn.apache.org/repos/asf/cxf/branches/2.5.x-fixes

................
  r1354451 | sergeyb | 2012-06-27 12:55:57 +0100 (Wed, 27 Jun 2012) | 24 lines
  
  Merged revisions 1354447 via svnmerge from 
  https://svn.apache.org/repos/asf/cxf/branches/2.6.x-fixes
  
  ................
    r1354447 | sergeyb | 2012-06-27 12:51:30 +0100 (Wed, 27 Jun 2012) | 17 lines
    
    Merged revisions 1354441-1354442,1354446 via svnmerge from 
    https://svn.apache.org/repos/asf/cxf/trunk
    
    ........
      r1354441 | sergeyb | 2012-06-27 12:44:38 +0100 (Wed, 27 Jun 2012) | 1 line
      
      [CXF-4396] Checking a port when 0.0.0.0 address gets replaced
    ........
      r1354442 | sergeyb | 2012-06-27 12:45:33 +0100 (Wed, 27 Jun 2012) | 1 line
      
      [CXF-4379] Passing corect type for adapters bound to interfaces to be discoverd
    ........
      r1354446 | sergeyb | 2012-06-27 12:49:57 +0100 (Wed, 27 Jun 2012) | 1 line
      
      [CXF-4379] Minor optimization
    ........
  ................
................

Modified:
    cxf/branches/2.4.x-fixes/   (props changed)
    cxf/branches/2.4.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/HttpUtils.java
    cxf/branches/2.4.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java
    cxf/branches/2.4.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXBUtils.java
    cxf/branches/2.4.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/HttpUtilsTest.java
    cxf/branches/2.4.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/InjectionUtilsTest.java

Propchange: cxf/branches/2.4.x-fixes/
------------------------------------------------------------------------------
  Merged /cxf/branches/2.5.x-fixes:r1354451
  Merged /cxf/trunk:r1354441-1354446
  Merged /cxf/branches/2.6.x-fixes:r1354447

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

Modified: cxf/branches/2.4.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/HttpUtils.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.4.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/HttpUtils.java?rev=1354452&r1=1354451&r2=1354452&view=diff
==============================================================================
--- cxf/branches/2.4.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/HttpUtils.java
(original)
+++ cxf/branches/2.4.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/HttpUtils.java
Wed Jun 27 11:58:32 2012
@@ -200,7 +200,10 @@ public final class HttpUtils {
             if (!absolute) {
                 u = URI.create(base + u.toString());
             } else {
-                u = URI.create(u.toString().replace(ANY_IP_ADDRESS, serverAndPort));
+                int originalPort = u.getPort();
+                String replaceValue = originalPort == -1 ? ANY_IP_ADDRESS
+                    : ANY_IP_ADDRESS + ":" + originalPort;
+                u = URI.create(u.toString().replace(replaceValue, serverAndPort));
             }
         }
         return u;

Modified: cxf/branches/2.4.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.4.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java?rev=1354452&r1=1354451&r2=1354452&view=diff
==============================================================================
--- cxf/branches/2.4.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java
(original)
+++ cxf/branches/2.4.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java
Wed Jun 27 11:58:32 2012
@@ -366,10 +366,11 @@ public final class InjectionUtils {
             result = createFromParameterHandler(value, pClass, 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.convertWithAdapter(valueToReplace, pClass, paramAnns);
             } catch (Throwable ex) {
                 result = null; 
             }

Modified: cxf/branches/2.4.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXBUtils.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.4.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXBUtils.java?rev=1354452&r1=1354451&r2=1354452&view=diff
==============================================================================
--- cxf/branches/2.4.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXBUtils.java
(original)
+++ cxf/branches/2.4.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXBUtils.java
Wed Jun 27 11:58:32 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/branches/2.4.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/HttpUtilsTest.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.4.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/HttpUtilsTest.java?rev=1354452&r1=1354451&r2=1354452&view=diff
==============================================================================
--- cxf/branches/2.4.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/HttpUtilsTest.java
(original)
+++ cxf/branches/2.4.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/HttpUtilsTest.java
Wed Jun 27 11:58:32 2012
@@ -178,6 +178,29 @@ public class HttpUtilsTest extends Asser
         assertEquals("http://localhost:8080/bar/foo", u.toString());
     }
     
+    @Test
+    public void testReplaceAnyIPAddressWithPort() {
+        Message m = new MessageImpl();
+        HttpServletRequest req = EasyMock.createMock(HttpServletRequest.class);
+        m.put(AbstractHTTPDestination.HTTP_REQUEST, req);
+        req.getScheme();
+        EasyMock.expectLastCall().andReturn("http");
+        req.getServerName();
+        EasyMock.expectLastCall().andReturn("localhost");
+        req.getLocalPort();
+        EasyMock.expectLastCall().andReturn(8080);
+        EasyMock.replay(req);
+        URI u = HttpUtils.toAbsoluteUri(URI.create("http://0.0.0.0:8080/bar/foo"), m);
+        assertEquals("http://localhost:8080/bar/foo", u.toString());
+    }
+    
+    @Test
+    public void testReplaceLocalHostWithPort() {
+        Message m = new MessageImpl();
+        URI u = HttpUtils.toAbsoluteUri(URI.create("http://localhost:8080/bar/foo"), m);
+        assertEquals("http://localhost:8080/bar/foo", u.toString());
+    }
+    
     private void doTestGetBaseAddress(String baseURI, String expected) {
         Message m = new MessageImpl();
         Exchange exchange = new ExchangeImpl();

Modified: cxf/branches/2.4.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/InjectionUtilsTest.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.4.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/InjectionUtilsTest.java?rev=1354452&r1=1354451&r2=1354452&view=diff
==============================================================================
--- cxf/branches/2.4.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/InjectionUtilsTest.java
(original)
+++ cxf/branches/2.4.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/InjectionUtilsTest.java
Wed Jun 27 11:58:32 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