Return-Path: X-Original-To: apmail-cxf-commits-archive@www.apache.org Delivered-To: apmail-cxf-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 9D7D7D240 for ; Fri, 14 Dec 2012 22:50:40 +0000 (UTC) Received: (qmail 21893 invoked by uid 500); 14 Dec 2012 22:50:40 -0000 Delivered-To: apmail-cxf-commits-archive@cxf.apache.org Received: (qmail 21845 invoked by uid 500); 14 Dec 2012 22:50:40 -0000 Mailing-List: contact commits-help@cxf.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@cxf.apache.org Delivered-To: mailing list commits@cxf.apache.org Received: (qmail 21804 invoked by uid 99); 14 Dec 2012 22:50:38 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 14 Dec 2012 22:50:38 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 14 Dec 2012 22:50:35 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id E0F942388AA9; Fri, 14 Dec 2012 22:50:13 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit 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 -0000 To: commits@cxf.apache.org From: sergeyb@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20121214225013.E0F942388AA9@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org 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 extensions = new LinkedList(); + 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 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 { + + 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);