cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r703513 - in /cxf/trunk/rt/frontend/jaxrs/src: main/java/org/apache/cxf/jaxrs/ main/java/org/apache/cxf/jaxrs/provider/ main/resources/schemas/ test/java/org/apache/cxf/jaxrs/provider/ test/resources/
Date Fri, 10 Oct 2008 16:16:05 GMT
Author: sergeyb
Date: Fri Oct 10 09:16:03 2008
New Revision: 703513

URL: http://svn.apache.org/viewvc?rev=703513&view=rev
Log:
Initial support for schema validation and xsi:schemaLocation

Added:
    cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/JAXBElementProviderTest.java
  (with props)
    cxf/trunk/rt/frontend/jaxrs/src/test/resources/
    cxf/trunk/rt/frontend/jaxrs/src/test/resources/test.xsd   (with props)
Modified:
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSServerFactoryBean.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/AbstractJAXBProvider.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/FormEncodingReaderProvider.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JAXBElementProvider.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JSONProvider.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ProviderFactory.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/SourceProvider.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/StringProvider.java
    cxf/trunk/rt/frontend/jaxrs/src/main/resources/schemas/jaxrs.xsd
    cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/ProviderFactoryTest.java

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSServerFactoryBean.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSServerFactoryBean.java?rev=703513&r1=703512&r2=703513&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSServerFactoryBean.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSServerFactoryBean.java
Fri Oct 10 09:16:03 2008
@@ -67,6 +67,7 @@
     private List<?> entityProviders;
     private Map<Object, Object> languageMappings;
     private Map<Object, Object> extensionMappings;
+    private List<String> schemaLocations;
 
     public JAXRSServerFactoryBean() {
         this(new JAXRSServiceFactoryBean());
@@ -78,6 +79,10 @@
         setBindingId(JAXRSBindingFactory.JAXRS_BINDING_ID);
     }
     
