cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1461083 - in /cxf/branches/2.5.x-fixes: ./ rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/
Date Tue, 26 Mar 2013 12:29:47 GMT
Author: sergeyb
Date: Tue Mar 26 12:29:47 2013
New Revision: 1461083

URL: http://svn.apache.org/r1461083
Log:
Merged revisions 1461046 via svnmerge from 
https://svn.apache.org/repos/asf/cxf/branches/2.6.x-fixes

................
  r1461046 | sergeyb | 2013-03-26 13:16:43 +0300 (Tue, 26 Mar 2013) | 16 lines
  
  Merged revisions 1461039 via svnmerge from 
  https://svn.apache.org/repos/asf/cxf/branches/2.7.x-fixes
  
  ................
    r1461039 | sergeyb | 2013-03-26 12:50:00 +0300 (Tue, 26 Mar 2013) | 9 lines
    
    Merged revisions 1461035 via svnmerge from 
    https://svn.apache.org/repos/asf/cxf/trunk
    
    ........
      r1461035 | sergeyb | 2013-03-26 12:29:24 +0300 (Tue, 26 Mar 2013) | 1 line
      
      [CXF-4912] Getting multiple declared exceptions checked by the client proxy, patch on
behalf of Parwiz Rezai applied with minor modifications
    ........
  ................
................

Modified:
    cxf/branches/2.5.x-fixes/   (props changed)
    cxf/branches/2.5.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ClientProxyImpl.java
    cxf/branches/2.5.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java
    cxf/branches/2.5.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java

Propchange: cxf/branches/2.5.x-fixes/
------------------------------------------------------------------------------
--- svn:mergeinfo (added)
+++ svn:mergeinfo Tue Mar 26 12:29:47 2013
@@ -0,0 +1,3 @@
+/cxf/branches/2.6.x-fixes:1461046
+/cxf/branches/2.7.x-fixes:1461039
+/cxf/trunk:1461035

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

Modified: cxf/branches/2.5.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ClientProxyImpl.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.5.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ClientProxyImpl.java?rev=1461083&r1=1461082&r2=1461083&view=diff
==============================================================================
--- cxf/branches/2.5.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ClientProxyImpl.java
(original)
+++ cxf/branches/2.5.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ClientProxyImpl.java
Tue Mar 26 12:29:47 2013
@@ -266,11 +266,17 @@ public class ClientProxyImpl extends Abs
             if (m.getReturnType() == Response.class && m.getExceptionTypes().length
== 0) {
                 return;
             }            
-            ResponseExceptionMapper<?> mapper = findExceptionMapper(m, inMessage);
-            if (mapper != null) {
-                t = mapper.fromResponse(r);
-                if (t != null) {
-                    throw t;
+            Class<?>[] exTypes = m.getExceptionTypes();
+            if (exTypes.length == 0) {
+                exTypes = new Class[]{ServerWebApplicationException.class};
+            }
+            for (Class<?> exType : exTypes) {
+                ResponseExceptionMapper<?> mapper = findExceptionMapper(inMessage,
exType);
+                if (mapper != null) {
+                    t = mapper.fromResponse(r);
+                    if (t != null) {
+                        throw t;
+                    }
                 }
             } 
                         
@@ -296,15 +302,9 @@ public class ClientProxyImpl extends Abs
         }
     }
     
