cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject svn commit: r808514 - in /cxf/branches/2.2.x-fixes: ./ 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/ja...
Date Thu, 27 Aug 2009 16:54:00 GMT
Author: dkulp
Date: Thu Aug 27 16:53:59 2009
New Revision: 808514

URL: http://svn.apache.org/viewvc?rev=808514&view=rev
Log:
Merged revisions 807181 via svnmerge from 
https://svn.apache.org/repos/asf/cxf/trunk

........
  r807181 | sergeyb | 2009-08-24 08:27:17 -0400 (Mon, 24 Aug 2009) | 1 line
  
  JAXRS : adding more Aegis JSON tests, fixing WADLGenerator to get namespaces from package-info.java
........

Added:
    cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/fortest/jaxb/packageinfo/
      - copied from r807181, cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/fortest/jaxb/packageinfo/
    cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/fortest/jaxb/packageinfo/Book2.java
      - copied unchanged from r807181, cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/fortest/jaxb/packageinfo/Book2.java
    cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/fortest/jaxb/packageinfo/package-info.java
      - copied unchanged from r807181, cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/fortest/jaxb/packageinfo/package-info.java
    cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/AegisElementProviderTest.java
      - copied unchanged from r807181, cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/AegisElementProviderTest.java
Removed:
    cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/AegisProviderTest.java
Modified:
    cxf/branches/2.2.x-fixes/   (props changed)
    cxf/branches/2.2.x-fixes/common/common/src/main/java/org/apache/cxf/jaxb/JAXBUtils.java
    cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/AbstractJAXRSFactoryBean.java
    cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/wadl/WadlGenerator.java
    cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/AbstractJAXBProvider.java
    cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/AegisElementProvider.java
    cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/AegisJSONProvider.java
    cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/DataBindingJSONProvider.java
    cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/DataBindingProvider.java
    cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/ResourceUtils.java
    cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/wadl/BookStore.java
    cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/wadl/WadlGeneratorTest.java
    cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/AegisJSONProviderTest.java
    cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/DataBindingJSONProviderTest.java

Propchange: cxf/branches/2.2.x-fixes/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Thu Aug 27 16:53:59 2009
@@ -1 +1 @@
-/cxf/trunk:782728-782730,783097,783294,783396,784059,784181-784184,784893,784895,785279-785282,785468,785621,785624,785651,785734,785866,786142,786271-786272,786395,786512,786514,786582-786583,786638,786647,786850,787200,787269,787277-787279,787290-787291,787305,787323,787366,787849,788030,788060,788187,788444,788451,788703,788752,788774,788819-788820,789013,789371,789387,789420,789527-789530,789704-789705,789788,789811,789896-789901,790074,790094,790134,790188,790294,790553,790637-790644,790868,791301,791354,791538,791753,791947,792007,792096,792183,792261-792265,792271,792604,792683-792685,792975,792985,793059,793570,794297,794396,794680,794728,794771,794778-794780,794892,795044,795104,795160,795583,795907,796022-796023,796352,796593,796741,796780,796994-796997,797117,797159,797192,797194,797231-797233,797442,797505,797517,797534,797581-797583,797587,797640,797651,797699,797882-797883,798344-798346,798363,798461,798479,798533,798551,798557,798561-798562,798570,798573,79858
 4,798654,798748-798749,798816,798891,798929-798930,799245,799267,799439,799448,799637,799723-799724,799792,800453,800497-800498,801380-801381,801447,801962,802892,803056,803129,803419,803460,803493,803689,804002,804175,804276,805784,805907,805909,806020-806021,806023,806405-806406,806576,806602-806604,806620,806627,806631,806633,806638,806687,806876,806922,806979-806982
+/cxf/trunk:782728-782730,783097,783294,783396,784059,784181-784184,784893,784895,785279-785282,785468,785621,785624,785651,785734,785866,786142,786271-786272,786395,786512,786514,786582-786583,786638,786647,786850,787200,787269,787277-787279,787290-787291,787305,787323,787366,787849,788030,788060,788187,788444,788451,788703,788752,788774,788819-788820,789013,789371,789387,789420,789527-789530,789704-789705,789788,789811,789896-789901,790074,790094,790134,790188,790294,790553,790637-790644,790868,791301,791354,791538,791753,791947,792007,792096,792183,792261-792265,792271,792604,792683-792685,792975,792985,793059,793570,794297,794396,794680,794728,794771,794778-794780,794892,795044,795104,795160,795583,795907,796022-796023,796352,796593,796741,796780,796994-796997,797117,797159,797192,797194,797231-797233,797442,797505,797517,797534,797581-797583,797587,797640,797651,797699,797882-797883,798344-798346,798363,798461,798479,798533,798551,798557,798561-798562,798570,798573,79858
 4,798654,798748-798749,798816,798891,798929-798930,799245,799267,799439,799448,799637,799723-799724,799792,800453,800497-800498,801380-801381,801447,801962,802892,803056,803129,803419,803460,803493,803689,804002,804175,804276,805784,805907,805909,806020-806021,806023,806405-806406,806576,806602-806604,806620,806627,806631,806633,806638,806687,806876,806922,806979-806982,807181

Propchange: cxf/branches/2.2.x-fixes/
------------------------------------------------------------------------------
Binary property 'svnmerge-integrated' - no diff available.