+    public void setSchemaLocations(List<String> schemas) {
+        this.schemaLocations = schemas;    
+    }
+    
     public Server create() {
         try {
             Endpoint ep = createEndpoint();
@@ -96,7 +101,9 @@
             }
             ProviderFactory.getInstance().setRequestPreporcessor(
                 new RequestPreprocessor(languageMappings, extensionMappings));
-            
+            if (schemaLocations != null) {
+                ProviderFactory.getInstance().setSchemaLocations(schemaLocations);
+            }
             
             if (start) {
                 server.start();

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/AbstractJAXBProvider.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/AbstractJAXBProvider.java?rev=703513&r1=703512&r2=703513&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/AbstractJAXBProvider.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/AbstractJAXBProvider.java
Fri Oct 10 09:16:03 2008
@@ -19,8 +19,16 @@
 
 package org.apache.cxf.jaxrs.provider;
 
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.Reader;
 import java.lang.annotation.Annotation;
 import java.lang.reflect.Type;
+import java.util.ArrayList;
+import java.util.List;
 import java.util.Map;
 import java.util.WeakHashMap;
 import java.util.logging.Logger;
@@ -30,13 +38,19 @@
 import javax.ws.rs.ext.ContextResolver;
 import javax.ws.rs.ext.MessageBodyReader;
 import javax.ws.rs.ext.MessageBodyWriter;
+import javax.xml.XMLConstants;
 import javax.xml.bind.JAXBContext;
 import javax.xml.bind.JAXBElement;
 import javax.xml.bind.JAXBException;
 import javax.xml.bind.Marshaller;
+import javax.xml.bind.Unmarshaller;
 import javax.xml.bind.annotation.XmlRootElement;
 import javax.xml.bind.annotation.adapters.XmlAdapter;
 import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
+import javax.xml.transform.Source;
+import javax.xml.transform.stream.StreamSource;
+import javax.xml.validation.Schema;
+import javax.xml.validation.SchemaFactory;
 
 import org.apache.cxf.common.logging.LogUtils;
 import org.apache.cxf.common.util.PackageUtils;
@@ -49,11 +63,13 @@
     private static final Logger LOG = LogUtils.getL7dLogger(AbstractJAXBProvider.class);
 
     private static final String CHARSET_PARAMETER = "charset"; 
-
+    private static final String CLASSPATH_PREFIX = "classpath:";
+        
     private static Map<String, JAXBContext> packageContexts = new WeakHashMap<String,
JAXBContext>();
     private static Map<Class<?>, JAXBContext> classContexts = new WeakHashMap<Class<?>,
JAXBContext>();
     
     @Context protected ContextResolver<JAXBContext> resolver;
+    private Schema schema;
     
     public boolean isWriteable(Class<?> type, Type genericType, Annotation[] anns)
{
         return isSupported(type, genericType, anns)
@@ -64,6 +80,10 @@
         return isSupported(type, genericType, annotations);
     }
 
+    public void setSchemas(List<String> locations) {
+        schema = createSchema(locations);    
+    }
+    
     public long getSize(Object o) {
         return -1;
     }
@@ -97,7 +117,7 @@
         synchronized (classContexts) {
             JAXBContext context = classContexts.get(type);
             if (context == null) {
-                context = JAXBContext.newInstance(type);
+                context = JAXBContext.newInstance(new Class[]{type});
                 classContexts.put(type, context);
             }
             return context;
@@ -148,6 +168,17 @@
         return objectFactoryForClass(InjectionUtils.getActualType(genericType));
     }
     
+    @SuppressWarnings("deprecation")
+    protected Unmarshaller createUnmarshaller(Class<?> cls, Type genericType) 
+        throws JAXBException {
+        JAXBContext context = getJAXBContext(cls, genericType);
+        Unmarshaller unmarshaller = context.createUnmarshaller();
+        if (schema != null) {
+            unmarshaller.setSchema(schema);
+        }
+        return unmarshaller;        
+    }
+    
     protected Marshaller createMarshaller(Object obj, Class<?> cls, Type genericType,
MediaType m)
         throws JAXBException {
         
@@ -187,4 +218,44 @@
         }
         return obj;
     }
+    
+    private Schema createSchema(List<String> locations) {
+        
+        SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
+        Schema s = null;
+        try {
+            List<Source> sources = new ArrayList<Source>();
+            for (String loc : locations) {
+                InputStream is = null;
+                if (loc.startsWith(CLASSPATH_PREFIX)) {
+                    String path = loc.substring(CLASSPATH_PREFIX.length() + 1);
+                    is = getClass().getClassLoader().getResourceAsStream(path);
+                    if (is == null) {
+                        LOG.warning("No schema resource " + loc + " is available on classpath");
+                        return null;
+                    }
+                } else {
+                    File f = new File(loc);
+                    if (!f.exists()) {
+                        LOG.warning("No schema resource " + loc + " is available on local
disk");
+                        return null;
+                    }
+                    is = new FileInputStream(f);
+                }
+                                
+                Reader r = new BufferedReader(
+                               new InputStreamReader(is, "UTF-8"));
+                sources.add(new StreamSource(r));
+            }
+            s = factory.newSchema(sources.toArray(new Source[]{}));
+        } catch (Exception ex) {
+            LOG.warning("Validation will be disabled, failed to create schema : " + ex.getMessage());
+        }
+        return s;
+        
+    }
+    
+    protected Schema getSchema() {
+        return schema;
+    }
 }

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/FormEncodingReaderProvider.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/FormEncodingReaderProvider.java?rev=703513&r1=703512&r2=703513&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/FormEncodingReaderProvider.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/FormEncodingReaderProvider.java
Fri Oct 10 09:16:03 2008
@@ -29,6 +29,7 @@
 import java.util.List;
 
 import javax.ws.rs.ConsumeMime;
+import javax.ws.rs.WebApplicationException;
 import javax.ws.rs.core.MediaType;
 import javax.ws.rs.core.MultivaluedMap;
 import javax.ws.rs.ext.MessageBodyReader;
@@ -62,10 +63,8 @@
 
             return params;
         } catch (Exception e) {
-            e.printStackTrace();
+            throw new WebApplicationException(e);
         }
