cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ashaki...@apache.org
Subject svn commit: r1445090 - in /cxf/trunk: rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/ systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/ systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/jaxws/
Date Tue, 12 Feb 2013 10:22:25 GMT
Author: ashakirin
Date: Tue Feb 12 10:22:25 2013
New Revision: 1445090

URL: http://svn.apache.org/r1445090
Log:
[CXF-4800] Extended using of exception mapper for methods returning Response

Modified:
    cxf/trunk/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/ClientProxyImpl.java
    cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSSoapBookTest.java
    cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/jaxws/BookStoreJaxrsJaxws.java
    cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/jaxws/BookStoreSoapRestImpl.java

Modified: cxf/trunk/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/ClientProxyImpl.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/ClientProxyImpl.java?rev=1445090&r1=1445089&r2=1445090&view=diff
==============================================================================
--- cxf/trunk/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/ClientProxyImpl.java
(original)
+++ cxf/trunk/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/ClientProxyImpl.java
Tue Feb 12 10:22:25 2013
@@ -275,9 +275,6 @@ public class ClientProxyImpl extends Abs
         int status = r.getStatus();
         
         if (status >= 300) {
-            if (m.getReturnType() == Response.class && m.getExceptionTypes().length
== 0) {
-                return;
-            }            
             ResponseExceptionMapper<?> mapper = findExceptionMapper(m, inMessage);
             if (mapper != null) {
                 t = mapper.fromResponse(r);
@@ -285,7 +282,11 @@ public class ClientProxyImpl extends Abs
                     throw t;
                 }
             } 
-                        
+                 
+            if ((t == null) && (m.getReturnType() == Response.class) && (m.getExceptionTypes().length
== 0)) {
+                return;
+            }
+
             t = convertToWebApplicationException(r);
             
             if (inMessage.getExchange().get(Message.RESPONSE_CODE) == null) {

Modified: cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSSoapBookTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSSoapBookTest.java?rev=1445090&r1=1445089&r2=1445090&view=diff
==============================================================================
--- cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSSoapBookTest.java
(original)
+++ cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSSoapBookTest.java
Tue Feb 12 10:22:25 2013
@@ -30,6 +30,7 @@ import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
+import javax.ws.rs.NotFoundException;
 import javax.ws.rs.WebApplicationException;
 import javax.ws.rs.core.MediaType;
 import javax.ws.rs.core.MultivaluedMap;
@@ -81,6 +82,7 @@ import org.apache.cxf.systest.jaxrs.jaxw
 import org.apache.cxf.testutil.common.AbstractBusClientServerTestBase;
 import org.apache.cxf.transport.http.HTTPConduit;
 import org.apache.cxf.transports.http.configuration.HTTPClientPolicy;
+import org.apache.http.HttpStatus;
 
 import org.junit.BeforeClass;
 import org.junit.Ignore;
@@ -436,7 +438,28 @@ public class JAXRSSoapBookTest extends A
             assertEquals("No Book with id 356 is available", ex.getMessage());
         }
     }
-    
+
+    @Test(expected = NotFoundException.class)   
+    public void testCheckBookClientException() {
+        
+        String baseAddress = "http://localhost:" + PORT + "/test/services/rest";
+        BookStoreJaxrsJaxws proxy = JAXRSClientFactory.create(baseAddress,
+                                          BookStoreJaxrsJaxws.class,
+                                          Collections.singletonList(new NotFoundResponseExceptionMapper()));
+        proxy.checkBook(100L);
+    }
+
+    @Test 
+    public void testCheckBookClientErrorResponse() {
+        
+        String baseAddress = "http://localhost:" + PORT + "/test/services/rest";
+        BookStoreJaxrsJaxws proxy = JAXRSClientFactory.create(baseAddress,
+                                          BookStoreJaxrsJaxws.class,
+                                          Collections.singletonList(new DummyResponseExceptionMapper()));
+        Response response = proxy.checkBook(100L);
+        assertEquals(HttpStatus.SC_NOT_FOUND, response.getStatus());
+    }
+
     @Test
     public void testNoBook357WebClient() throws Exception {
         
@@ -928,6 +951,26 @@ public class JAXRSSoapBookTest extends A
         
     }
 
+    @Ignore
+    public static class NotFoundResponseExceptionMapper implements ResponseExceptionMapper<Exception>
{
+        
+        public Exception fromResponse(Response r) {
+            if (r.getStatus() == HttpStatus.SC_NOT_FOUND) {
+                return new NotFoundException();
+            } else {
+                return null;
+            }
+        }
+    }
+
+    @Ignore
+    public static class DummyResponseExceptionMapper implements ResponseExceptionMapper<Exception>
{
+        
+        public Exception fromResponse(Response r) {
+            return null;
+        }
+    }
+
     @Ignore 
     public class TestStreamDrainInterptor extends AbstractPhaseInterceptor<Message>
{
         public TestStreamDrainInterptor() {

Modified: cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/jaxws/BookStoreJaxrsJaxws.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/jaxws/BookStoreJaxrsJaxws.java?rev=1445090&r1=1445089&r2=1445090&view=diff
==============================================================================
--- cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/jaxws/BookStoreJaxrsJaxws.java
(original)
+++ cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/jaxws/BookStoreJaxrsJaxws.java
Tue Feb 12 10:22:25 2013
@@ -28,6 +28,7 @@ import javax.ws.rs.POST;
 import javax.ws.rs.Path;
 import javax.ws.rs.PathParam;
 import javax.ws.rs.Produces;
+import javax.ws.rs.core.Response;
 
 import org.apache.cxf.systest.jaxrs.Book;
 import org.apache.cxf.systest.jaxrs.BookNotFoundFault;
@@ -66,4 +67,8 @@ public interface BookStoreJaxrsJaxws {
     @Path("/fastinfoset2")
     @Produces({"application/fastinfoset", "text/xml", "application/xml" })
     Book getFastinfoBook();
+
+    @GET
+    @Path("/check/{id}")
+    Response checkBook(@PathParam("id") Long id);
 }

Modified: cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/jaxws/BookStoreSoapRestImpl.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/jaxws/BookStoreSoapRestImpl.java?rev=1445090&r1=1445089&r2=1445090&view=diff
==============================================================================
--- cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/jaxws/BookStoreSoapRestImpl.java
(original)
+++ cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/jaxws/BookStoreSoapRestImpl.java
Tue Feb 12 10:22:25 2013
@@ -40,6 +40,7 @@ import org.apache.cxf.systest.jaxrs.Book
 import org.apache.cxf.systest.jaxrs.BookNotFoundFault;
 import org.apache.cxf.systest.jaxrs.BookSubresource;
 import org.apache.cxf.systest.jaxrs.BookSubresourceImpl;
+import org.apache.http.HttpStatus;
 
 @SchemaValidation
 public class BookStoreSoapRestImpl implements BookStoreJaxrsJaxws {
@@ -150,5 +151,14 @@ public class BookStoreSoapRestImpl imple
     public Book getFastinfoBook() {
         return new Book("CXF2", 2L);
     }
+
+    @Override
+    public Response checkBook(Long id) {
+        if (id.longValue() != 0L) {
+            return Response.status(HttpStatus.SC_NOT_FOUND).build();
+        } else {
+            return Response.ok().build();
+        }
+    }
     
 }



Mime
View raw message