cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1421983 - in /cxf/trunk: 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 17:17:09 GMT
Author: sergeyb
Date: Fri Dec 14 17:17:08 2012
New Revision: 1421983

URL: http://svn.apache.org/viewvc?rev=1421983&view=rev
Log:
[CXF-4702] Initial support for registering providers on the bus

Added:
    cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BusMapperException.java
  (with props)
Modified:
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ProviderFactory.java
    cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookServer.java
    cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java
    cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ProviderFactory.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ProviderFactory.java?rev=1421983&r1=1421982&r2=1421983&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ProviderFactory.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ProviderFactory.java
Fri Dec 14 17:17:08 2012
@@ -183,6 +183,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 
@@ -667,6 +668,26 @@ public final class ProviderFactory {
                                                   m);
     }
     
+    private void setBusProviders() {
+        List<Object> extensions = new LinkedList<Object>(); 
+        addBusExtension(extensions,
+                        MessageBodyReader.class,
+                        MessageBodyWriter.class,
+                        ExceptionMapper.class);
+        if (!extensions.isEmpty()) {
+            setProviders(extensions.toArray());
+        }
+    }
+    
+    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/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookServer.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookServer.java?rev=1421983&r1=1421982&r2=1421983&view=diff
==============================================================================
--- cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookServer.java (original)
+++ cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookServer.java Fri
Dec 14 17:17:08 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/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java?rev=1421983&r1=1421982&r2=1421983&view=diff
==============================================================================
--- cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java (original)
+++ cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java Fri
Dec 14 17:17:08 2012
@@ -136,6 +136,12 @@ public class BookStore {
         return books.get(id);
     }
     
+    @POST
+    @Path("/mapperonbus")
+    public void mapperOnBus() {
+        throw new BusMapperException();
+    }
+    
     @GET
     @Path("/beanparam2")
     @Produces("application/xml")

Added: cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BusMapperException.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BusMapperException.java?rev=1421983&view=auto
==============================================================================
--- cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BusMapperException.java
(added)
+++ cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BusMapperException.java
Fri Dec 14 17:17:08 2012
@@ -0,0 +1,25 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.cxf.systest.jaxrs;
+
+public class BusMapperException extends RuntimeException {
+
+    private static final long serialVersionUID = 3279797637779356514L;
+
+}

Propchange: cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BusMapperException.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BusMapperException.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Modified: cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java?rev=1421983&r1=1421982&r2=1421983&view=diff
==============================================================================
--- cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java
(original)
+++ cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java
Fri Dec 14 17:17:08 2012
@@ -90,6 +90,15 @@ 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.getHeaderString("BusMapper"));
+    }
+    
+    @Test
     public void testUseParamBeanWebClient() {
         String address = "http://localhost:" + PORT + "/bookstore/beanparam";
         doTestUseParamBeanWebClient(address);



Mime
View raw message