cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1468493 - in /cxf/branches/2.6.x-fixes: ./ rt/rs/extensions/providers/src/main/java/org/apache/cxf/jaxrs/provider/json/JSONProvider.java rt/rs/extensions/providers/src/test/java/org/apache/cxf/jaxrs/provider/dom4j/DOM4JProviderTest.java
Date Tue, 16 Apr 2013 16:28:39 GMT
Author: sergeyb
Date: Tue Apr 16 16:28:38 2013
New Revision: 1468493

URL: http://svn.apache.org/r1468493
Log:
Merged revisions 1468491 via svnmerge from 
https://svn.apache.org/repos/asf/cxf/branches/2.7.x-fixes

................
  r1468491 | sergeyb | 2013-04-16 17:25:00 +0100 (Tue, 16 Apr 2013) | 9 lines
  
  Merged revisions 1468490 via svnmerge from 
  https://svn.apache.org/repos/asf/cxf/trunk
  
  ........
    r1468490 | sergeyb | 2013-04-16 17:22:36 +0100 (Tue, 16 Apr 2013) | 1 line
    
    [CXF-4967] Fixing NPE in JSONProvider
  ........
................

Modified:
    cxf/branches/2.6.x-fixes/   (props changed)
    cxf/branches/2.6.x-fixes/rt/rs/extensions/providers/src/main/java/org/apache/cxf/jaxrs/provider/json/JSONProvider.java
    cxf/branches/2.6.x-fixes/rt/rs/extensions/providers/src/test/java/org/apache/cxf/jaxrs/provider/dom4j/DOM4JProviderTest.java

Propchange: cxf/branches/2.6.x-fixes/
------------------------------------------------------------------------------
--- svn:mergeinfo (added)
+++ svn:mergeinfo Tue Apr 16 16:28:38 2013
@@ -0,0 +1,2 @@
+/cxf/branches/2.7.x-fixes:1468491
+/cxf/trunk:1468490

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