-
-        return null;
     }
 
     public static void copy(final InputStream input, final OutputStream output, final int
bufferSize)

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JAXBElementProvider.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JAXBElementProvider.java?rev=703513&r1=703512&r2=703513&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JAXBElementProvider.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JAXBElementProvider.java
Fri Oct 10 09:16:03 2008
@@ -25,11 +25,12 @@
 import java.io.OutputStream;
 import java.lang.annotation.Annotation;
 import java.lang.reflect.Type;
+import java.util.List;
 
+import javax.ws.rs.WebApplicationException;
 import javax.ws.rs.core.MediaType;
 import javax.ws.rs.core.MultivaluedMap;
 import javax.ws.rs.ext.Provider;
-import javax.xml.bind.JAXBContext;
 import javax.xml.bind.JAXBElement;
 import javax.xml.bind.JAXBException;
 import javax.xml.bind.Marshaller;
@@ -39,15 +40,23 @@
 @Provider
 public final class JAXBElementProvider extends AbstractJAXBProvider  {
     
+    private String jaxbSchemaLocation;
+    
+    public void setSchemas(List<String> locations) {
+        super.setSchemas(locations);
+    }
+    
+    public void setSchemaLocation(String schemaLocation) {
+        jaxbSchemaLocation = schemaLocation;
+    }
     
     public Object readFrom(Class<Object> type, Type genericType, Annotation[] annotations,
MediaType m, 
         MultivaluedMap<String, String> headers, InputStream is) 
         throws IOException {
         try {
             Class<?> theType = getActualType(type, genericType);
-            JAXBContext context = getJAXBContext(theType, genericType);
+            Unmarshaller unmarshaller = createUnmarshaller(theType, genericType);
             
-            Unmarshaller unmarshaller = context.createUnmarshaller();
             if (JAXBElement.class.isAssignableFrom(type)) {
                 return unmarshaller.unmarshal(new StreamSource(is), theType);
             } else {
@@ -55,10 +64,8 @@
             }
             
         } catch (JAXBException e) {
-            e.printStackTrace();         
+            throw new WebApplicationException(e);        
         }
-
-        return null;
     }
 
     
@@ -72,11 +79,13 @@
                 genericType = actualClass;
             }
             Marshaller ms = createMarshaller(actualObject, actualClass, genericType, m);
+            if (jaxbSchemaLocation != null) {
+                ms.setProperty(Marshaller.JAXB_SCHEMA_LOCATION, jaxbSchemaLocation);
+            }
             ms.marshal(actualObject, os);
             
         } catch (JAXBException e) {
-            //TODO: better exception handling
-            e.printStackTrace();
+            throw new WebApplicationException(e);
         }
     }
 

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JSONProvider.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JSONProvider.java?rev=703513&r1=703512&r2=703513&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JSONProvider.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JSONProvider.java
Fri Oct 10 09:16:03 2008
@@ -26,10 +26,12 @@
 import java.lang.annotation.Annotation;
 import java.lang.reflect.Type;
 import java.util.HashMap;
+import java.util.List;
 import java.util.Map;
 
 import javax.ws.rs.ConsumeMime;
 import javax.ws.rs.ProduceMime;
+import javax.ws.rs.WebApplicationException;
 import javax.ws.rs.core.MediaType;
 import javax.ws.rs.core.MultivaluedMap;
 import javax.ws.rs.ext.Provider;
@@ -53,6 +55,10 @@
     
     private Map<String, String> namespaceMap = new HashMap<String, String>();
     
+    public void setSchemas(List<String> locations) {
+        super.setSchemas(locations);
+    }
+    
     public void setNamespaceMap(Map<String, String> namespaceMap) {
         this.namespaceMap = namespaceMap;
     }
@@ -77,12 +83,10 @@
             return response;
             
         } catch (JAXBException e) {
-            e.printStackTrace();         
+            throw new WebApplicationException(e);         
         } catch (XMLStreamException e) {
-            e.printStackTrace();
+            throw new WebApplicationException(e);
         } 