Modified: cxf/branches/2.2.x-fixes/common/common/src/main/java/org/apache/cxf/jaxb/JAXBUtils.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/common/common/src/main/java/org/apache/cxf/jaxb/JAXBUtils.java?rev=808514&r1=808513&r2=808514&view=diff
==============================================================================
--- cxf/branches/2.2.x-fixes/common/common/src/main/java/org/apache/cxf/jaxb/JAXBUtils.java
(original)
+++ cxf/branches/2.2.x-fixes/common/common/src/main/java/org/apache/cxf/jaxb/JAXBUtils.java
Thu Aug 27 16:53:59 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/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/AbstractJAXRSFactoryBean.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/AbstractJAXRSFactoryBean.java?rev=808514&r1=808513&r2=808514&view=diff
==============================================================================
--- cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/AbstractJAXRSFactoryBean.java
(original)
+++ cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/AbstractJAXRSFactoryBean.java
Thu Aug 27 16:53:59 2009
@@ -19,12 +19,12 @@
 package org.apache.cxf.jaxrs;
 
 import java.lang.reflect.Method;
+import java.lang.reflect.Type;
 import java.util.Arrays;
 import java.util.Collections;
 import java.util.Iterator;
 import java.util.List;
 import java.util.ResourceBundle;
-import java.util.Set;
 import java.util.logging.Logger;
 
 import javax.ws.rs.WebApplicationException;
@@ -251,8 +251,8 @@
         DataBinding db = getDataBinding();
         try {
             Method m = db.getClass().getMethod("setAllClasses", new Class[]{Set.class});
-            Set<Class<?>> allClasses = ResourceUtils.getAllRequestResponseTypes(
-                                                         serviceFactory.getRealClassResourceInfo(),
false);
+            Map<Class<?>, Type> allClasses = ResourceUtils.getAllRequestResponseTypes(
+                                                 serviceFactory.getRealClassResourceInfo(),
false);
             m.invoke(db, new Object[]{allClasses});
         } catch (Exception ex) { 
             db.initialize(s);

Modified: cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/wadl/WadlGenerator.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/wadl/WadlGenerator.java?rev=808514&r1=808513&r2=808514&view=diff
==============================================================================
--- cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/wadl/WadlGenerator.java
(original)
+++ cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/wadl/WadlGenerator.java
Thu Aug 27 16:53:59 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/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/AbstractJAXBProvider.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/AbstractJAXBProvider.java?rev=808514&r1=808513&r2=808514&view=diff
==============================================================================
--- cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/AbstractJAXBProvider.java
(original)
+++ cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/AbstractJAXBProvider.java
Thu Aug 27 16:53:59 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/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/AegisElementProvider.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/AegisElementProvider.java?rev=808514&r1=808513&r2=808514&view=diff
==============================================================================
--- cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/AegisElementProvider.java
(original)
+++ cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/AegisElementProvider.java
Thu Aug 27 16:53:59 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/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/AegisJSONProvider.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/AegisJSONProvider.java?rev=808514&r1=808513&r2=808514&view=diff
==============================================================================
--- cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/AegisJSONProvider.java
(original)
+++ cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/AegisJSONProvider.java
Thu Aug 27 16:53:59 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/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/DataBindingJSONProvider.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/DataBindingJSONProvider.java?rev=808514&r1=808513&r2=808514&view=diff
==============================================================================
--- cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/DataBindingJSONProvider.java
(original)
+++ cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/DataBindingJSONProvider.java
Thu Aug 27 16:53:59 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/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/DataBindingProvider.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/DataBindingProvider.java?rev=808514&r1=808513&r2=808514&view=diff
==============================================================================
--- cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/DataBindingProvider.java
(original)
+++ cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/DataBindingProvider.java
Thu Aug 27 16:53:59 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/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/ResourceUtils.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/ResourceUtils.java?rev=808514&r1=808513&r2=808514&view=diff
==============================================================================
--- cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/ResourceUtils.java
(original)
+++ cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/ResourceUtils.java
Thu Aug 27 16:53:59 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);
         }        
     }
     

Modified: cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/wadl/BookStore.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/wadl/BookStore.java?rev=808514&r1=808513&r2=808514&view=diff
==============================================================================
--- cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/wadl/BookStore.java
(original)
+++ cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/wadl/BookStore.java
Thu Aug 27 16:53:59 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/branches/2.2.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/wadl/WadlGeneratorTest.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/wadl/WadlGeneratorTest.java?rev=808514&r1=808513&r2=808514&view=diff
==============================================================================
--- cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/wadl/WadlGeneratorTest.java
(original)
+++ cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/wadl/WadlGeneratorTest.java
Thu Aug 27 16:53:59 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"));

Modified: cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/AegisJSONProviderTest.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/AegisJSONProviderTest.java?rev=808514&r1=808513&r2=808514&view=diff
==============================================================================
--- cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/AegisJSONProviderTest.java
(original)
+++ cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/AegisJSONProviderTest.java
Thu Aug 27 16:53:59 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/branches/2.2.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/DataBindingJSONProviderTest.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/DataBindingJSONProviderTest.java?rev=808514&r1=808513&r2=808514&view=diff
==============================================================================
--- cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/DataBindingJSONProviderTest.java
(original)
+++ cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/DataBindingJSONProviderTest.java
Thu Aug 27 16:53:59 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.POST;
 import javax.ws.rs.Path;
@@ -103,6 +105,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