cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject cxf git commit: [CXF-6895] Adding DOM4JProvider reading XML with BOM
Date Mon, 09 May 2016 09:59:27 GMT
Repository: cxf
Updated Branches:
  refs/heads/3.0.x-fixes 6e3b8bad8 -> 62e0f8d45


[CXF-6895] Adding DOM4JProvider reading XML with BOM


Project: http://git-wip-us.apache.org/repos/asf/cxf/repo
Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/62e0f8d4
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/62e0f8d4
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/62e0f8d4

Branch: refs/heads/3.0.x-fixes
Commit: 62e0f8d454414fca8935e403474f4a5b5768b436
Parents: 6e3b8ba
Author: Sergey Beryozkin <sberyozkin@gmail.com>
Authored: Mon May 9 10:55:15 2016 +0100
Committer: Sergey Beryozkin <sberyozkin@gmail.com>
Committed: Mon May 9 10:59:05 2016 +0100

----------------------------------------------------------------------
 .../jaxrs/provider/dom4j/DOM4JProviderTest.java | 23 ++++++++++++++++++++
 1 file changed, 23 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/62e0f8d4/rt/rs/extensions/providers/src/test/java/org/apache/cxf/jaxrs/provider/dom4j/DOM4JProviderTest.java
----------------------------------------------------------------------
diff --git a/rt/rs/extensions/providers/src/test/java/org/apache/cxf/jaxrs/provider/dom4j/DOM4JProviderTest.java
b/rt/rs/extensions/providers/src/test/java/org/apache/cxf/jaxrs/provider/dom4j/DOM4JProviderTest.java
index f4fa478..a3c94e7 100644
--- a/rt/rs/extensions/providers/src/test/java/org/apache/cxf/jaxrs/provider/dom4j/DOM4JProviderTest.java
+++ b/rt/rs/extensions/providers/src/test/java/org/apache/cxf/jaxrs/provider/dom4j/DOM4JProviderTest.java
@@ -20,12 +20,15 @@ package org.apache.cxf.jaxrs.provider.dom4j;
 
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
+import java.io.InputStream;
+import java.io.SequenceInputStream;
 import java.lang.annotation.Annotation;
 
 import javax.ws.rs.core.Application;
 import javax.ws.rs.core.MediaType;
 import javax.ws.rs.ext.Providers;
 
+import org.apache.cxf.common.util.StringUtils;
 import org.apache.cxf.endpoint.Endpoint;
 import org.apache.cxf.jaxrs.impl.MetadataMap;
 import org.apache.cxf.jaxrs.impl.ProvidersImpl;
@@ -50,9 +53,29 @@ public class DOM4JProviderTest extends Assert {
         // starts with the xml PI
         assertTrue(str.contains("<a/>") || str.contains("<a></a>"));
     }
+    @Test
+    public void testReadXMLWithBom() throws Exception {
+        String str = readXMLBom().asXML();
+        // starts with the xml PI
+        assertTrue(str.contains("<a/>") || str.contains("<a></a>"));
+    }
     private org.dom4j.Document readXML() throws Exception {
         return readXML(MediaType.APPLICATION_XML_TYPE, "<a/>");
     }
+    private org.dom4j.Document readXMLBom() throws Exception {
+        byte[] bom = new byte[]{(byte)239, (byte)187, (byte)191};
+        assertEquals("efbbbf", StringUtils.toHexString(bom));
+        byte[] strBytes = "<a/>".getBytes(StandardCharsets.UTF_8);
+        InputStream is = new SequenceInputStream(new ByteArrayInputStream(bom),
+                                                 new ByteArrayInputStream(strBytes));
+        DOM4JProvider p = new DOM4JProvider();
+        p.setProviders(new ProvidersImpl(createMessage(false)));
+        org.dom4j.Document dom = p.readFrom(org.dom4j.Document.class, org.dom4j.Document.class,

+            new Annotation[] {}, MediaType.valueOf("text/xml;a=b"), 
+            new MetadataMap<String, String>(),
+            is);
+        return dom;
+    }
     private org.dom4j.Document readXML(MediaType ct, final String xml) throws Exception {
         DOM4JProvider p = new DOM4JProvider();
         p.setProviders(new ProvidersImpl(createMessage(false)));


Mime
View raw message