cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1059972 - in /cxf/branches/2.3.x-fixes: ./ rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/ systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/
Date Mon, 17 Jan 2011 16:19:21 GMT
Author: sergeyb
Date: Mon Jan 17 16:19:21 2011
New Revision: 1059972

URL: http://svn.apache.org/viewvc?rev=1059972&view=rev
Log:
Merged revisions 1059968 via svnmerge from 
https://svn.apache.org/repos/asf/cxf/trunk

........
  r1059968 | sergeyb | 2011-01-17 16:09:54 +0000 (Mon, 17 Jan 2011) | 1 line
  
  [CXF-3248] Application.getClasses() may also return provider classes
........

Modified:
    cxf/branches/2.3.x-fixes/   (props changed)
    cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/ResourceUtils.java
    cxf/branches/2.3.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookApplication.java
    cxf/branches/2.3.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookExceptionMapper.java
    cxf/branches/2.3.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerNonSpringBookTest.java
    cxf/branches/2.3.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/RuntimeExceptionMapper.java

Propchange: cxf/branches/2.3.x-fixes/
------------------------------------------------------------------------------
    svn:mergeinfo = /cxf/trunk:1059968

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

Modified: cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/ResourceUtils.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/ResourceUtils.java?rev=1059972&r1=1059971&r2=1059972&view=diff
==============================================================================
--- cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/ResourceUtils.java
(original)
+++ cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/ResourceUtils.java
Mon Jan 17 16:19:21 2011
@@ -550,12 +550,20 @@ public final class ResourceUtils {
         List<Object> providers = new ArrayList<Object>();
         Map<Class, ResourceProvider> map = new HashMap<Class, ResourceProvider>();
         
-        // at the moment we don't support per-request providers, only resource classes
         // Note, app.getClasse() returns a list of per-resource classes
+        // or singleton provider classes
         for (Class<?> c : app.getClasses()) {
-            if (isValidPerRequestResourceClass(c, singletons)) {
-                resourceClasses.add(c);
-                map.put(c, new PerRequestResourceProvider(c));
+            if (isValidApplicationClass(c, singletons)) {
+                if (c.getAnnotation(Provider.class) != null) {
+                    try {
+                        providers.add(c.newInstance());
+                    } catch (Throwable ex) {
+                        throw new RuntimeException("Provider " + c.getName() + " can not
be created", ex); 
+                    }
+                } else {
+                    resourceClasses.add(c);
+                    map.put(c, new PerRequestResourceProvider(c));
+                }
             }
         }
         
@@ -611,7 +619,7 @@ public final class ResourceUtils {
         return true;
     }
     
-    private static boolean isValidPerRequestResourceClass(Class<?> c, Set<Object>
singletons) {
+    private static boolean isValidApplicationClass(Class<?> c, Set<Object> singletons)
{
         if (!isValidResourceClass(c)) {
             return false;
         }

Modified: cxf/branches/2.3.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookApplication.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.3.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookApplication.java?rev=1059972&r1=1059971&r2=1059972&view=diff
==============================================================================
--- cxf/branches/2.3.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookApplication.java
(original)
+++ cxf/branches/2.3.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookApplication.java
Mon Jan 17 16:19:21 2011
@@ -32,6 +32,7 @@ public class BookApplication extends App
         Set<Class<?>> classes = new HashSet<Class<?>>();
         classes.add(org.apache.cxf.systest.jaxrs.BookStorePerRequest.class);
         classes.add(org.apache.cxf.systest.jaxrs.jaxws.BookStoreJaxrsJaxws.class);
+        classes.add(org.apache.cxf.systest.jaxrs.RuntimeExceptionMapper.class);
         return classes;
     }
 
@@ -39,6 +40,9 @@ public class BookApplication extends App
     public Set<Object> getSingletons() {
         Set<Object> classes = new HashSet<Object>();
         classes.add(new org.apache.cxf.systest.jaxrs.BookStore());
+        BookExceptionMapper mapper = new org.apache.cxf.systest.jaxrs.BookExceptionMapper();
+        mapper.setToHandle(true);
+        classes.add(mapper);
         return classes;
     }
     

Modified: cxf/branches/2.3.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookExceptionMapper.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.3.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookExceptionMapper.java?rev=1059972&r1=1059971&r2=1059972&view=diff
==============================================================================
--- cxf/branches/2.3.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookExceptionMapper.java
(original)
+++ cxf/branches/2.3.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookExceptionMapper.java
Mon Jan 17 16:19:21 2011
@@ -21,7 +21,9 @@ package org.apache.cxf.systest.jaxrs;
 import javax.ws.rs.core.MediaType;
 import javax.ws.rs.core.Response;
 import javax.ws.rs.ext.ExceptionMapper;
+import javax.ws.rs.ext.Provider;
 
+@Provider
 public class BookExceptionMapper implements ExceptionMapper<BookNotFoundFault> {
 
     private boolean toHandle;

Modified: cxf/branches/2.3.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerNonSpringBookTest.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.3.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerNonSpringBookTest.java?rev=1059972&r1=1059971&r2=1059972&view=diff
==============================================================================
--- cxf/branches/2.3.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerNonSpringBookTest.java
(original)
+++ cxf/branches/2.3.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerNonSpringBookTest.java
Mon Jan 17 16:19:21 2011
@@ -30,6 +30,7 @@ import org.apache.cxf.helpers.IOUtils;
 import org.apache.cxf.io.CachedOutputStream;
 import org.apache.cxf.jaxrs.client.JAXRSClientFactory;
 import org.apache.cxf.jaxrs.client.JAXRSClientFactoryBean;
+import org.apache.cxf.jaxrs.client.ServerWebApplicationException;
 import org.apache.cxf.jaxrs.client.WebClient;
 import org.apache.cxf.testutil.common.AbstractBusClientServerTestBase;
 
@@ -146,6 +147,32 @@ public class JAXRSClientServerNonSpringB
         
     }
     
+    @Test
+    public void testGetNonExistentBook() throws Exception {
+        WebClient wc = WebClient.create("http://localhost:" + PORT 
+                                        + "/application11/thebooks/bookstore/books/321");
+        try {
+            wc.accept("*/*").get(Book.class);
+            fail();
+        } catch (ServerWebApplicationException ex) {
+            assertEquals("No book found at all : 321", ex.getMessage());
+        }
+        
+    }
+    
+    @Test
+    public void testBookWithNonExistentMethod() throws Exception {
+        WebClient wc = WebClient.create("http://localhost:" + PORT
+                                        + "/application11/thebooks/bookstore/nonexistent");
+        try {
+            wc.accept("*/*").get(Book.class);
+            fail();
+        } catch (ServerWebApplicationException ex) {
+            assertEquals("Nonexistent method", ex.getMessage());
+        }
+        
+    }
+    
     private void getAndCompareAsStrings(String address, 
                                         String resourcePath,
                                         String acceptType,

Modified: cxf/branches/2.3.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/RuntimeExceptionMapper.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.3.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/RuntimeExceptionMapper.java?rev=1059972&r1=1059971&r2=1059972&view=diff
==============================================================================
--- cxf/branches/2.3.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/RuntimeExceptionMapper.java
(original)
+++ cxf/branches/2.3.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/RuntimeExceptionMapper.java
Mon Jan 17 16:19:21 2011
@@ -22,7 +22,9 @@ import javax.ws.rs.core.Context;
 import javax.ws.rs.core.Response;
 import javax.ws.rs.core.UriInfo;
 import javax.ws.rs.ext.ExceptionMapper;
+import javax.ws.rs.ext.Provider;
 
+@Provider
 public class RuntimeExceptionMapper implements ExceptionMapper<RuntimeException> {
 
     @Context 



Mime
View raw message