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:58:38 GMT
Repository: cxf
Updated Branches:
  refs/heads/3.1.x-fixes 0dc95c180 -> 765686ec0


[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/765686ec
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/765686ec
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/765686ec

Branch: refs/heads/3.1.x-fixes
Commit: 765686ec011bbcbe4f093515fcf0a9a193b2e3a9
Parents: 0dc95c1
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:58:05 2016 +0100

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


http://git-wip-us.apache.org/repos/asf/cxf/blob/765686ec/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 a0912a0..98c3845 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,6 +20,8 @@ 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 java.nio.charset.StandardCharsets;
 
@@ -27,6 +29,7 @@ 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;
@@ -51,9 +54,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