Modified: cxf/branches/2.6.x-fixes/rt/rs/extensions/providers/src/main/java/org/apache/cxf/jaxrs/provider/json/JSONProvider.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.6.x-fixes/rt/rs/extensions/providers/src/main/java/org/apache/cxf/jaxrs/provider/json/JSONProvider.java?rev=1468493&r1=1468492&r2=1468493&view=diff
==============================================================================
--- cxf/branches/2.6.x-fixes/rt/rs/extensions/providers/src/main/java/org/apache/cxf/jaxrs/provider/json/JSONProvider.java
(original)
+++ cxf/branches/2.6.x-fixes/rt/rs/extensions/providers/src/main/java/org/apache/cxf/jaxrs/provider/json/JSONProvider.java
Tue Apr 16 16:28:38 2013
@@ -491,7 +491,7 @@ public class JSONProvider<T> extends Abs
         Type genericType, String enc, OutputStream os, boolean isCollection) throws Exception
{
         
         QName qname = getQName(actualClass, genericType, actualObject);
-        if (ignoreNamespaces && (isCollection  || dropRootElement)) {        
+        if (qname != null && ignoreNamespaces && (isCollection  || dropRootElement))
{        
             qname = new QName(qname.getLocalPart());
         }
         if (BADGER_FISH_CONVENTION.equals(convention)) {

Modified: cxf/branches/2.6.x-fixes/rt/rs/extensions/providers/src/test/java/org/apache/cxf/jaxrs/provider/dom4j/DOM4JProviderTest.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.6.x-fixes/rt/rs/extensions/providers/src/test/java/org/apache/cxf/jaxrs/provider/dom4j/DOM4JProviderTest.java?rev=1468493&r1=1468492&r2=1468493&view=diff
==============================================================================
--- cxf/branches/2.6.x-fixes/rt/rs/extensions/providers/src/test/java/org/apache/cxf/jaxrs/provider/dom4j/DOM4JProviderTest.java
(original)
+++ cxf/branches/2.6.x-fixes/rt/rs/extensions/providers/src/test/java/org/apache/cxf/jaxrs/provider/dom4j/DOM4JProviderTest.java
Tue Apr 16 16:28:38 2013
@@ -29,6 +29,7 @@ import org.apache.cxf.endpoint.Endpoint;
 import org.apache.cxf.jaxrs.impl.MetadataMap;
 import org.apache.cxf.jaxrs.impl.ProvidersImpl;
 import org.apache.cxf.jaxrs.provider.ProviderFactory;
+import org.apache.cxf.jaxrs.provider.json.JSONProvider;
 import org.apache.cxf.message.Exchange;
 import org.apache.cxf.message.ExchangeImpl;
 import org.apache.cxf.message.Message;
@@ -47,9 +48,10 @@ public class DOM4JProviderTest extends A
         // starts with the xml PI
         assertTrue(str.contains("<a/>") || str.contains("<a></a>"));
     }
-    
     private org.dom4j.Document readXML() throws Exception {
-        final String xml = "<a/>";
+        return readXML("<a/>");
+    }
+    private org.dom4j.Document readXML(final String xml) throws Exception {
         DOM4JProvider p = new DOM4JProvider();
         p.setProviders(new ProvidersImpl(createMessage()));
         org.dom4j.Document dom = p.readFrom(org.dom4j.Document.class, org.dom4j.Document.class,

@@ -101,6 +103,21 @@ public class DOM4JProviderTest extends A
         assertEquals("{\"a\":\"\"}", str);
     }
     
+    @Test
+    public void testWriteJSONDropRoot() throws Exception {
+        org.dom4j.Document dom = readXML("<root><a/></root>");
+        DOM4JProvider p = new DOM4JProvider();
+        p.setProviders(new ProvidersImpl(createMessageWithJSONProvider()));
+        
+        ByteArrayOutputStream bos = new ByteArrayOutputStream();
+        p.writeTo(dom, org.dom4j.Document.class, org.dom4j.Document.class, 
+                   new Annotation[]{}, MediaType.APPLICATION_JSON_TYPE, new MetadataMap<String,
Object>(),
+                   bos);
+        String str = bos.toString();
+        // starts with the xml PI
+        assertEquals("{\"a\":\"\"}", str);
+    }
+    
     private Message createMessage() {
         ProviderFactory factory = ProviderFactory.getInstance();
         Message m = new MessageImpl();
@@ -123,4 +140,31 @@ public class DOM4JProviderTest extends A
         e.put(Endpoint.class, endpoint);
         return m;
     }
+    
+    private Message createMessageWithJSONProvider() {
+        ProviderFactory factory = ServerProviderFactory.getInstance();
+        JSONProvider<Object> provider = new JSONProvider<Object>();
+        provider.setDropRootElement(true);
+        provider.setIgnoreNamespaces(true);
+        factory.registerUserProvider(provider);
+        Message m = new MessageImpl();
+        m.put("org.apache.cxf.http.case_insensitive_queries", false);
+        Exchange e = new ExchangeImpl();
+        m.setExchange(e);
+        e.setInMessage(m);
+        Endpoint endpoint = EasyMock.createMock(Endpoint.class);
+        endpoint.getEndpointInfo();
+        EasyMock.expectLastCall().andReturn(null).anyTimes();
+        endpoint.get(Application.class.getName());
+        EasyMock.expectLastCall().andReturn(null);
+        endpoint.size();
+        EasyMock.expectLastCall().andReturn(0).anyTimes();
+        endpoint.isEmpty();
+        EasyMock.expectLastCall().andReturn(true).anyTimes();
+        endpoint.get(ServerProviderFactory.class.getName());
+        EasyMock.expectLastCall().andReturn(factory).anyTimes();
+        EasyMock.replay(endpoint);
+        e.put(Endpoint.class, endpoint);
+        return m;
+    }
 }



Mime
View raw message