cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r797541 - in /cxf/branches/2.2.x-fixes: ./ rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/ rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/
Date Fri, 24 Jul 2009 15:42:57 GMT
Author: sergeyb
Date: Fri Jul 24 15:42:56 2009
New Revision: 797541

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

........
  r797534 | sergeyb | 2009-07-24 16:33:57 +0100 (Fri, 24 Jul 2009) | 1 line
  
  JAXRS : fixing Aegis JSON reads
........

Modified:
    cxf/branches/2.2.x-fixes/   (props changed)
    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/utils/JAXRSUtils.java
    cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/AegisJSONProviderTest.java

Propchange: cxf/branches/2.2.x-fixes/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Fri Jul 24 15:42:56 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
+/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

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

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=797541&r1=797540&r2=797541&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
Fri Jul 24 15:42:56 2009
@@ -25,6 +25,8 @@
 import java.io.OutputStreamWriter;
 import java.lang.annotation.Annotation;
 import java.lang.reflect.Type;
+import java.util.Collections;
+import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 import java.util.concurrent.ConcurrentHashMap;
@@ -33,11 +35,13 @@
 import javax.ws.rs.Produces;
 import javax.ws.rs.core.MediaType;
 import javax.ws.rs.ext.Provider;
+import javax.xml.namespace.NamespaceContext;
 import javax.xml.namespace.QName;
 import javax.xml.stream.XMLStreamReader;
 import javax.xml.stream.XMLStreamWriter;
 
-import org.apache.cxf.common.util.PackageUtils;
+import org.apache.cxf.jaxrs.utils.JAXRSUtils;
+import org.apache.cxf.staxutils.DepthXMLStreamReader;
 import org.codehaus.jettison.AbstractXMLStreamWriter;
 import org.codehaus.jettison.mapped.Configuration;
 import org.codehaus.jettison.mapped.MappedNamespaceConvention;
@@ -99,17 +103,17 @@
     
     @Override
     protected XMLStreamReader createStreamReader(Class<?> type, InputStream is) throws
Exception {
+        if (readXsiType) {
+            namespaceMap.putIfAbsent("http://www.w3.org/2001/XMLSchema-instance", "xsins");
+        }
+        getQName(type);
         MappedXMLInputFactory factory = new MappedXMLInputFactory(namespaceMap);
-        return factory.createXMLStreamReader(is);
+        return new NamespaceContextReader(factory.createXMLStreamReader(is));
     }
     
     private QName getQName(Class<?> type) {
-        String nsURI = PackageUtils.getNamespace(PackageUtils.getPackageName(type));
-        if (nsURI.endsWith("/")) {
-            nsURI = nsURI.substring(0, nsURI.length() - 1);
-        }
-        QName qname = new QName(nsURI, type.getSimpleName(), "ns1"); 
-        namespaceMap.putIfAbsent(nsURI, "ns1");
+        QName qname = JAXRSUtils.getClassQName(type); 
+        namespaceMap.putIfAbsent(qname.getNamespaceURI(), "ns1");
         return qname;
     }
     
@@ -118,4 +122,36 @@
                                     qname.getNamespaceURI(),
                                     qname.getLocalPart());
     }
+    
+    private class NamespaceContextReader extends DepthXMLStreamReader {
+        public NamespaceContextReader(XMLStreamReader reader) {
+            super(reader);
+        }
+        
+        @Override
+        public NamespaceContext getNamespaceContext() {
+            return new NamespaceContext() {
+
+                public String getNamespaceURI(String prefix) {
+                    for (Map.Entry<String, String> entry : namespaceMap.entrySet())
{
+                        if (entry.getValue().equals(prefix)) {
+                            return entry.getKey();
+                        }
+                    }
+                    return null;
+                }
+
+                public String getPrefix(String ns) {
+                    return namespaceMap.get(ns);
+                }
+
+                public Iterator getPrefixes(String ns) {
+                    String prefix = getPrefix(ns);
+                    return prefix == null ? null : Collections.singletonList(prefix).iterator();
+                }
+                
+            };
+        }
+    }
+    
 }

Modified: cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java?rev=797541&r1=797540&r2=797541&view=diff
==============================================================================
--- cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java
(original)
+++ cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java
Fri Jul 24 15:42:56 2009
@@ -63,9 +63,11 @@
 import javax.ws.rs.ext.MessageBodyReader;
 import javax.ws.rs.ext.MessageBodyWriter;
 import javax.ws.rs.ext.Providers;
+import javax.xml.namespace.QName;
 
 import org.apache.cxf.common.i18n.BundleUtils;
 import org.apache.cxf.common.logging.LogUtils;
+import org.apache.cxf.common.util.PackageUtils;
 import org.apache.cxf.common.util.StringUtils;
 import org.apache.cxf.jaxrs.ext.MessageContext;
 import org.apache.cxf.jaxrs.ext.MessageContextImpl;
@@ -1041,4 +1043,12 @@
         return false;
     }
     
+    public static QName getClassQName(Class<?> type) {
+        String nsURI = PackageUtils.getNamespace(PackageUtils.getPackageName(type));
+        if (nsURI.endsWith("/")) {
+            nsURI = nsURI.substring(0, nsURI.length() - 1);
+        }
+        return new QName(nsURI, type.getSimpleName(), "ns1"); 
+    }
+    
 }

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=797541&r1=797540&r2=797541&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
Fri Jul 24 15:42:56 2009
@@ -35,7 +35,6 @@
 import org.apache.cxf.jaxrs.resources.Tags;
 
 import org.junit.Assert;
-import org.junit.Ignore;
 import org.junit.Test;
 
 public class AegisJSONProviderTest extends Assert {
@@ -52,14 +51,27 @@
         assertFalse(p.isReadable(AegisTestBean.class, null, null, null));
     }
     
-    @SuppressWarnings("unchecked")
+    
     @Test
-    @Ignore
     public void testReadFrom() throws Exception {
+        doTestRead(true);
+    }
+    
+    @Test
+    public void testReadFromNoMap() throws Exception {
+        doTestRead(false);
+    }
+    
+    @SuppressWarnings("unchecked")
+    private void doTestRead(boolean setNsMap) throws Exception {
         AegisJSONProvider p = new AegisJSONProvider();
-        Map<String, String> namespaceMap = new HashMap<String, String>();
-        namespaceMap.put("http://fortest.jaxrs.cxf.apache.org", "ns1");
-        namespaceMap.put("http://www.w3.org/2001/XMLSchema-instance", "ns2");
+        p.clearContexts();
+        if (setNsMap) {
+            Map<String, String> namespaceMap = new HashMap<String, String>();
+            namespaceMap.put("http://fortest.jaxrs.cxf.apache.org", "ns1");
+            namespaceMap.put("http://www.w3.org/2001/XMLSchema-instance", "xsins");
+            p.setNamespaceMap(namespaceMap);
+        }
         String data = "{\"ns1.AegisTestBean\":{\"@xsins.type\":\"ns1:AegisTestBean\","
             + "\"ns1.boolValue\":true,\"ns1.strValue\":\"hovercraft\"}}";
         



Mime
View raw message