cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r807181 - in /cxf/trunk: common/common/src/main/java/org/apache/cxf/jaxb/ rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/wadl/ rt/frontend/jaxrs/src/main/java/org/apache/cxf/...
Date Mon, 24 Aug 2009 12:27:19 GMT
Author: sergeyb
Date: Mon Aug 24 12:27:17 2009
New Revision: 807181

URL: http://svn.apache.org/viewvc?rev=807181&view=rev
Log:
JAXRS : adding more Aegis JSON tests, fixing WADLGenerator to get namespaces from package-info.java

Added:
    cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/fortest/jaxb/packageinfo/
    cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/fortest/jaxb/packageinfo/Book2.java
  (with props)
    cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/fortest/jaxb/packageinfo/package-info.java
  (with props)
    cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/AegisElementProviderTest.java
  (with props)
Removed:
    cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/AegisProviderTest.java
Modified:
    cxf/trunk/common/common/src/main/java/org/apache/cxf/jaxb/JAXBUtils.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/AbstractJAXRSFactoryBean.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/wadl/WadlGenerator.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/AegisElementProvider.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/AegisJSONProvider.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/DataBindingJSONProvider.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/DataBindingProvider.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/ResourceUtils.java
    cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/wadl/BookStore.java
    cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/wadl/WadlGeneratorTest.java
    cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/AegisJSONProviderTest.java
    cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/DataBindingJSONProviderTest.java

Modified: cxf/trunk/common/common/src/main/java/org/apache/cxf/jaxb/JAXBUtils.java
URL: http://svn.apache.org/viewvc/cxf/trunk/common/common/src/main/java/org/apache/cxf/jaxb/JAXBUtils.java?rev=807181&r1=807180&r2=807181&view=diff
==============================================================================
--- cxf/trunk/common/common/src/main/java/org/apache/cxf/jaxb/JAXBUtils.java (original)
+++ cxf/trunk/common/common/src/main/java/org/apache/cxf/jaxb/JAXBUtils.java Mon Aug 24 12:27:17
2009
@@ -682,6 +682,18 @@
         return results;
     }
     
