cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1422136 - in /cxf/branches/2.6.x-fixes: ./ rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/
Date Fri, 14 Dec 2012 22:50:12 GMT
Author: sergeyb
Date: Fri Dec 14 22:50:10 2012
New Revision: 1422136

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

........
  r1421983 | sergeyb | 2012-12-14 17:17:08 +0000 (Fri, 14 Dec 2012) | 1 line
  
  [CXF-4702] Initial support for registering providers on the bus
........
  r1422119 | sergeyb | 2012-12-14 22:07:38 +0000 (Fri, 14 Dec 2012) | 1 line
  
  [CXF-4702] Minor optimization
........

Added:
    cxf/branches/2.6.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BusMapperException.java
      - copied unchanged from r1422119, cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BusMapperException.java
Modified:
    cxf/branches/2.6.x-fixes/   (props changed)
    cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ProviderFactory.java
    cxf/branches/2.6.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookServer.java
    cxf/branches/2.6.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java
    cxf/branches/2.6.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java

Propchange: cxf/branches/2.6.x-fixes/
------------------------------------------------------------------------------
    svn:mergeinfo = /cxf/trunk:1421983-1422119

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

Modified: cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ProviderFactory.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ProviderFactory.java?rev=1422136&r1=1422135&r2=1422136&view=diff
==============================================================================
--- cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ProviderFactory.java
(original)
+++ cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ProviderFactory.java
Fri Dec 14 22:50:10 2012
@@ -115,6 +115,7 @@ public final class ProviderFactory {
     private ProviderFactory(Bus bus) {
         this.bus = bus;
         initJaxbProviders();
+        setBusProviders();
     }
     
     // Not ideal but in the end seems like the simplest option compared 
@@ -480,6 +481,30 @@ public final class ProviderFactory {
                                                   m);
     }
     
+    private void setBusProviders() {
+        List<Object> extensions = new LinkedList<Object>(); 
+        final String alreadySetProp = "bus.providers.set";
+        if (bus.getProperty(alreadySetProp) == null) {
+            addBusExtension(extensions,
+                            MessageBodyReader.class,
+                            MessageBodyWriter.class,
+                            ExceptionMapper.class);
+            if (!extensions.isEmpty()) {
+                setProviders(extensions.toArray());
+                bus.setProperty(alreadySetProp, "");
+            }
+        }
+    }
+    
+    private void addBusExtension(List<Object> extensions, Class<?>... extClasses)
{
+        for (Class<?> extClass : extClasses) {
+            Object ext = bus.getProperty(extClass.getName());
+            if (ext != null && extClass.isInstance(ext)) {
+                extensions.add(ext);
+            }
+        }
+    }
+    
 //CHECKSTYLE:OFF       
     private void setProviders(Object... providers) {
         

Modified: cxf/branches/2.6.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookServer.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.6.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookServer.java?rev=1422136&r1=1422135&r2=1422136&view=diff
==============================================================================
--- cxf/branches/2.6.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookServer.java
(original)
+++ cxf/branches/2.6.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookServer.java
Fri Dec 14 22:50:10 2012
@@ -25,6 +25,9 @@ import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
+import javax.ws.rs.core.Response;
+import javax.ws.rs.ext.ExceptionMapper;
+
 import org.apache.cxf.Bus;
 import org.apache.cxf.BusFactory;
 import org.apache.cxf.interceptor.Interceptor;
@@ -46,6 +49,7 @@ public class BookServer extends Abstract
     
     protected void run() {
         Bus bus = BusFactory.getDefaultBus();
+        bus.setProperty(ExceptionMapper.class.getName(), new BusMapperExceptionMapper());
         setBus(bus);
         JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean();
         sf.setBus(bus);
@@ -103,4 +107,12 @@ public class BookServer extends Abstract
             System.out.println("done!");
         }
     }
+    
+    private static class BusMapperExceptionMapper implements ExceptionMapper<BusMapperException>
{
+
+        public Response toResponse(BusMapperException exception) {
+            return Response.serverError().header("BusMapper", "the-mapper").build();
+        }
+        
+    }
 }

Modified: cxf/branches/2.6.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.6.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java?rev=1422136&r1=1422135&r2=1422136&view=diff
==============================================================================
--- cxf/branches/2.6.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java
(original)
+++ cxf/branches/2.6.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java
Fri Dec 14 22:50:10 2012
@@ -120,6 +120,12 @@ public class BookStore {
         //System.out.println("PreDestroy called");
     }
 
+    @POST
+    @Path("/mapperonbus")
+    public void mapperOnBus() {
+        throw new BusMapperException();
+    }
+
     @GET
     @Path("emptybook")
     @Produces({"application/xml", "application/json" })

Modified: cxf/branches/2.6.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.6.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java?rev=1422136&r1=1422135&r2=1422136&view=diff
==============================================================================
--- cxf/branches/2.6.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java
(original)
+++ cxf/branches/2.6.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java
Fri Dec 14 22:50:10 2012
@@ -89,6 +89,14 @@ public class JAXRSClientServerBookTest e
     }
     
     @Test
+    public void testUseMapperOnBus() {
+        String address = "http://localhost:" + PORT + "/bookstore/mapperonbus";
+        WebClient wc = WebClient.create(address);
+        Response r = wc.post(null);
+        assertEquals(500, r.getStatus());
+        assertEquals("the-mapper", r.getMetadata().getFirst("BusMapper").toString());
+    }
+
     public void testGetIntroChapterFromSelectedBook() {
         String address = "http://localhost:" + PORT + "/bookstore/books(id=le=123)/chapter";
         doTestGetChapterFromSelectedBook(address);



Mime
View raw message