-
-        return null;
     }
 
     public void writeTo(Object obj, Class<?> cls, Type genericType, Annotation[] anns,
 
@@ -103,9 +107,9 @@
             xsw.close();
             
         } catch (JAXBException e) {
-            e.printStackTrace();
+            throw new WebApplicationException(e);
         } catch (XMLStreamException e) {
-            e.printStackTrace();
+            throw new WebApplicationException(e);
         }
     }
 

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=703513&r1=703512&r2=703513&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 Oct 10 09:16:03 2008
@@ -20,6 +20,7 @@
 package org.apache.cxf.jaxrs.provider;
 
 import java.lang.annotation.Annotation;
+import java.lang.reflect.Method;
 import java.lang.reflect.ParameterizedType;
 import java.lang.reflect.Type;
 import java.util.ArrayList;
@@ -529,4 +530,22 @@
         requestHandlers.clear();
         responseHandlers.clear();
     }
+    
+    public void setSchemaLocations(List<String> schemas) {
+        setSchemasOnProviders(userMessageReaders, schemas);
+        setSchemasOnProviders(defaultMessageReaders, schemas);
+    }
+    
+    private void setSchemasOnProviders(List<ProviderInfo<MessageBodyReader>>
providers,
+                                       List<String> schemas) {
+        for (ProviderInfo<MessageBodyReader> r : providers) {
+            try {
+                Method m = r.getProvider().getClass().getMethod("setSchemas", 
+                                                     new Class[]{List.class});
+                m.invoke(r.getProvider(), new Object[]{schemas});
+            } catch (Exception ex) {
+                // ignore
+            }
+        }
+    }
 }

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/SourceProvider.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/SourceProvider.java?rev=703513&r1=703512&r2=703513&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/SourceProvider.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/SourceProvider.java
Fri Oct 10 09:16:03 2008
@@ -25,6 +25,7 @@
 import java.lang.annotation.Annotation;
 import java.lang.reflect.Type;
 
+import javax.ws.rs.WebApplicationException;
 import javax.ws.rs.core.MediaType;
 import javax.ws.rs.core.MultivaluedMap;
 import javax.ws.rs.ext.MessageBodyReader;
@@ -89,6 +90,7 @@
             t.transform(source, result);
         } catch (TransformerException te) {
             te.printStackTrace();
+            throw new WebApplicationException(te);
         }
     }
     

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/StringProvider.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/StringProvider.java?rev=703513&r1=703512&r2=703513&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/StringProvider.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/StringProvider.java
Fri Oct 10 09:16:03 2008
@@ -53,21 +53,12 @@
     public String readFrom(Class<String> clazz, Type genericType, Annotation[] annotations,
MediaType m, 
         MultivaluedMap<String, String> headers, InputStream is) 
         throws IOException  {
-        try {
-            return IOUtils.toString(is);
-        } catch (IOException e) {
-            // TODO: better exception handling
-        }
-        return null;
+        return IOUtils.toString(is);
     }
 
     public void writeTo(String obj, Class<?> clazz, Type genericType, Annotation[]
annotations,  
         MediaType m, MultivaluedMap<String, Object> headers, OutputStream os) throws
