cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j...@apache.org
Subject svn commit: r599368 - in /incubator/cxf/trunk: rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/ systests/src/test/java/org/apache/cxf/systest/jaxrs/
Date Thu, 29 Nov 2007 10:35:05 GMT
Author: jliu
Date: Thu Nov 29 02:35:04 2007
New Revision: 599368

URL: http://svn.apache.org/viewvc?rev=599368&view=rev
Log:
CXF-1240. Support parsing java primitive types from URL.

Modified:
    incubator/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSDispatchInterceptor.java
    incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java
    incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java

Modified: incubator/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSDispatchInterceptor.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSDispatchInterceptor.java?rev=599368&r1=599367&r2=599368&view=diff
==============================================================================
--- incubator/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSDispatchInterceptor.java
(original)
+++ incubator/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSDispatchInterceptor.java
Thu Nov 29 02:35:04 2007
@@ -37,6 +37,7 @@
 import javax.ws.rs.ext.EntityProvider;
 import javax.ws.rs.ext.ProviderFactory;
 
+import org.apache.cxf.common.util.PrimitiveUtils;
 import org.apache.cxf.jaxrs.JAXRSServiceImpl;
 import org.apache.cxf.jaxrs.model.ClassResourceInfo;
 import org.apache.cxf.jaxrs.model.OperationResourceInfo;
@@ -200,7 +201,7 @@
         return result;
     }
 
-    private String readFromUriParam(UriParam uriParamAnnotation,
+    private Object readFromUriParam(UriParam uriParamAnnotation,
                                     Class<?> parameter,
                                     Type parameterType,
                                     Annotation[] parameterAnnotations,
@@ -212,8 +213,11 @@
             return null;
         }
 
-        String result = values.get(parameterName);
-
+        Object result = values.get(parameterName);
+        
+        if (parameter.isPrimitive()) {
+            result = PrimitiveUtils.read((String)result, parameter);
+        }
         return result;
     }
 }

Modified: incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java?rev=599368&r1=599367&r2=599368&view=diff
==============================================================================
--- incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java
(original)
+++ incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java
Thu Nov 29 02:35:04 2007
@@ -67,6 +67,20 @@
             throw new BookNotFoundFault(details);
         }
     }
+    
+    @HttpMethod("GET")
+    @UriTemplate("/booknames/{bookId}/")
+    public Book getBookName(@UriParam("bookId") int id) throws BookNotFoundFault {
+        System.out.println("----invoking getBookName with id: " + id);
+        Book book = books.get(new Long(id));
+        if (book != null) {
+            return book;
+        } else {
+            BookNotFoundDetails details = new BookNotFoundDetails();
+            details.setId(id);
+            throw new BookNotFoundFault(details);
+        }
+    }
 
     @HttpMethod("POST")
     @UriTemplate("/books")

Modified: incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java?rev=599368&r1=599367&r2=599368&view=diff
==============================================================================
--- incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java
(original)
+++ incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java
Thu Nov 29 02:35:04 2007
@@ -57,6 +57,20 @@
     }
     
     @Test
+    public void testGetBook123Int() throws Exception {
+        String endpointAddress =
+            "http://localhost:9080/bookstore/booknames/123"; 
+        URL url = new URL(endpointAddress);
+        InputStream in = url.openStream();
+        assertNotNull(in);           
+
+        InputStream expected = getClass()
+            .getResourceAsStream("resources/expected_get_book123.txt");
+
+        assertEquals(getStringFromInputStream(expected), getStringFromInputStream(in)); 
+    }
+    
+    @Test
     public void testGetBookNotFound() throws Exception {
         String endpointAddress =
             "http://localhost:9080/bookstore/books/126"; 



Mime
View raw message