cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bimargul...@apache.org
Subject svn commit: r806876 - in /cxf/trunk/rt/frontend/jaxrs/src: main/java/org/apache/cxf/jaxrs/provider/ test/java/org/apache/cxf/jaxrs/provider/
Date Sat, 22 Aug 2009 18:10:38 GMT
Author: bimargulies
Date: Sat Aug 22 18:10:37 2009
New Revision: 806876

URL: http://svn.apache.org/viewvc?rev=806876&view=rev
Log:
CXF-2401.

Modified:
    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/JSONUtils.java
    cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/AegisJSONProviderTest.java

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=806876&r1=806875&r2=806876&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
Sat Aug 22 18:10:37 2009
@@ -32,6 +32,7 @@
 import javax.ws.rs.core.MediaType;
 import javax.ws.rs.core.MultivaluedMap;
 import javax.ws.rs.ext.Provider;
+import javax.xml.namespace.QName;
 import javax.xml.stream.XMLStreamReader;
 import javax.xml.stream.XMLStreamWriter;
 
@@ -75,7 +76,7 @@
         org.apache.cxf.aegis.type.Type aegisType = TypeUtil.getWriteTypeStandalone(context,
obj, genericType);
         AegisWriter<XMLStreamWriter> aegisWriter = context.createXMLStreamWriter();
         try {
-            XMLStreamWriter xmlStreamWriter = createStreamWriter(type, os);
+            XMLStreamWriter xmlStreamWriter = createStreamWriter(aegisType.getSchemaType(),
os);
             // use type qname as element qname?
             xmlStreamWriter.writeStartDocument();
             aegisWriter.write(obj, aegisType.getSchemaType(), false, xmlStreamWriter, aegisType);
@@ -86,7 +87,8 @@
         }
     }
     
-    protected XMLStreamWriter createStreamWriter(Class<?> type, OutputStream os) throws
Exception {
+    protected XMLStreamWriter createStreamWriter(QName typeQName, 
+                                                 OutputStream os) throws Exception {
         return StaxUtils.createXMLStreamWriter(os);
     }
 }

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=806876&r1=806875&r2=806876&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
Sat Aug 22 18:10:37 2009
@@ -68,10 +68,11 @@
     }
     
     @Override
-    protected XMLStreamWriter createStreamWriter(Class<?> type, OutputStream os) throws
Exception {
-        QName qname = getQName(type);
-        return JSONUtils.createStreamWriter(os, qname, writeXsiType, namespaceMap, 
-                                                           serializeAsArray, arrayKeys);
+    protected XMLStreamWriter createStreamWriter(QName typeQName, OutputStream os) throws
Exception {
+        namespaceMap.putIfAbsent(typeQName.getNamespaceURI(), "ns1");
+        XMLStreamWriter writer = JSONUtils.createStreamWriter(os, typeQName, writeXsiType,
namespaceMap, 
+                                                              serializeAsArray, arrayKeys);
+        return writer;
     }
     
     @Override

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JSONUtils.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JSONUtils.java?rev=806876&r1=806875&r2=806876&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JSONUtils.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JSONUtils.java
Sat Aug 22 18:10:37 2009
@@ -21,11 +21,13 @@
 import java.io.InputStream;
 import java.io.OutputStream;
 import java.io.OutputStreamWriter;
+import java.nio.charset.Charset;
 import java.util.Collections;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 
+import javax.xml.XMLConstants;
 import javax.xml.namespace.NamespaceContext;
 import javax.xml.namespace.QName;
 import javax.xml.stream.XMLStreamReader;
@@ -40,6 +42,10 @@
 
 public final class JSONUtils {
 
+    private static final String XSI_PREFIX = "xsi";
+    private static final String XSI_URI = XMLConstants.W3C_XML_SCHEMA_INSTANCE_NS_URI;
+    private static final Charset UTF8 = Charset.forName("utf-8");
+
     private JSONUtils() {
     }
     
@@ -49,13 +55,13 @@
                                                      boolean serializeAsArray,
                                                      List<String> arrayKeys) throws
Exception {
         if (writeXsiType) {
-            namespaceMap.put("http://www.w3.org/2001/XMLSchema-instance", "xsi");
+            namespaceMap.put(XSI_URI, XSI_PREFIX);
         }
         Configuration c = new Configuration(namespaceMap);
         MappedNamespaceConvention convention = new MappedNamespaceConvention(c);
         AbstractXMLStreamWriter xsw = new MappedXMLStreamWriter(
                                             convention, 
-                                            new OutputStreamWriter(os, "UTF-8"));
+                                            new OutputStreamWriter(os, UTF8));
         if (serializeAsArray) {
             if (arrayKeys != null) {
                 for (String key : arrayKeys) {
@@ -80,7 +86,7 @@
     public static XMLStreamReader createStreamReader(InputStream is, boolean readXsiType,
                                                Map<String, String> namespaceMap) throws
Exception {
         if (readXsiType) {
-            namespaceMap.put("http://www.w3.org/2001/XMLSchema-instance", "xsi");
+            namespaceMap.put(XSI_URI, XSI_PREFIX);
         }
         MappedXMLInputFactory factory = new MappedXMLInputFactory(namespaceMap);
         return new JettisonReader(namespaceMap, factory.createXMLStreamReader(is));
@@ -98,8 +104,8 @@
         public String getAttributePrefix(int n) {
             QName name = getAttributeName(n);
             if (name != null 
-                && "http://www.w3.org/2001/XMLSchema-instance".equals(name.getNamespaceURI()))
{
-                return "xsi";
+                && XSI_URI.equals(name.getNamespaceURI())) {
+                return XSI_PREFIX;
             } else {
                 return super.getAttributePrefix(n);
             }

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=806876&r1=806875&r2=806876&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
Sat Aug 22 18:10:37 2009
@@ -132,7 +132,7 @@
         
     }
     
-    @org.junit.Ignore
+   // @org.junit.Ignore
     @Test
     public void testWriteCollection() throws Exception {
         AegisJSONProvider p = new AegisJSONProvider();
@@ -144,14 +144,13 @@
         bean.setStrValue("hovercraft");
         List<AegisTestBean> beans = new ArrayList<AegisTestBean>();
         beans.add(bean);
-        Method m = CollectionsResource.class.getMethod("getAegisBeans", new Class[]{});
-        p.writeTo(beans, (Class)m.getReturnType(), m.getGenericReturnType(), 
-                  AegisTestBean.class.getAnnotations(), 
-                  MediaType.APPLICATION_JSON_TYPE, new MetadataMap<String, Object>(),
os);
+        Method m = CollectionsResource.class.getMethod("getAegisBeans", new Class[] {});
+        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");
-        System.out.println(json);
-        //assertEquals(data, json);
+        assertEquals("{\"ns1.ArrayOfAegisTestBean\":{\"ns1.AegisTestBean\":"
+                     + "{\"ns1.boolValue\":true,\"ns1.strValue\":\"hovercraft\"}}}", json);
     }
     
     @Test



Mime
View raw message