IOException {
-        try {
-            os.write(obj.getBytes());
-        } catch (IOException e) {
-            //TODO: better exception handling
-        }
+        os.write(obj.getBytes());
     }
 
 }

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/resources/schemas/jaxrs.xsd
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/resources/schemas/jaxrs.xsd?rev=703513&r1=703512&r2=703513&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/resources/schemas/jaxrs.xsd (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/resources/schemas/jaxrs.xsd Fri Oct 10 09:16:03 2008
@@ -48,6 +48,7 @@
             <xsd:element name="providers" type="xsd:anyType" minOccurs="0"/>
             <xsd:element name="extensionMappings" type="xsd:anyType" minOccurs="0"/>
             <xsd:element name="languageMappings" type="xsd:anyType" minOccurs="0"/>
+            <xsd:element name="schemaLocations" type="schemasType" minOccurs="0"/>
           </xsd:all>
           <xsd:attributeGroup ref="cxf-beans:beanAttributes"/>
           <xsd:attribute name="address" type="xsd:string" />

Added: cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/JAXBElementProviderTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/JAXBElementProviderTest.java?rev=703513&view=auto
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/JAXBElementProviderTest.java
(added)
+++ cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/JAXBElementProviderTest.java
Fri Oct 10 09:16:03 2008
@@ -0,0 +1,54 @@
+/**
+ * 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.jaxrs.provider;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.xml.validation.Schema;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+
+public class JAXBElementProviderTest extends Assert {
+
+    @Test
+    public void testSetSchemasFromClasspath() {
+        JAXBElementProvider provider = new JAXBElementProvider();
+        List<String> locations = new ArrayList<String>();
+        locations.add("classpath:/test.xsd");
+        provider.setSchemas(locations);
+        Schema s = provider.getSchema();
+        assertNotNull("schema can not be read from classpath", s);
+    }
+    
+    @Test
+    public void testSetSchemasFromDisk() {
+        JAXBElementProvider provider = new JAXBElementProvider();
+        List<String> locations = new ArrayList<String>();
+        String loc = getClass().getClassLoader().getResource("test.xsd").getFile();
+        locations.add(loc);
+        provider.setSchemas(locations);
+        Schema s = provider.getSchema();
+        assertNotNull("schema can not be read from disk", s);
+    }
+    
+}

Propchange: cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/JAXBElementProviderTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/JAXBElementProviderTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Modified: cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/ProviderFactoryTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/ProviderFactoryTest.java?rev=703513&r1=703512&r2=703513&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/ProviderFactoryTest.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/ProviderFactoryTest.java
Fri Oct 10 09:16:03 2008
@@ -25,6 +25,7 @@
 import java.io.OutputStream;
 import java.lang.annotation.Annotation;
 import java.lang.reflect.Type;
+import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
 
@@ -37,6 +38,7 @@
 import javax.ws.rs.ext.MessageBodyWriter;
 import javax.xml.bind.JAXBContext;
 import javax.xml.bind.annotation.XmlRootElement;
+import javax.xml.validation.Schema;
 
 import org.apache.abdera.model.Entry;
 import org.apache.abdera.model.Feed;
@@ -278,4 +280,17 @@
 
     }
     
+    @Test
+    public void testSetSchemasFromClasspath() {
+        JAXBElementProvider provider = new JAXBElementProvider();
+        ProviderFactory pf = ProviderFactory.getInstance();
+        pf.registerUserProvider(provider);
+        
+        List<String> locations = new ArrayList<String>();
+        locations.add("classpath:/test.xsd");
+        pf.setSchemaLocations(locations);
+        Schema s = provider.getSchema();
+        assertNotNull("schema can not be read from classpath", s);
+    }
+    
 }

Added: cxf/trunk/rt/frontend/jaxrs/src/test/resources/test.xsd
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/test/resources/test.xsd?rev=703513&view=auto
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/test/resources/test.xsd (added)
+++ cxf/trunk/rt/frontend/jaxrs/src/test/resources/test.xsd Fri Oct 10 09:16:03 2008
@@ -0,0 +1,35 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!--
+  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.
+-->
+
+<xs:schema
+    targetNamespace="http://cxf.apache.org/jaxrs/test" 
+    xmlns:tns="http://cxf.apache.org/jaxrs/test"
+    xmlns:xs="http://www.w3.org/2001/XMLSchema"
+    elementFormDefault="qualified"
+    attributeFormDefault="unqualified" >
+
+    <xs:element name="test">
+        <xs:complexType>
+           <xs:attribute name="foo" type="xs:boolean"/>
+           <xs:attribute name="bar" type="xs:boolean"/>
+        </xs:complexType>
+    </xs:element>
+    
+</xs:schema>

Propchange: cxf/trunk/rt/frontend/jaxrs/src/test/resources/test.xsd
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cxf/trunk/rt/frontend/jaxrs/src/test/resources/test.xsd
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Propchange: cxf/trunk/rt/frontend/jaxrs/src/test/resources/test.xsd
------------------------------------------------------------------------------
    svn:mime-type = text/xml



Mime
View raw message