-    private static ResponseExceptionMapper<?> findExceptionMapper(Method m, Message
message) {
+    private static ResponseExceptionMapper<?> findExceptionMapper(Message message,
Class<?> exType) {
         ProviderFactory pf = ProviderFactory.getInstance(message);
-        for (Class<?> exType : m.getExceptionTypes()) {
-            ResponseExceptionMapper<?> mapper = pf.createResponseExceptionMapper(exType);
-            if (mapper != null) {
-                return mapper;
-            }
-        }
-        return null;
+        return pf.createResponseExceptionMapper(exType);
     }
     
     private MultivaluedMap<String, String> setRequestHeaders(MultivaluedMap<String,
String> headers,          

Modified: cxf/branches/2.5.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.5.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java?rev=1461083&r1=1461082&r2=1461083&view=diff
==============================================================================
--- cxf/branches/2.5.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java
(original)
+++ cxf/branches/2.5.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java
Tue Mar 26 12:29:47 2013
@@ -236,6 +236,24 @@ public class BookStore {
     }
     
     @GET
+    @Path("multipleexceptions")
+    public Response getBookWithExceptions(@QueryParam("exception") boolean notReturned) 
+        throws BookNotFoundFault, BookNotReturnedException {
+        if (notReturned) {
+            throw new WebApplicationException(Response.status(404).header("Status", "notReturned").build());
+        } else {
+            throw new WebApplicationException(Response.status(404).header("Status", "notFound").build());
+        }
+    }
+    
+    @GET
+    @Path("multipleexceptions2")
+    public Response getBookWithExceptions2(@QueryParam("exception") boolean notReturned)

+        throws BookNotReturnedException, BookNotFoundFault {
+        return getBookWithExceptions(notReturned);
+    }
+    
+    @GET
     @Path("propogateExceptionVar/{i}")
     public Book propogateExceptionWithVar() throws BookNotFoundFault {
         return null;
@@ -990,6 +1008,15 @@ public class BookStore {
         return echoBookNameAndHeader(httpHeaders.getRequestHeader("CustomHeader").get(0),
name);
     }
     
+    @POST
+    @Path("/booksecho3")
+    @Consumes("text/plain")
+    @Produces("text/plain")
+    public Response echoBookNameAndHeader3(String name) {
+        return echoBookNameAndHeader(httpHeaders.getRequestHeader("customheader").get(0),
name);
+    }
+        
+    
     @GET
     @Path("/cd/{CDId}/")
     public CD getCD() {
@@ -1199,6 +1226,16 @@ public class BookStore {
                                     new Class[]{Book.class}, 
                                     handler);
     }
+    
+    public static class BookNotReturnedException extends RuntimeException {
+
+        private static final long serialVersionUID = 4935423670510083220L;
+
+        public BookNotReturnedException(String errorMessage) {
+            super(errorMessage);
+        }
+        
+    }
 }
 
 

Modified: cxf/branches/2.5.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.5.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java?rev=1461083&r1=1461082&r2=1461083&view=diff
==============================================================================
--- cxf/branches/2.5.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java
(original)
+++ cxf/branches/2.5.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java
Tue Mar 26 12:29:47 2013
@@ -28,6 +28,7 @@ import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.HashMap;
+import java.util.LinkedList;
 import java.util.List;
 import java.util.Map;
 
@@ -53,6 +54,7 @@ import org.apache.cxf.io.CachedOutputStr
 import org.apache.cxf.jaxrs.client.ClientWebApplicationException;
 import org.apache.cxf.jaxrs.client.JAXRSClientFactory;
 import org.apache.cxf.jaxrs.client.JAXRSClientFactoryBean;
+import org.apache.cxf.jaxrs.client.ResponseExceptionMapper;
 import org.apache.cxf.jaxrs.client.ResponseReader;
 import org.apache.cxf.jaxrs.client.ServerWebApplicationException;
 import org.apache.cxf.jaxrs.client.WebClient;
@@ -64,6 +66,7 @@ import org.apache.cxf.phase.AbstractPhas
 import org.apache.cxf.phase.Phase;
 import org.apache.cxf.systest.jaxrs.BookStore.BookInfo;
 import org.apache.cxf.systest.jaxrs.BookStore.BookInfoInterface;
+import org.apache.cxf.systest.jaxrs.BookStore.BookNotReturnedException;
 import org.apache.cxf.testutil.common.AbstractBusClientServerTestBase;
 
 import org.junit.BeforeClass;
@@ -339,6 +342,51 @@ public class JAXRSClientServerBookTest e
     }
     
     @Test
+    public void testBookWithMultipleExceptions() throws Exception {
+        List<Object> providers = new LinkedList<Object>();
+        providers.add(new NotReturnedExceptionMapper());
+        providers.add(new NotFoundExceptionMapper());
+        BookStore store = JAXRSClientFactory.create("http://localhost:" + PORT, 
+                                                    BookStore.class,
+                                                    providers);
+        try {
+            store.getBookWithExceptions(true);
+            fail();
+        } catch (BookNotReturnedException ex) {
+            assertEquals("notReturned", ex.getMessage());
+        }
+        try {
+            store.getBookWithExceptions(false);
+            fail();
+        } catch (BookNotFoundFault ex) {
+            assertEquals("notFound", ex.getMessage());
+        }
+        
+    }
+    
+    @Test
+    public void testBookWithMultipleExceptions2() throws Exception {
+        List<Object> providers = new LinkedList<Object>();
+        providers.add(new NotReturnedExceptionMapper());
+        providers.add(new NotFoundExceptionMapper());
+        BookStore store = JAXRSClientFactory.create("http://localhost:" + PORT, 
+                                                    BookStore.class,
+                                                    providers);
+        try {
+            store.getBookWithExceptions2(true);
+            fail();
+        } catch (BookNotReturnedException ex) {
+            assertEquals("notReturned", ex.getMessage());
+        }
+        try {
+            store.getBookWithExceptions2(false);
+            fail();
+        } catch (BookNotFoundFault ex) {
+            assertEquals("notFound", ex.getMessage());
+        }
+    }
+    
+    @Test
     public void testTempRedirectWebClient() throws Exception {
         WebClient client = WebClient.create("http://localhost:" + PORT + "/bookstore/tempredirect");
         Response r = client.type("*/*").get();
@@ -1045,6 +1093,15 @@ public class JAXRSClientServerBookTest e
     }
     
     @Test
+    public void testGetBookLowCaseHeader() throws Exception {
+        WebClient wc = WebClient.create("http://localhost:" + PORT + "/bookstore/booksecho3");
+        wc.type("text/plain").accept("text/plain").header("CustomHeader", "custom");
+        String name = wc.post("book", String.class);
+        assertEquals("book", name);
+        assertEquals("custom", wc.getResponse().getMetadata().getFirst("CustomHeader").toString());
+    }
+    
+    @Test
     public void testGetBookSimple() throws Exception {
         WebClient wc = WebClient.create("http://localhost:" + PORT + "/simplebooks/simple");
         Book book = wc.get(Book.class);
@@ -1919,4 +1976,29 @@ public class JAXRSClientServerBookTest e
         }
     }
     
+    public static class NotReturnedExceptionMapper implements ResponseExceptionMapper<BookNotReturnedException>
{
+
+        public BookNotReturnedException fromResponse(Response r) {
+            String status = r.getMetadata().getFirst("Status").toString();
+            if ("notReturned".equals(status)) { 
+                return new BookNotReturnedException(status);
+            } else {
+                return null;
+            }
+        }
+        
+    }
+    
+    public static class NotFoundExceptionMapper implements ResponseExceptionMapper<BookNotFoundFault>
{
+
+        public BookNotFoundFault fromResponse(Response r) {
+            String status = r.getMetadata().getFirst("Status").toString();
+            if ("notFound".equals(status)) { 
+                return new BookNotFoundFault(status);
+            } else {
+                return null;
+            }
+        }
+        
+    }
 }



Mime
View raw message