I just committed a quick fix for it.
Sergey, if you have time, please double check it.


On Wed Jul  4 08:44:12 2012, Freeman Fang wrote:
Hi Sergey,

This commit break some jaxrs tests in 2.5.x branch, they're

org.apache.cxf.jaxrs.utils.InjectionUtilsTest.testHandleParameterWithXmlAdapterOnInterface


org.apache.cxf.jaxrs.ext.codegen.CodeGeneratorProviderTest.testBookStoreAsInterface


org.apache.cxf.jaxrs.ext.codegen.CodeGeneratorProviderTest.testBookStoreAsClass


org.apache.cxf.jaxrs.ext.codegen.CodeGeneratorProviderTest.testBookStoreTypesOnly


Those test failed since Project CXF-2.5.x #337[1] on CI and afterwards.

The reason for CodeGeneratorProviderTest failure is because there's
another extra "Books.class" in addition to the classes listed, as
CodeGeneratorProviderTest get removed from trunk and 2.6.x branches,
so I'm not sure CodeGeneratorProviderTest is still valid based on
current jaxrs code.

The InjectionUtilsTest failed because the code
Object id = InjectionUtils.handleParameter(value,
                                                   true,
                                                   Id.class,
                                                   new Annotation[] {},
                                                   ParameterType.PATH,
                                                   createMessage());

now return id as a String.class, but not the expected Id.class.

Could you please take a look?


[1]https://builds.apache.org/job/CXF-2.5.x/337/#showFailuresLink

Thanks
Freeman

On 2012-6-27, at 下午7:58, serg...@apache.org wrote:

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;
+        }
+
+    }
}



---------------------------------------------
Freeman Fang

FuseSource
Email:ff...@fusesource.com
Web: fusesource.com
Twitter: freemanfang
Blog: http://freemanfang.blogspot.com
http://blog.sina.com.cn/u/1473905042
weibo: http://weibo.com/u/1473905042














--
Willem
----------------------------------
FuseSource
Web: http://www.fusesource.com
Blog:    http://willemjiang.blogspot.com (English)
        http://jnn.javaeye.com (Chinese)
Twitter: willemjiang
Weibo: willemjiang

Reply via email to