cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject git commit: [CXF-5808] Updating JAXBUtils to default to a mapper shipper with CXF if possible
Date Mon, 14 Jul 2014 15:49:00 GMT
Repository: cxf
Updated Branches:
  refs/heads/2.7.x-fixes 7c5682882 -> f02aee092


[CXF-5808] Updating JAXBUtils to default to a mapper shipper with CXF if possible


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

Branch: refs/heads/2.7.x-fixes
Commit: f02aee092c84d426a024ea39a2688a43fc98f866
Parents: 7c56828
Author: Sergey Beryozkin <sberyozkin@talend.com>
Authored: Wed Jun 18 12:55:22 2014 +0100
Committer: Sergey Beryozkin <sberyozkin@talend.com>
Committed: Mon Jul 14 16:48:40 2014 +0100

----------------------------------------------------------------------
 .../org/apache/cxf/common/jaxb/JAXBUtils.java   | 32 +++++++++++++++-----
 .../jaxrs/provider/AbstractJAXBProvider.java    |  2 +-
 .../cxf/jaxrs/provider/json/JSONProvider.java   |  6 ++--
 .../jaxrs/provider/json/utils/JSONUtils.java    |  4 +--
 4 files changed, 30 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/f02aee09/api/src/main/java/org/apache/cxf/common/jaxb/JAXBUtils.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/cxf/common/jaxb/JAXBUtils.java b/api/src/main/java/org/apache/cxf/common/jaxb/JAXBUtils.java
index 94810ce..31cf54c 100644
--- a/api/src/main/java/org/apache/cxf/common/jaxb/JAXBUtils.java
+++ b/api/src/main/java/org/apache/cxf/common/jaxb/JAXBUtils.java
@@ -68,6 +68,7 @@ import org.w3c.dom.Node;
 import org.xml.sax.EntityResolver;
 import org.xml.sax.InputSource;
 
+import org.apache.cxf.common.classloader.ClassLoaderUtils;
 import org.apache.cxf.common.util.ASMHelper;
 import org.apache.cxf.common.util.ASMHelper.ClassWriter;
 import org.apache.cxf.common.util.ASMHelper.FieldVisitor;
@@ -1008,17 +1009,32 @@ public final class JAXBUtils {
         className += postFix;
         Class<?> cls = helper.findClass(className, JAXBUtils.class);
         if (cls == null) {
-            ClassWriter cw = helper.createClassWriter();
-            if (cw == null) {
-                return null;
+            try {
+                ClassWriter cw = helper.createClassWriter();
+                if (cw != null) { 
+                    cls = createNamespaceWrapperInternal(helper, cw, postFix, mcls);
+                }
+            } catch (RuntimeException ex) {
+                // continue
             }
-            cls = createNamespaceWrapperInternal(helper, cw, postFix, mcls);
         }
-        try {
-            return cls.getConstructor(Map.class).newInstance(map);
-        } catch (Exception e) {
-            return null;
+        if (cls == null
+            && (mcls.getName().contains(".internal.") || mcls.getName().contains("com.sun")))
{
+            try {
+                cls = ClassLoaderUtils.loadClass("org.apache.cxf.common.jaxb.NamespaceMapper",

+                                                 JAXBUtils.class);
+            } catch (ClassNotFoundException ex2) {
+                // ignore
+            }
         }
+        if (cls != null) {
+            try {
+                return cls.getConstructor(Map.class).newInstance(map);
+            } catch (Exception e) {
+                // ignore
+            }
+        }
+        return null;
     }
     /*
     // This is the "prototype" for the ASM generated class below

http://git-wip-us.apache.org/repos/asf/cxf/blob/f02aee09/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/AbstractJAXBProvider.java
----------------------------------------------------------------------
diff --git a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/AbstractJAXBProvider.java
b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/AbstractJAXBProvider.java
index 4105dff..7e66049 100644
--- a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/AbstractJAXBProvider.java
+++ b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/AbstractJAXBProvider.java
@@ -141,7 +141,7 @@ public abstract class AbstractJAXBProvider<T> extends AbstractConfigurableProvid
     protected void setNamespaceMapper(Marshaller ms, 
                                       Map<String, String> map) throws Exception {
         Object nsMapper = JAXBUtils.setNamespaceMapper(map, ms);
-        if (namespaceMapperPropertyName != null) {
+        if (nsMapper != null && namespaceMapperPropertyName != null) {
             setMarshallerProp(ms, nsMapper, namespaceMapperPropertyName, null);
         }
     }

http://git-wip-us.apache.org/repos/asf/cxf/blob/f02aee09/rt/rs/extensions/providers/src/main/java/org/apache/cxf/jaxrs/provider/json/JSONProvider.java
----------------------------------------------------------------------
diff --git a/rt/rs/extensions/providers/src/main/java/org/apache/cxf/jaxrs/provider/json/JSONProvider.java
b/rt/rs/extensions/providers/src/main/java/org/apache/cxf/jaxrs/provider/json/JSONProvider.java
index 4050087..34bf30b 100644
--- a/rt/rs/extensions/providers/src/main/java/org/apache/cxf/jaxrs/provider/json/JSONProvider.java
+++ b/rt/rs/extensions/providers/src/main/java/org/apache/cxf/jaxrs/provider/json/JSONProvider.java
@@ -487,6 +487,9 @@ public class JSONProvider<T> extends AbstractJAXBProvider<T>
 {
         }
         XMLStreamWriter writer = createWriter(actualObject, actualClass, genericType, enc,

                                               actualOs, isCollection);
+        if (namespaceMap.size() > 1 || namespaceMap.size() == 1 && !namespaceMap.containsKey(JSONUtils.XSI_URI))
{
+            setNamespaceMapper(ms, namespaceMap);
+        }
         ms.marshal(actualObject, writer);
         writer.close();
         if (os != actualOs) {
@@ -597,9 +600,6 @@ public class JSONProvider<T> extends AbstractJAXBProvider<T>
 {
         }
         
         Marshaller ms = createMarshaller(actualObject, actualClass, genericType, enc);
-        if (!namespaceMap.isEmpty()) {
-            setNamespaceMapper(ms, namespaceMap);
-        }
         marshal(ms, actualObject, actualClass, genericType, enc, os, false);
     }
     

http://git-wip-us.apache.org/repos/asf/cxf/blob/f02aee09/rt/rs/extensions/providers/src/main/java/org/apache/cxf/jaxrs/provider/json/utils/JSONUtils.java
----------------------------------------------------------------------
diff --git a/rt/rs/extensions/providers/src/main/java/org/apache/cxf/jaxrs/provider/json/utils/JSONUtils.java
b/rt/rs/extensions/providers/src/main/java/org/apache/cxf/jaxrs/provider/json/utils/JSONUtils.java
index 6b2a4ad..4bf0b83 100644
--- a/rt/rs/extensions/providers/src/main/java/org/apache/cxf/jaxrs/provider/json/utils/JSONUtils.java
+++ b/rt/rs/extensions/providers/src/main/java/org/apache/cxf/jaxrs/provider/json/utils/JSONUtils.java
@@ -55,8 +55,8 @@ import org.codehaus.jettison.mapped.TypeConverter;
 
 public final class JSONUtils {
 
-    private static final String XSI_PREFIX = "xsi";
-    private static final String XSI_URI = WSDLConstants.NS_SCHEMA_XSI; 
+    public static final String XSI_PREFIX = "xsi";
+    public static final String XSI_URI = WSDLConstants.NS_SCHEMA_XSI; 
     
     private JSONUtils() {
     }


Mime
View raw message