You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by dk...@apache.org on 2019/05/06 18:17:14 UTC

[cxf] branch master updated (083c6fa -> 1cc03b9)

This is an automated email from the ASF dual-hosted git repository.

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


    from 083c6fa  CXF-7885 - SOAP Action ignored by CXF JMS webservice method invoker
     new 2e44ce1  Need to exclude the old version of stax-api that SAAJ impl pulls in on Java11
     new 1cc03b9  [CXF-8028] Use ClassValue to cache/record the method/field needed for the SAAJ workarounds to avoid expensive reflection on every element.

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../main/java/org/apache/cxf/helpers/DOMUtils.java | 48 ++++++++++++++--------
 parent/pom.xml                                     |  6 +++
 2 files changed, 37 insertions(+), 17 deletions(-)


[cxf] 01/02: Need to exclude the old version of stax-api that SAAJ impl pulls in on Java11

Posted by dk...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 2e44ce12233c213b5fef8bbc28d71554554a8fbb
Author: Daniel Kulp <dk...@apache.org>
AuthorDate: Mon May 6 11:51:31 2019 -0400

    Need to exclude the old version of stax-api that SAAJ impl pulls in on Java11
---
 parent/pom.xml | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/parent/pom.xml b/parent/pom.xml
index 84d602e..4d8b1d0 100644
--- a/parent/pom.xml
+++ b/parent/pom.xml
@@ -2848,6 +2848,12 @@
                     <groupId>com.sun.xml.messaging.saaj</groupId>
                     <artifactId>saaj-impl</artifactId>
                     <version>1.4.0-b03</version>
+                    <exclusions>
+                        <exclusion>
+                            <groupId>javax.xml.stream</groupId>
+                            <artifactId>stax-api</artifactId>
+                        </exclusion>
+                    </exclusions>
                 </dependency>
                 <dependency>
                     <groupId>org.jacorb</groupId>


[cxf] 02/02: [CXF-8028] Use ClassValue to cache/record the method/field needed for the SAAJ workarounds to avoid expensive reflection on every element.

Posted by dk...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 1cc03b9b70bc509d8f8c631563c3964e56e30621
Author: Daniel Kulp <dk...@apache.org>
AuthorDate: Mon May 6 14:10:32 2019 -0400

    [CXF-8028] Use ClassValue to cache/record the method/field needed for the SAAJ workarounds to avoid expensive reflection on every element.
---
 .../main/java/org/apache/cxf/helpers/DOMUtils.java | 48 ++++++++++++++--------
 1 file changed, 31 insertions(+), 17 deletions(-)

diff --git a/core/src/main/java/org/apache/cxf/helpers/DOMUtils.java b/core/src/main/java/org/apache/cxf/helpers/DOMUtils.java
index 280cb17..303ed17 100644
--- a/core/src/main/java/org/apache/cxf/helpers/DOMUtils.java
+++ b/core/src/main/java/org/apache/cxf/helpers/DOMUtils.java
@@ -22,6 +22,7 @@ package org.apache.cxf.helpers;
 import java.io.IOException;
 import java.io.StringReader;
 import java.lang.reflect.Field;
+import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
 import java.security.AccessController;
 import java.security.PrivilegedAction;
@@ -54,6 +55,7 @@ import org.xml.sax.InputSource;
 import org.xml.sax.SAXException;
 
 import org.apache.cxf.common.logging.LogUtils;
+import org.apache.cxf.common.util.ReflectionUtil;
 import org.apache.cxf.common.util.StringUtils;
 
 /**
@@ -66,8 +68,25 @@ public final class DOMUtils {
     private static final String XMLNAMESPACE = "xmlns";
     private static volatile Document emptyDocument;
 
-
-
+    private static final ClassValue<Method> GET_DOM_ELEMENTS_METHODS = new ClassValue<Method>() {
+        @Override
+        protected Method computeValue(Class<?> type) {
+            try {
+                return ReflectionUtil.getMethod(type, "getDomElement");
+            } catch (NoSuchMethodException e) {
+                //best effort to try, do nothing if NoSuchMethodException
+                return null;
+            }
+        }
+    };
+    private static final ClassValue<Field> GET_DOCUMENT_FRAGMENT_FIELDS = new ClassValue<Field>() {
+        @Override
+        protected Field computeValue(Class<?> type) {
+            return ReflectionUtil.getDeclaredField(type, "documentFragment");
+        }
+        
+    };
+        
     static {
         try {
             Method[] methods = DOMUtils.class.getClassLoader().
@@ -751,13 +770,13 @@ public final class DOMUtils {
     public static Node getDomElement(Node node) {
         if (node != null && isJava9SAAJ()) {
             //java9plus hack
-            try {
-                Method method = node.getClass().getMethod("getDomElement");
-                node = (Node)method.invoke(node);
-            } catch (NoSuchMethodException e) {
-                //best effort to try, do nothing if NoSuchMethodException
-            } catch (Exception e) {
-                throw new RuntimeException(e);
+            Method method = GET_DOM_ELEMENTS_METHODS.get(node.getClass());
+            if (method != null) {
+                try {
+                    return (Node)ReflectionUtil.setAccessible(method).invoke(node);
+                } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
+                    throw new RuntimeException(e);
+                }
             }
         }
         return node;
@@ -771,14 +790,9 @@ public final class DOMUtils {
     public static DocumentFragment getDomDocumentFragment(DocumentFragment fragment) {
         if (fragment != null && isJava9SAAJ()) {
             //java9 plus hack
-            try {
-                Field f = fragment.getClass().getDeclaredField("documentFragment");
-                f.setAccessible(true);
-                fragment = (DocumentFragment) f.get(fragment);
-            } catch (NoSuchFieldException e) {
-                //best effort to try, do nothing if NoSuchMethodException
-            } catch (Exception e) {
-                throw new RuntimeException(e);
+            Field f = GET_DOCUMENT_FRAGMENT_FIELDS.get(fragment.getClass());
+            if (f != null) {
+                return ReflectionUtil.accessDeclaredField(f, fragment, DocumentFragment.class);
             }
         }
         return fragment;