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 756E96B93 for ; Tue, 24 May 2011 17:45:55 +0000 (UTC) Received: (qmail 4734 invoked by uid 500); 24 May 2011 17:45:55 -0000 Delivered-To: apmail-cxf-commits-archive@cxf.apache.org Received: (qmail 4669 invoked by uid 500); 24 May 2011 17:45:55 -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 4662 invoked by uid 99); 24 May 2011 17:45:55 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 24 May 2011 17:45:55 +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; Tue, 24 May 2011 17:45:53 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id CC2352388A3C; Tue, 24 May 2011 17:45:33 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1127182 - in /cxf/trunk: rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/ rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/schemas/ systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/ systests/jaxrs/src/test/res... Date: Tue, 24 May 2011 17:45:33 -0000 To: commits@cxf.apache.org From: sergeyb@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20110524174533.CC2352388A3C@eris.apache.org> Author: sergeyb Date: Tue May 24 17:45:33 2011 New Revision: 1127182 URL: http://svn.apache.org/viewvc?rev=1127182&view=rev Log: [CXF-3538] Enabling schema validation for a maven plugin-driven test Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/ResourceUtils.java cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/schemas/SchemaHandler.java cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerSpringBookTest.java cxf/trunk/systests/jaxrs/src/test/resources/jaxrs/WEB-INF/beans.xml cxf/trunk/tools/wadlto/jaxrs/src/test/resources/wadl/bookstoreImport.xml Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/ResourceUtils.java URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/ResourceUtils.java?rev=1127182&r1=1127181&r2=1127182&view=diff ============================================================================== --- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/ResourceUtils.java (original) +++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/ResourceUtils.java Tue May 24 17:45:33 2011 @@ -20,7 +20,6 @@ package org.apache.cxf.jaxrs.utils; import java.io.File; -import java.io.FileInputStream; import java.io.InputStream; import java.io.InputStreamReader; import java.lang.annotation.Annotation; @@ -28,6 +27,7 @@ import java.lang.reflect.Constructor; import java.lang.reflect.Method; import java.lang.reflect.Modifier; import java.lang.reflect.Type; +import java.net.URL; import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; @@ -381,11 +381,16 @@ public final class ResourceUtils { } public static InputStream getResourceStream(String loc, Bus bus) throws Exception { - InputStream is = null; + URL url = getResourceURL(loc, bus); + return url == null ? null : url.openStream(); + } + + public static URL getResourceURL(String loc, Bus bus) throws Exception { + URL url = null; if (loc.startsWith(CLASSPATH_PREFIX)) { String path = loc.substring(CLASSPATH_PREFIX.length()); - is = ResourceUtils.getClasspathResourceStream(path, ResourceUtils.class, bus); - if (is == null) { + url = ResourceUtils.getClasspathResourceURL(path, ResourceUtils.class, bus); + if (url == null) { LOG.warning("No classpath resource " + loc + " is available on classpath"); return null; } @@ -396,20 +401,29 @@ public final class ResourceUtils { LOG.warning("No file resource " + loc + " is available on local disk"); return null; } - is = new FileInputStream(f); + url = f.toURI().toURL(); } - return is; + return url; } public static InputStream getClasspathResourceStream(String path, Class callingClass, Bus bus) { InputStream is = ClassLoaderUtils.getResourceAsStream(path, callingClass); - if (is == null && bus != null) { + return is == null ? getResource(path, InputStream.class, bus) : is; + } + + public static URL getClasspathResourceURL(String path, Class callingClass, Bus bus) { + URL url = ClassLoaderUtils.getResource(path, callingClass); + return url == null ? getResource(path, URL.class, bus) : url; + } + + public static T getResource(String path, Class resourceClass, Bus bus) { + if (bus != null) { ResourceManager rm = bus.getExtension(ResourceManager.class); if (rm != null) { - is = rm.getResourceAsStream(path); + return rm.resolveResource(path, resourceClass); } } - return is; + return null; } public static List getUserResources(String loc) { Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/schemas/SchemaHandler.java URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/schemas/SchemaHandler.java?rev=1127182&r1=1127181&r2=1127182&view=diff ============================================================================== --- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/schemas/SchemaHandler.java (original) +++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/schemas/SchemaHandler.java Tue May 24 17:45:33 2011 @@ -20,9 +20,9 @@ package org.apache.cxf.jaxrs.utils.schemas; import java.io.BufferedReader; -import java.io.InputStream; import java.io.InputStreamReader; import java.io.Reader; +import java.net.URL; import java.util.ArrayList; import java.util.List; import java.util.logging.Logger; @@ -68,13 +68,15 @@ public class SchemaHandler { try { List sources = new ArrayList(); for (String loc : locations) { - InputStream is = ResourceUtils.getResourceStream(loc, bus); - if (is == null) { + URL url = ResourceUtils.getResourceURL(loc, bus); + if (url == null) { return null; } Reader r = new BufferedReader( - new InputStreamReader(is, "UTF-8")); - sources.add(new StreamSource(r)); + new InputStreamReader(url.openStream(), "UTF-8")); + StreamSource source = new StreamSource(r); + source.setSystemId(url.toString()); + sources.add(source); } s = factory.newSchema(sources.toArray(new Source[]{})); } catch (Exception ex) { Modified: cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerSpringBookTest.java URL: http://svn.apache.org/viewvc/cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerSpringBookTest.java?rev=1127182&r1=1127181&r2=1127182&view=diff ============================================================================== --- cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerSpringBookTest.java (original) +++ cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerSpringBookTest.java Tue May 24 17:45:33 2011 @@ -74,7 +74,10 @@ public class JAXRSClientServerSpringBook public void testPostGeneratedBook() throws Exception { String baseAddress = "http://localhost:" + PORT + "/the/generated/bookstore/books/1"; JAXBElementProvider provider = new JAXBElementProvider(); - provider.setMarshallAsJaxbElement(true); + provider.setJaxbElementClassMap(Collections.singletonMap( + "org.apache.cxf.systest.jaxrs.codegen.schema.Book", + "{http://superbooks}thebook")); + WebClient wc = WebClient.create(baseAddress, Collections.singletonList(provider)); wc.type("application/xml"); Modified: cxf/trunk/systests/jaxrs/src/test/resources/jaxrs/WEB-INF/beans.xml URL: http://svn.apache.org/viewvc/cxf/trunk/systests/jaxrs/src/test/resources/jaxrs/WEB-INF/beans.xml?rev=1127182&r1=1127181&r2=1127182&view=diff ============================================================================== --- cxf/trunk/systests/jaxrs/src/test/resources/jaxrs/WEB-INF/beans.xml (original) +++ cxf/trunk/systests/jaxrs/src/test/resources/jaxrs/WEB-INF/beans.xml Tue May 24 17:45:33 2011 @@ -193,8 +193,13 @@ http://cxf.apache.org/schemas/core.xsd"> + + + classpath:/wadl/schemas/book.xsd + + Modified: cxf/trunk/tools/wadlto/jaxrs/src/test/resources/wadl/bookstoreImport.xml URL: http://svn.apache.org/viewvc/cxf/trunk/tools/wadlto/jaxrs/src/test/resources/wadl/bookstoreImport.xml?rev=1127182&r1=1127181&r2=1127182&view=diff ============================================================================== --- cxf/trunk/tools/wadlto/jaxrs/src/test/resources/wadl/bookstoreImport.xml (original) +++ cxf/trunk/tools/wadlto/jaxrs/src/test/resources/wadl/bookstoreImport.xml Tue May 24 17:45:33 2011 @@ -30,7 +30,7 @@ - +