You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by ff...@apache.org on 2022/01/25 15:50:19 UTC

[cxf] branch 3.5.x-fixes updated: [CXF-8644]introduce a cache for AbstractJAXBProvider to avoid unnecessary ObjectFactory.class|jaxb.index availability check

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

ffang pushed a commit to branch 3.5.x-fixes
in repository https://gitbox.apache.org/repos/asf/cxf.git


The following commit(s) were added to refs/heads/3.5.x-fixes by this push:
     new 0fbafc0  [CXF-8644]introduce a cache for AbstractJAXBProvider to avoid unnecessary ObjectFactory.class|jaxb.index availability check
0fbafc0 is described below

commit 0fbafc05632f475a4080f6c0c1da44f60f7f72ea
Author: Freeman Fang <fr...@gmail.com>
AuthorDate: Tue Jan 25 10:47:02 2022 -0500

    [CXF-8644]introduce a cache for AbstractJAXBProvider to avoid unnecessary ObjectFactory.class|jaxb.index availability check
    
    (cherry picked from commit 02c81854625e2e362e66b4af41f53341df4c4fb7)
---
 .../org/apache/cxf/jaxrs/provider/AbstractJAXBProvider.java   | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

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 f2bee17..5510438 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
@@ -101,6 +101,7 @@ public abstract class AbstractJAXBProvider<T> extends AbstractConfigurableProvid
     protected Set<Class<?>> collectionContextClasses = ConcurrentHashMap.newKeySet();
 
     protected Map<String, String> jaxbElementClassMap = Collections.emptyMap();
+    protected Map<String, Boolean> objectFactoryOrIndexMap = new ConcurrentHashMap<>();
     protected boolean unmarshalAsJaxbElement;
     protected boolean marshalAsJaxbElement;
     protected boolean xmlTypeAsJaxbElementOnly;
@@ -594,8 +595,15 @@ public abstract class AbstractJAXBProvider<T> extends AbstractConfigurableProvid
     }
 
     protected boolean objectFactoryOrIndexAvailable(Class<?> type) {
-        return type.getResource("ObjectFactory.class") != null
+        if (this.objectFactoryOrIndexMap.get(type.getName()) != null) {
+            return this.objectFactoryOrIndexMap.get(type.getName());
+        } else {
+            boolean ret = type.getResource("ObjectFactory.class") != null
                || type.getResource("jaxb.index") != null;
+            this.objectFactoryOrIndexMap.put(type.getName(), ret);
+            return ret;
+        }
+        
     }
 
     private boolean objectFactoryForType(Type genericType) {
@@ -704,6 +712,7 @@ public abstract class AbstractJAXBProvider<T> extends AbstractConfigurableProvid
     public void clearContexts() {
         classContexts.clear();
         packageContexts.clear();
+        objectFactoryOrIndexMap.clear();
     }
 
     //TODO: move these methods into the dedicated utility class