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> T getResource(String path, Class<T> 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<UserResource> 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<Source> sources = new ArrayList<Source>();
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">
<bean id="jaxbProviderForTypes"
class="org.apache.cxf.jaxrs.provider.JAXBElementProvider">
<property name="unmarshallAsJaxbElement" value="true"/>
+ <property name="schemaLocations" ref="theSchemaLocations"/>
</bean>
+ <util:list id="theSchemaLocations">
+ <value>classpath:/wadl/schemas/book.xsd</value>
+ </util:list>
+
<bean id="jaxbProvider"
class="org.apache.cxf.jaxrs.provider.JAXBElementProvider">
<property name="schemaHandler" ref="schemaHolder"/>
</bean>
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 @@
<method name="POST" id="addBook">
<request>
- <representation mediaType="application/xml" element="prefix1:thebook2"/>
+ <representation mediaType="application/xml" element="prefix1:thebook"/>
</request>
</method>
</resource>