cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From amccri...@apache.org
Subject [cxf] branch master updated: CXF-7888 - Handle EscapeHandler for IBM XLXP JAXB implementation.
Date Thu, 01 Nov 2018 20:32:18 GMT
This is an automated email from the ASF dual-hosted git repository.

amccright pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/cxf.git


The following commit(s) were added to refs/heads/master by this push:
     new 0dbe05e  CXF-7888 - Handle EscapeHandler for IBM XLXP JAXB implementation.
0dbe05e is described below

commit 0dbe05e16e3cd0240ba781ff2fb9e78c1833fcc6
Author: Andy McCright <j.andrew.mccright@gmail.com>
AuthorDate: Thu Nov 1 15:31:24 2018 -0500

    CXF-7888 - Handle EscapeHandler for IBM XLXP JAXB implementation.
    
    This allows the escape handler to be set on an IBM XML Marshaller for
    environments like WebSphere Liberty where the default com.sun.xml
    implementation is replaced with a different JAXB impl. The new tests
    verifies that it works for both the com.sun.xml and com.ibm.xml impls.
---
 .../java/org/apache/cxf/common/jaxb/JAXBUtils.java |   8 +-
 .../ibm/xml/mock/marshaller/MockMarshaller.java    | 177 +++++++++++++++++++++
 .../org/apache/cxf/common/jaxb/JAXBUtilsTest.java  |  50 ++++++
 3 files changed, 232 insertions(+), 3 deletions(-)