+    public static String getPackageNamespace(Class<?> cls) {
+        Package p = Package.getPackage(PackageUtils.getPackageName(cls));
+        if (p != null) {
+            javax.xml.bind.annotation.XmlSchema schemaAnn = 
+                p.getAnnotation(javax.xml.bind.annotation.XmlSchema.class);
+            if (schemaAnn != null) {
+                return schemaAnn.namespace();
+            }
+        }
+        return null;
+    }
+    
     public static void scanPackages(Set<Class<?>> classes, 
                                     Map<Package, CachedClass> objectFactoryCache) {
         // try and read any jaxb.index files that are with the other classes.

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/AbstractJAXRSFactoryBean.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/AbstractJAXRSFactoryBean.java?rev=807181&r1=807180&r2=807181&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/AbstractJAXRSFactoryBean.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/AbstractJAXRSFactoryBean.java
Mon Aug 24 12:27:17 2009
@@ -18,6 +18,7 @@
  */
 package org.apache.cxf.jaxrs;
 
+import java.lang.reflect.Type;
 import java.util.Arrays;
 import java.util.Collections;
 import java.util.HashMap;
@@ -25,7 +26,6 @@
 import java.util.List;
 import java.util.Map;
 import java.util.ResourceBundle;
-import java.util.Set;
 import java.util.logging.Logger;
 
 import javax.ws.rs.WebApplicationException;
@@ -252,8 +252,8 @@
     protected void setDataBindingProvider(ProviderFactory factory, Service s) {
         DataBinding db = getDataBinding();
         if (db instanceof PropertiesAwareDataBinding) {
-            Set<Class<?>> allClasses = ResourceUtils.getAllRequestResponseTypes(
-                                                         serviceFactory.getRealClassResourceInfo(),
false);
+            Map<Class<?>, Type> allClasses = ResourceUtils.getAllRequestResponseTypes(
+                                                 serviceFactory.getRealClassResourceInfo(),
false);
             Map<String, Object> props = new HashMap<String, Object>();
             props.put(PropertiesAwareDataBinding.TYPES_PROPERTY, allClasses);
             ((PropertiesAwareDataBinding)db).initialize(props);

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/wadl/WadlGenerator.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/wadl/WadlGenerator.java?rev=807181&r1=807180&r2=807181&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/wadl/WadlGenerator.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/wadl/WadlGenerator.java
Mon Aug 24 12:27:17 2009
@@ -109,7 +109,7 @@
         
         List<ClassResourceInfo> cris = getResourcesList(m, resource);
         
-        Set<Class<?>> jaxbTypes = ResourceUtils.getAllRequestResponseTypes(cris,
true);
+        Set<Class<?>> jaxbTypes = ResourceUtils.getAllRequestResponseTypes(cris,
true).keySet();
         JAXBContext context = createJaxbContext(jaxbTypes);
         SchemaCollection coll = getSchemaCollection(context);
         JAXBContextProxy proxy = null;
@@ -438,7 +438,16 @@
         
         XmlRootElement root = type.getAnnotation(XmlRootElement.class);
         if (root != null) {
-            return getQNameFromParts(root.name(), root.namespace(), clsMap);
+            QName qname = getQNameFromParts(root.name(), root.namespace(), clsMap);
+            if (qname != null) {
+                return qname;
+            }
+            String ns = JAXBUtils.getPackageNamespace(type);
+            if (ns != null) {
+                return getQNameFromParts(root.name(), ns, clsMap);
+            } else {
+                return null;
+            }
         }
         
         try {

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=807181&r1=807180&r2=807181&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
Mon Aug 24 12:27:17 2009
@@ -213,6 +213,12 @@
         QName qname = null;
         if (root != null) {
             String namespace = getNamespace(root.namespace());
+            if ("".equals(namespace)) {
+                String packageNs = JAXBUtils.getPackageNamespace(cls);
+                if (packageNs != null) {
+                    namespace = getNamespace(packageNs);
+                }
+            }
             String name = getLocalName(root.name(), cls.getSimpleName(), pluralName);
             return new QName(namespace, name);
         } else {

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/AegisElementProvider.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/AegisElementProvider.java?rev=807181&r1=807180&r2=807181&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/AegisElementProvider.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/AegisElementProvider.java
Mon Aug 24 12:27:17 2009
@@ -53,14 +53,15 @@
         AegisContext context = getAegisContext(type, genericType);
         AegisReader<XMLStreamReader> aegisReader = context.createXMLStreamReader();
         try {
-            XMLStreamReader xmlStreamReader = createStreamReader(type, is);
+            XMLStreamReader xmlStreamReader = createStreamReader(type, genericType, is);
             return aegisReader.read(xmlStreamReader);
         } catch (Exception e) {
             throw new WebApplicationException(e);
         }
     }
 
-    protected XMLStreamReader createStreamReader(Class<?> type, InputStream is) throws
Exception {
+    protected XMLStreamReader createStreamReader(Class<?> type, Type genericType, InputStream
is) 
+        throws Exception {
         return StaxUtils.createXMLStreamReader(is);
     }
     

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/AegisJSONProvider.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/AegisJSONProvider.java?rev=807181&r1=807180&r2=807181&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/AegisJSONProvider.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/AegisJSONProvider.java
Mon Aug 24 12:27:17 2009
@@ -36,6 +36,7 @@
 import javax.xml.stream.XMLStreamReader;
 import javax.xml.stream.XMLStreamWriter;
 
+import org.apache.cxf.jaxrs.utils.InjectionUtils;
 import org.apache.cxf.jaxrs.utils.JAXRSUtils;
 
 @Provider
@@ -76,8 +77,13 @@
     }
     
     @Override
-    protected XMLStreamReader createStreamReader(Class<?> type, InputStream is) throws
Exception {
-        getQName(type);
+    protected XMLStreamReader createStreamReader(Class<?> type,  Type genericType,
InputStream is) 
+        throws Exception {
+        if (!InjectionUtils.isSupportedCollectionOrArray(type) && !Map.class.isAssignableFrom(type))
{
+            getQName(type);
+        } else {
+            getQName(InjectionUtils.getActualType(genericType));
+        }
         return JSONUtils.createStreamReader(is, readXsiType, namespaceMap);
     }
     
@@ -86,4 +92,5 @@
         namespaceMap.putIfAbsent(qname.getNamespaceURI(), "ns1");
         return qname;
     }
+    
 }

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/DataBindingJSONProvider.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/DataBindingJSONProvider.java?rev=807181&r1=807180&r2=807181&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/DataBindingJSONProvider.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/DataBindingJSONProvider.java
Mon Aug 24 12:27:17 2009
@@ -34,6 +34,7 @@
 import javax.xml.stream.XMLStreamReader;
 import javax.xml.stream.XMLStreamWriter;
 
+import org.apache.cxf.jaxrs.utils.InjectionUtils;
 import org.apache.cxf.jaxrs.utils.JAXRSUtils;
 
 @Provider
@@ -73,8 +74,14 @@
     }
     
     @Override
-    protected XMLStreamWriter createWriter(Class<?> type, OutputStream os) throws Exception
{
-        QName qname = getQName(type);
+    protected XMLStreamWriter createWriter(Class<?> type, Type genericType, OutputStream
os) 
+        throws Exception {
+        QName qname = null;
+        if (!InjectionUtils.isSupportedCollectionOrArray(type)) {
+            qname = getQName(type);
+        } else {
+            qname = getQName(InjectionUtils.getActualType(genericType));
+        }
         return JSONUtils.createStreamWriter(os, qname, writeXsiType, namespaceMap, 
                                             serializeAsArray, arrayKeys);
     }
@@ -87,8 +94,13 @@
     }
     
     @Override
-    protected XMLStreamReader createReader(Class<?> type, InputStream is) throws Exception
{
-        getQName(type);
+    protected XMLStreamReader createReader(Class<?> type, Type genericType, InputStream
is) 
+        throws Exception {
+        if (!InjectionUtils.isSupportedCollectionOrArray(type)) {
+            getQName(type);
+        } else {
+            getQName(InjectionUtils.getActualType(genericType));
+        }
         return JSONUtils.createStreamReader(is, readXsiType, namespaceMap);
     }
     

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/DataBindingProvider.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/DataBindingProvider.java?rev=807181&r1=807180&r2=807181&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/DataBindingProvider.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/DataBindingProvider.java
Mon Aug 24 12:27:17 2009
@@ -66,7 +66,7 @@
                        MultivaluedMap<String, String> headers, InputStream is)
         throws IOException {
         try {
-            XMLStreamReader reader = createReader(clazz, is);
+            XMLStreamReader reader = createReader(clazz, genericType, is);
             DataReader<XMLStreamReader> dataReader = binding.createReader(XMLStreamReader.class);
             return dataReader.read(null, reader, clazz);
         } catch (Exception ex) {
@@ -74,7 +74,8 @@
         }
     }
 
-    protected XMLStreamReader createReader(Class<?> clazz, InputStream is) throws Exception
{
+    protected XMLStreamReader createReader(Class<?> clazz, Type genericType, InputStream
is) 
+        throws Exception {
         return StaxUtils.createXMLStreamReader(is);
     }
     
@@ -93,7 +94,7 @@
                         MediaType type, MultivaluedMap<String, Object> headers, OutputStream
os)
         throws IOException {
         try {
-            XMLStreamWriter writer = createWriter(clazz, os);
+            XMLStreamWriter writer = createWriter(clazz, genericType, os);
             writeToWriter(writer, o);
         } catch (Exception ex) {
             throw new WebApplicationException(ex);
@@ -106,7 +107,8 @@
         writer.flush();
     }
     
-    protected XMLStreamWriter createWriter(Class<?> clazz, OutputStream os) throws
Exception {
+    protected XMLStreamWriter createWriter(Class<?> clazz, Type genericType, OutputStream
os) 
+        throws Exception {
         return StaxUtils.createXMLStreamWriter(os);
     }
 }

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=807181&r1=807180&r2=807181&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
Mon Aug 24 12:27:17 2009
@@ -26,15 +26,15 @@
 import java.lang.annotation.Annotation;
 import java.lang.reflect.Constructor;
 import java.lang.reflect.Method;
+import java.lang.reflect.Type;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.Comparator;
-import java.util.HashSet;
+import java.util.HashMap;
 import java.util.LinkedList;
 import java.util.List;
 import java.util.Map;
 import java.util.ResourceBundle;
-import java.util.Set;
 import java.util.logging.Logger;
 
 import javax.ws.rs.CookieParam;
@@ -397,22 +397,26 @@
     }
     
 
-    public static Set<Class<?>> getAllRequestResponseTypes(List<ClassResourceInfo>
cris, boolean jaxbOnly) {
-        Set<Class<?>> types = new HashSet<Class<?>>();
+    public static Map<Class<?>, Type> getAllRequestResponseTypes(List<ClassResourceInfo>
cris, 
+                                                                 boolean jaxbOnly) {
+        Map<Class<?>, Type> types = new HashMap<Class<?>, Type>();
         for (ClassResourceInfo root : cris) {
             for (OperationResourceInfo ori : root.getMethodDispatcher().getOperationResourceInfos())
{
+                Class<?> cls = ori.getMethodToInvoke().getReturnType();
+                Type type = ori.getMethodToInvoke().getGenericReturnType();
                 if (jaxbOnly) {
-                    checkJaxbType(ori.getMethodToInvoke().getReturnType(), types);
+                    checkJaxbType(cls, types);
                 } else {
-                    types.add(ori.getMethodToInvoke().getReturnType());
+                    types.put(cls, type);
                 }
                 for (Parameter pm : ori.getParameters()) {
                     if (pm.getType() == ParameterType.REQUEST_BODY) {
                         Class<?> inType = ori.getMethodToInvoke().getParameterTypes()[pm.getIndex()];
+                        Type type2 = ori.getMethodToInvoke().getGenericParameterTypes()[pm.getIndex()];
                         if (jaxbOnly) {
                             checkJaxbType(inType, types);
                         } else {
-                            types.add(inType);
+                            types.put(inType, type2);
                         }
                     }
                 }
@@ -423,12 +427,12 @@
         return types;
     }
 
-    private static void checkJaxbType(Class<?> type, Set<Class<?>> types)
{
+    private static void checkJaxbType(Class<?> type, Map<Class<?>, Type>
types) {
         JAXBElementProvider provider = new JAXBElementProvider();
         if (!InjectionUtils.isPrimitive(type) 
             && !JAXBElement.class.isAssignableFrom(type)
             && provider.isReadable(type, type, new Annotation[0], MediaType.APPLICATION_XML_TYPE))
{
-            types.add(type);
+            types.put(type, type);
         }        
     }
     

Added: cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/fortest/jaxb/packageinfo/Book2.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/fortest/jaxb/packageinfo/Book2.java?rev=807181&view=auto
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/fortest/jaxb/packageinfo/Book2.java
(added)
+++ cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/fortest/jaxb/packageinfo/Book2.java
Mon Aug 24 12:27:17 2009
@@ -0,0 +1,42 @@
+/**
+ * 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.fortest.jaxb.packageinfo;
+
+import javax.xml.bind.annotation.XmlRootElement;
+
+@XmlRootElement(name = "thebook2")
+public class Book2 {
+
+    private int id;
+    
+    public Book2() {
+    }
+    
+    public Book2(int id) {
+        this.id = id;
+    }
+    
+    public int getId() {
+        return id;
+    }
+    
+    public void setId(int ident) {
+        id = ident;
+    }
+}

Propchange: cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/fortest/jaxb/packageinfo/Book2.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/fortest/jaxb/packageinfo/Book2.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/fortest/jaxb/packageinfo/package-info.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/fortest/jaxb/packageinfo/package-info.java?rev=807181&view=auto
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/fortest/jaxb/packageinfo/package-info.java
(added)
+++ cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/fortest/jaxb/packageinfo/package-info.java
Mon Aug 24 12:27:17 2009
@@ -0,0 +1,21 @@
+/**
+ * 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.
+ */
+@javax.xml.bind.annotation.XmlSchema(namespace = "http://superbooks")
+package org.apache.cxf.jaxrs.fortest.jaxb.packageinfo;
+

Propchange: cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/fortest/jaxb/packageinfo/package-info.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/fortest/jaxb/packageinfo/package-info.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Modified: cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/wadl/BookStore.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/wadl/BookStore.java?rev=807181&r1=807180&r2=807181&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/wadl/BookStore.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/wadl/BookStore.java
Mon Aug 24 12:27:17 2009
@@ -31,6 +31,8 @@
 import javax.ws.rs.core.Context;
 import javax.ws.rs.core.HttpHeaders;
 
+import org.apache.cxf.jaxrs.fortest.jaxb.packageinfo.Book2;
+
 @Path("/bookstore/{id}")
 @Consumes({"application/xml", "application/json" })
 @Produces({"application/xml", "application/json" })
@@ -70,6 +72,12 @@
         return this;
     }
     
+    @Path("book2")
+    @GET
+    public Book2 getBook2() {
+        return new Book2();
+    }
+    
     public static class QueryBean {
         private int a;
         private int b;

Modified: cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/wadl/WadlGeneratorTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/wadl/WadlGeneratorTest.java?rev=807181&r1=807180&r2=807181&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/wadl/WadlGeneratorTest.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/wadl/WadlGeneratorTest.java
Mon Aug 24 12:27:17 2009
@@ -18,6 +18,8 @@
  */
 package org.apache.cxf.jaxrs.model.wadl;
 
+import java.io.File;
+import java.io.FileOutputStream;
 import java.io.StringReader;
 import java.util.ArrayList;
 import java.util.List;
@@ -82,14 +84,14 @@
         assertNotNull(r);
         assertEquals(WadlGenerator.WADL_TYPE.toString(),
                      r.getMetadata().getFirst(HttpHeaders.CONTENT_TYPE));
-//        File f = new File("test.xml");
-//        f.delete();
-//        f.createNewFile();
-//        System.out.println(f.getAbsolutePath());
-//        FileOutputStream fos = new FileOutputStream(f);
-//        fos.write(r.getEntity().toString().getBytes());
-//        fos.flush();
-//        fos.close();
+        File f = new File("test.xml");
+        f.delete();
+        f.createNewFile();
+        System.out.println(f.getAbsolutePath());
+        FileOutputStream fos = new FileOutputStream(f);
+        fos.write(r.getEntity().toString().getBytes());
+        fos.flush();
+        fos.close();
     }
     
     @Test
@@ -121,9 +123,9 @@
                                                           XmlSchemaConstants.XSD_NAMESPACE_URI,
"schema");
         assertEquals(1, schemasEls.size());
         assertEquals("http://superbooks", schemasEls.get(0).getAttribute("targetNamespace"));
-        assertEquals(2, DOMUtils.getChildrenWithName(schemasEls.get(0), 
+        assertEquals(3, DOMUtils.getChildrenWithName(schemasEls.get(0), 
                        XmlSchemaConstants.XSD_NAMESPACE_URI, "element").size());
-        assertEquals(2, DOMUtils.getChildrenWithName(schemasEls.get(0), 
+        assertEquals(3, DOMUtils.getChildrenWithName(schemasEls.get(0), 
                        XmlSchemaConstants.XSD_NAMESPACE_URI, "complexType").size());
     }
     
@@ -132,12 +134,13 @@
         
         List<Element> resourceEls = DOMUtils.getChildrenWithName(resource, 
                                          WadlGenerator.WADL_NS, "resource");
-        assertEquals(5, resourceEls.size());        
+        assertEquals(6, resourceEls.size());        
         assertEquals("/", resourceEls.get(0).getAttribute("path"));
-        assertEquals("/books/{bookid}", resourceEls.get(1).getAttribute("path"));
-        assertEquals("/chapter", resourceEls.get(2).getAttribute("path"));
-        assertEquals("/booksubresource", resourceEls.get(3).getAttribute("path"));
-        assertEquals("/itself", resourceEls.get(4).getAttribute("path"));
+        assertEquals("/book2", resourceEls.get(1).getAttribute("path"));
+        assertEquals("/books/{bookid}", resourceEls.get(2).getAttribute("path"));
+        assertEquals("/chapter", resourceEls.get(3).getAttribute("path"));
+        assertEquals("/booksubresource", resourceEls.get(4).getAttribute("path"));
+        assertEquals("/itself", resourceEls.get(5).getAttribute("path"));
         
         
         List<Element> methodEls = DOMUtils.getChildrenWithName(resourceEls.get(0),

@@ -161,14 +164,14 @@
         checkParameter(paramsEls.get(0), "a", "query");
         checkParameter(paramsEls.get(1), "b", "query");
         
-        paramsEls = DOMUtils.getChildrenWithName(resourceEls.get(1), 
+        paramsEls = DOMUtils.getChildrenWithName(resourceEls.get(2), 
                                                                WadlGenerator.WADL_NS, "param");
         assertEquals(3, paramsEls.size());
         checkParameter(paramsEls.get(0), "id", "template");
         checkParameter(paramsEls.get(1), "bookid", "template");
         checkParameter(paramsEls.get(2), "mid", "matrix");
         
-        methodEls = DOMUtils.getChildrenWithName(resourceEls.get(1), 
+        methodEls = DOMUtils.getChildrenWithName(resourceEls.get(2), 
                                                  WadlGenerator.WADL_NS, "method");
         assertEquals(1, methodEls.size());
         assertEquals("POST", methodEls.get(0).getAttribute("name"));

Added: cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/AegisElementProviderTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/AegisElementProviderTest.java?rev=807181&view=auto
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/AegisElementProviderTest.java
(added)
+++ cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/AegisElementProviderTest.java
Mon Aug 24 12:27:17 2009
@@ -0,0 +1,141 @@
+/**
+ * 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.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.lang.reflect.Method;
+import java.lang.reflect.Type;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.ws.rs.ext.MessageBodyReader;
+import javax.ws.rs.ext.MessageBodyWriter;
+
+import org.apache.cxf.jaxrs.fortest.AegisTestBean;
+
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Test;
+
+public class AegisElementProviderTest extends Assert {
+    
+    private static final String SIMPLE_BEAN_XML 
+        = "<?xml version='1.0' encoding='UTF-8'?>" 
+           + "<ns1:AegisTestBean xmlns:ns1=\"http://fortest.jaxrs.cxf.apache.org\""
+           + " xmlns:ns2=\"http://www.w3.org/2001/XMLSchema-instance\""
+           + " ns2:type=\"ns1:AegisTestBean\">"
+           + "<ns1:boolValue>true</ns1:boolValue><ns1:strValue>hovercraft</ns1:strValue></ns1:AegisTestBean>";
+
+    @After
+    public void clearCache() {
+        AbstractAegisProvider.clearContexts();
+    }
+    
+    @Test
+    public void testIsWriteable() {
+        MessageBodyWriter<Object> p = new AegisElementProvider();
+        assertTrue(p.isWriteable(AegisTestBean.class, null, null, null));
+    }
+    
+    @Test
+    public void testIsReadable() {
+        MessageBodyReader<Object> p = new AegisElementProvider();
+        assertTrue(p.isReadable(AegisTestBean.class, null, null, null));
+    }
+    
+    
+    @SuppressWarnings("unchecked")
+    @Test
+    public void testReadFrom() throws Exception {
+        MessageBodyReader<Object> p = new AegisElementProvider();
+        byte[] simpleBytes = SIMPLE_BEAN_XML.getBytes("utf-8");
+        Object beanObject = p.readFrom((Class)AegisTestBean.class, null, null, 
+                                          null, null, new ByteArrayInputStream(simpleBytes));
+        AegisTestBean bean = (AegisTestBean) beanObject;
+        assertEquals("hovercraft", bean.getStrValue());
+        assertEquals(Boolean.TRUE, bean.getBoolValue());
+    }
+    
+    @Test
+    public void testWriteTo() throws Exception {
+        MessageBodyWriter<Object> p = new AegisElementProvider();
+        ByteArrayOutputStream os = new ByteArrayOutputStream();
+        AegisTestBean bean = new AegisTestBean();
+        bean.setBoolValue(Boolean.TRUE);
+        bean.setStrValue("hovercraft");
+        p.writeTo(bean, null, null, null, null, null, os);
+        byte[] bytes = os.toByteArray();
+        String xml = new String(bytes, "utf-8");
+        assertEquals(SIMPLE_BEAN_XML, xml);
+    }
+    
+    
+    @SuppressWarnings("unchecked")
+    @Test
+    public void testReadWriteComplexMap() throws Exception {
+        Map<AegisTestBean, AegisSuperBean> testMap = 
+            new HashMap<AegisTestBean, AegisSuperBean>();
+        
+        Class<InterfaceWithMap> iwithMapClass = InterfaceWithMap.class;
+        Method method = iwithMapClass.getMethod("mapFunction");
+        Type mapType = method.getGenericReturnType();
+
+        AegisTestBean bean = new AegisTestBean();
+        bean.setBoolValue(Boolean.TRUE);
+        bean.setStrValue("hovercraft");
+        
+        AegisSuperBean bean2 = new AegisSuperBean();
+        bean2.setBoolValue(Boolean.TRUE);
+        bean2.setStrValue("hovercraft2");
+        testMap.put(bean, bean2);
+        
+        MessageBodyWriter<Object> writer = new AegisElementProvider();
+        ByteArrayOutputStream os = new ByteArrayOutputStream();
+        
+        writer.writeTo(testMap, testMap.getClass(), mapType, null, null, null, os);
+        byte[] bytes = os.toByteArray();
+        String xml = new String(bytes, "utf-8");
+        System.out.println(xml);        
+        MessageBodyReader<Object> reader = new AegisElementProvider();         
+        byte[] simpleBytes = xml.getBytes("utf-8");
+        
+        Object beanObject = reader.readFrom((Class)Map.class, mapType, null, 
+                                          null, null, new ByteArrayInputStream(simpleBytes));
+        Map<AegisTestBean, AegisSuperBean> map2 = (Map)beanObject;
+        assertEquals(1, map2.size());
+        Map.Entry<AegisTestBean, AegisSuperBean> entry = map2.entrySet().iterator().next();
+        AegisTestBean bean1 = entry.getKey();
+        assertEquals("hovercraft", bean1.getStrValue());
+        assertEquals(Boolean.TRUE, bean1.getBoolValue());
+        AegisTestBean bean22 = entry.getValue();
+        assertEquals("hovercraft2", bean22.getStrValue());
+        assertEquals(Boolean.TRUE, bean22.getBoolValue());
+        
+    }
+    
+    public static class AegisSuperBean extends AegisTestBean {
+    }
+    
+    private static interface InterfaceWithMap {
+        Map<AegisTestBean, AegisSuperBean> mapFunction();
+    }
+    
+}

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

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

Modified: cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/AegisJSONProviderTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/AegisJSONProviderTest.java?rev=807181&r1=807180&r2=807181&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/AegisJSONProviderTest.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/AegisJSONProviderTest.java
Mon Aug 24 12:27:17 2009
@@ -22,6 +22,7 @@
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
 import java.lang.reflect.Method;
+import java.lang.reflect.Type;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
@@ -134,8 +135,14 @@
     
     @Test
     public void testWriteCollection() throws Exception {
+        String json = writeCollection();
+        assertEquals("{\"ns1.ArrayOfAegisTestBean\":{\"@xsi.type\":\"ns1:ArrayOfAegisTestBean\","
+            + "\"ns1.AegisTestBean\":{\"@xsi.type\":\"ns1:AegisTestBean\",\"ns1.boolValue\":true,"
+            + "\"ns1.strValue\":\"hovercraft\"}}}", json);
+    }
+    
+    private String writeCollection() throws Exception {
         AegisJSONProvider p = new AegisJSONProvider();
-        p.setWriteXsiType(false);
         AbstractAegisProvider.clearContexts();
         ByteArrayOutputStream os = new ByteArrayOutputStream();
         AegisTestBean bean = new AegisTestBean();
@@ -147,9 +154,24 @@
         p.writeTo(beans, (Class)m.getReturnType(), m.getGenericReturnType(), AegisTestBean.class
             .getAnnotations(), MediaType.APPLICATION_JSON_TYPE, new MetadataMap<String,
Object>(), os);
         byte[] bytes = os.toByteArray();
-        String json = new String(bytes, "utf-8");
-        assertEquals("{\"ns1.ArrayOfAegisTestBean\":{\"ns1.AegisTestBean\":"
-                     + "{\"ns1.boolValue\":true,\"ns1.strValue\":\"hovercraft\"}}}", json);
+        return new String(bytes, "utf-8");
+    }
+    
+    
+    @SuppressWarnings("unchecked")
+    @Test
+    public void testReadCollection() throws Exception {
+        String json = writeCollection();         
+        byte[] simpleBytes = json.getBytes("utf-8");
+        Method m = CollectionsResource.class.getMethod("getAegisBeans", new Class[] {});
       
+        AegisJSONProvider p = new AegisJSONProvider();
+        Object beanObject = p.readFrom((Class)m.getReturnType(), m.getGenericReturnType(),
null, 
+                                          null, null, new ByteArrayInputStream(simpleBytes));
+        List<AegisTestBean> list = (List)beanObject;
+        assertEquals(1, list.size());
+        AegisTestBean bean = list.get(0);
+        assertEquals("hovercraft", bean.getStrValue());
+        assertEquals(Boolean.TRUE, bean.getBoolValue());
     }
     
     @Test
@@ -180,4 +202,69 @@
     private TagVO createTag(String name, String group) {
         return new TagVO(name, group);
     }
+    
+    @SuppressWarnings("unchecked")
+    @Test
+    public void testReadWriteComplexMap() throws Exception {
+        Map<AegisTestBean, AegisSuperBean> testMap = 
+            new HashMap<AegisTestBean, AegisSuperBean>();
+        
+        Class<InterfaceWithMap> iwithMapClass = InterfaceWithMap.class;
+        Method method = iwithMapClass.getMethod("mapFunction");
+        Type mapType = method.getGenericReturnType();
+
+        AegisTestBean bean = new AegisTestBean();
+        bean.setBoolValue(Boolean.TRUE);
+        bean.setStrValue("hovercraft");
+        
+        AegisSuperBean bean2 = new AegisSuperBean();
+        bean2.setBoolValue(Boolean.TRUE);
+        bean2.setStrValue("hovercraft2");
+        testMap.put(bean, bean2);
+        
+        AegisJSONProvider writer = new AegisJSONProvider();
+        Map<String, String> namespaceMap = new HashMap<String, String>();
+        namespaceMap.put("urn:org.apache.cxf.aegis.types", "ns1");
+        namespaceMap.put("http://fortest.jaxrs.cxf.apache.org", "ns2");
+        writer.setNamespaceMap(namespaceMap);
+        
+        
+        ByteArrayOutputStream os = new ByteArrayOutputStream();
+        
+        writer.writeTo(testMap, testMap.getClass(), mapType, null, null, null, os);
+        byte[] bytes = os.toByteArray();
+        String xml = new String(bytes, "utf-8");
+        String expected = "{\"ns1.AegisTestBean2AegisSuperBeanMap\":{\"@xsi.type\":"
+            + "\"ns1:AegisTestBean2AegisSuperBeanMap\",\"ns1.entry\":{\"ns1.key\":{\"@xsi.type\":\"ns1:"
+            + "AegisTestBean\",\"ns2.boolValue\":true,\"ns2.strValue\":\"hovercraft\"},\"ns1.value\":"
+            + "{\"@xsi.type\":\"ns1:AegisSuperBean\",\"ns2.boolValue\":true,"
+            + "\"ns2.strValue\":\"hovercraft2\"}}}}";
+        assertEquals(expected, xml);        
+        AegisJSONProvider reader = new AegisJSONProvider();       
+        Map<String, String> namespaceMap2 = new HashMap<String, String>();
+        namespaceMap2.put("urn:org.apache.cxf.aegis.types", "ns1");
+        namespaceMap2.put("http://fortest.jaxrs.cxf.apache.org", "ns2");
+        reader.setNamespaceMap(namespaceMap2);
+        byte[] simpleBytes = xml.getBytes("utf-8");
+        
+        Object beanObject = reader.readFrom((Class)Map.class, mapType, null, 
+                                          null, null, new ByteArrayInputStream(simpleBytes));
+        Map<AegisTestBean, AegisSuperBean> map2 = (Map)beanObject;
+        assertEquals(1, map2.size());
+        Map.Entry<AegisTestBean, AegisSuperBean> entry = map2.entrySet().iterator().next();
+        AegisTestBean bean1 = entry.getKey();
+        assertEquals("hovercraft", bean1.getStrValue());
+        assertEquals(Boolean.TRUE, bean1.getBoolValue());
+        AegisTestBean bean22 = entry.getValue();
+        assertEquals("hovercraft2", bean22.getStrValue());
+        assertEquals(Boolean.TRUE, bean22.getBoolValue());
+        
+    }
+    
+    public static class AegisSuperBean extends AegisTestBean {
+    }
+    
+    private static interface InterfaceWithMap {
+        Map<AegisTestBean, AegisSuperBean> mapFunction();
+    }
 }

Modified: cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/DataBindingJSONProviderTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/DataBindingJSONProviderTest.java?rev=807181&r1=807180&r2=807181&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/DataBindingJSONProviderTest.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/DataBindingJSONProviderTest.java
Mon Aug 24 12:27:17 2009
@@ -23,7 +23,9 @@
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
 import java.lang.annotation.Annotation;
+import java.util.ArrayList;
 import java.util.Collections;
+import java.util.List;
 
 import javax.ws.rs.GET;
 import javax.ws.rs.POST;
@@ -150,6 +152,26 @@
     }
     
     @Test
+    @Ignore
+    public void testAegisCollectionWrite() throws Exception {
+        Service s = new JAXRSServiceImpl(Collections.singletonList(c));
+        s.put("writeXsiType", true);
+        AegisDatabinding binding = new AegisDatabinding();
+        binding.initialize(s);
+        DataBindingJSONProvider p = new DataBindingJSONProvider();
+        p.setDataBinding(binding);
+        
+        Book b = new Book("CXF", 127L);
+        List<Book> books = new ArrayList<Book>();
+        books.add(b);
+        ByteArrayOutputStream bos = new ByteArrayOutputStream();
+        p.writeTo(books, List.class, Book.class,
+            new Annotation[0], MediaType.APPLICATION_JSON_TYPE, new MetadataMap<String,
Object>(), bos);
+        
+        System.out.println(bos.toString());         
+    }
+    
+    @Test
     public void testAegisRead() throws Exception {
         String data = "{\"ns1.Book\":{\"@xsi.type\":\"ns1:Book\",\"ns1.id\":127,"
             + "\"ns1.name\":\"CXF\",\"ns1.state\":\"\"}}";



Mime
View raw message