diff --git a/core/src/main/java/org/apache/cxf/common/jaxb/JAXBUtils.java b/core/src/main/java/org/apache/cxf/common/jaxb/JAXBUtils.java
index bc5c528..f240bce 100644
--- a/core/src/main/java/org/apache/cxf/common/jaxb/JAXBUtils.java
+++ b/core/src/main/java/org/apache/cxf/common/jaxb/JAXBUtils.java
@@ -1536,11 +1536,13 @@ public final class JAXBUtils {
     }
 
     private static String getPostfix(Class<?> cls) {
-        if (cls.getName().contains("com.sun.xml.internal")
-            || cls.getName().contains("eclipse")) {
+        String className = cls.getName();
+        if (className.contains("com.sun.xml.internal")
+            || className.contains("eclipse")) {
             //eclipse moxy accepts sun package CharacterEscapeHandler 
             return ".internal";
-        } else if (cls.getName().contains("com.sun.xml.bind")) {
+        } else if (className.contains("com.sun.xml.bind")
+            || className.startsWith("com.ibm.xml")) {
             return "";
         }
         return null;
diff --git a/core/src/test/java/com/ibm/xml/mock/marshaller/MockMarshaller.java b/core/src/test/java/com/ibm/xml/mock/marshaller/MockMarshaller.java
new file mode 100644
index 0000000..1551158
--- /dev/null
+++ b/core/src/test/java/com/ibm/xml/mock/marshaller/MockMarshaller.java
@@ -0,0 +1,177 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package com.ibm.xml.mock.marshaller;
+
+import java.io.File;
+import java.io.OutputStream;
+import java.io.Writer;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.xml.bind.JAXBException;
+import javax.xml.bind.Marshaller;
+import javax.xml.bind.PropertyException;
+import javax.xml.bind.ValidationEventHandler;
+import javax.xml.bind.annotation.adapters.XmlAdapter;
+import javax.xml.bind.attachment.AttachmentMarshaller;
+import javax.xml.stream.XMLEventWriter;
+import javax.xml.stream.XMLStreamWriter;
+import javax.xml.transform.Result;
+import javax.xml.validation.Schema;
+
+import org.w3c.dom.Node;
+
+import org.xml.sax.ContentHandler;
+
+public class MockMarshaller implements Marshaller {
+
+    private final Map<String, Object> properties = new HashMap<>();
+
+    @Override
+    public void marshal(Object jaxbElement, Result result) throws JAXBException {
+        // TODO Auto-generated method stub
+
+    }
+
+    @Override
+    public void marshal(Object jaxbElement, OutputStream os) throws JAXBException {
+        // TODO Auto-generated method stub
+
+    }
+
+    @Override
+    public void marshal(Object jaxbElement, File output) throws JAXBException {
+        // TODO Auto-generated method stub
+
+    }
+
+    @Override
+    public void marshal(Object jaxbElement, Writer writer) throws JAXBException {
+        // TODO Auto-generated method stub
+
+    }
+
+    @Override
+    public void marshal(Object jaxbElement, ContentHandler handler) throws JAXBException
{
+        // TODO Auto-generated method stub
+
+    }
+
+    @Override
+    public void marshal(Object jaxbElement, Node node) throws JAXBException {
+        // TODO Auto-generated method stub
+
+    }
+
+    @Override
+    public void marshal(Object jaxbElement, XMLStreamWriter writer) throws JAXBException
{
+        // TODO Auto-generated method stub
+
+    }
+
+    @Override
+    public void marshal(Object jaxbElement, XMLEventWriter writer) throws JAXBException {
+        // TODO Auto-generated method stub
+
+    }
+
+    @Override
+    public Node getNode(Object contentTree) throws JAXBException {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    @Override
+    public void setProperty(String name, Object value) throws PropertyException {
+        properties.put(name, value);
+    }
+
+    @Override
+    public Object getProperty(String name) throws PropertyException {
+        return properties.get(name);
+    }
+
+    @Override
+    public void setEventHandler(ValidationEventHandler handler) throws JAXBException {
+        // TODO Auto-generated method stub
+
+    }
+
+    @Override
+    public ValidationEventHandler getEventHandler() throws JAXBException {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    @Override
+    public void setAdapter(XmlAdapter adapter) {
+        // TODO Auto-generated method stub
+
+    }
+
+    @Override
+    public <A extends XmlAdapter> void setAdapter(Class<A> type, A adapter) {
+        // TODO Auto-generated method stub
+
+    }
+
+    @Override
+    public <A extends XmlAdapter> A getAdapter(Class<A> type) {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    @Override
+    public void setAttachmentMarshaller(AttachmentMarshaller am) {
+        // TODO Auto-generated method stub
+
+    }
+
+    @Override
+    public AttachmentMarshaller getAttachmentMarshaller() {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    @Override
+    public void setSchema(Schema schema) {
+        // TODO Auto-generated method stub
+
+    }
+
+    @Override
+    public Schema getSchema() {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    @Override
+    public void setListener(Listener listener) {
+        // TODO Auto-generated method stub
+
+    }
+
+    @Override
+    public Listener getListener() {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+}
diff --git a/core/src/test/java/org/apache/cxf/common/jaxb/JAXBUtilsTest.java b/core/src/test/java/org/apache/cxf/common/jaxb/JAXBUtilsTest.java
new file mode 100644
index 0000000..ad8a621
--- /dev/null
+++ b/core/src/test/java/org/apache/cxf/common/jaxb/JAXBUtilsTest.java
@@ -0,0 +1,50 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.cxf.common.jaxb;
+
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.Marshaller;
+
+import com.ibm.xml.mock.marshaller.MockMarshaller;
+import com.sun.xml.bind.marshaller.MinimumEscapeHandler;
+import com.sun.xml.bind.v2.runtime.JAXBContextImpl;
+import com.sun.xml.bind.v2.runtime.MarshallerImpl;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+public class JAXBUtilsTest extends Assert {
+
+    @Test
+    public void testCanSetEscapeHandlerWithStandardJaxbImpl() throws Exception {
+        Marshaller m = new MarshallerImpl((JAXBContextImpl) JAXBContext.newInstance(this.getClass()),
null);
+        final Object mockHandler = MinimumEscapeHandler.theInstance;
+        JAXBUtils.setEscapeHandler(m, mockHandler);
+        assertEquals(mockHandler, m.getProperty("com.sun.xml.bind.characterEscapeHandler"));
+    }
+
+    @Test
+    public void testCanSetEscapeHandlerWithIbmJaxbImpl() throws Exception {
+        Marshaller m = new MockMarshaller();
+        final Object mockHandler = new Object();
+        JAXBUtils.setEscapeHandler(m, mockHandler);
+        assertEquals(mockHandler, m.getProperty("com.sun.xml.bind.characterEscapeHandler"));
+    }
+}


Mime
View raw message