You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by am...@apache.org on 2020/10/29 16:21:14 UTC

[cxf] branch master updated: Reduce classloading on Rest Client init

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 8d62ad9  Reduce classloading on Rest Client init
     new 51707c7  Merge pull request #715 from andymc12/master
8d62ad9 is described below

commit 8d62ad92dbd57e8bb99e0704ffde0faf66b719b7
Author: Andy McCright <j....@gmail.com>
AuthorDate: Tue Oct 27 16:34:05 2020 -0500

    Reduce classloading on Rest Client init
    
    Signed-off-by: Andy McCright <j....@gmail.com>
---
 .../client/MicroProfileClientProviderFactory.java  | 31 +++++++++++++---------
 1 file changed, 18 insertions(+), 13 deletions(-)

diff --git a/rt/rs/microprofile-client/src/main/java/org/apache/cxf/microprofile/client/MicroProfileClientProviderFactory.java b/rt/rs/microprofile-client/src/main/java/org/apache/cxf/microprofile/client/MicroProfileClientProviderFactory.java
index ddfc0b5..a41e2b3 100644
--- a/rt/rs/microprofile-client/src/main/java/org/apache/cxf/microprofile/client/MicroProfileClientProviderFactory.java
+++ b/rt/rs/microprofile-client/src/main/java/org/apache/cxf/microprofile/client/MicroProfileClientProviderFactory.java
@@ -41,10 +41,26 @@ import org.eclipse.microprofile.rest.client.ext.ResponseExceptionMapper;
 
 public final class MicroProfileClientProviderFactory extends ProviderFactory {
     static final String CLIENT_FACTORY_NAME = MicroProfileClientProviderFactory.class.getName();
+    private static final Class<?> ASYNC_II_FACTORY_CLASS;
     private static final Logger LOG = LogUtils.getL7dLogger(MicroProfileClientProviderFactory.class);
     private List<ProviderInfo<ResponseExceptionMapper<?>>> responseExceptionMappers = new ArrayList<>(1);
     private List<ProviderInfo<Object>> asyncInvocationInterceptorFactories = new ArrayList<>();
     private final Comparator<ProviderInfo<?>> comparator;
+    
+
+    static {
+        Class<?> c;
+        try {
+            c = ClassLoaderUtils.loadClass("org.eclipse.microprofile.rest.client.ext.AsyncInvocationInterceptorFactory",
+                                           MicroProfileClientProviderFactory.class);
+        } catch (ClassNotFoundException ex) {
+            // expected if using the MP Rest Client 1.0 APIs
+            c = null;
+            LOG.log(Level.FINEST, ex, () -> {
+                return "Caught ClassNotFoundException - expected if using MP Rest Client 1.0 APIs"; });
+        }
+        ASYNC_II_FACTORY_CLASS = c;
+    }
 
     private MicroProfileClientProviderFactory(Bus bus, Comparator<ProviderInfo<?>> comparator) {
         super(bus);
@@ -87,20 +103,9 @@ public final class MicroProfileClientProviderFactory extends ProviderFactory {
             if (ResponseExceptionMapper.class.isAssignableFrom(providerCls)) {
                 addProviderToList(responseExceptionMappers, provider);
             }
-            String className = "org.eclipse.microprofile.rest.client.ext.AsyncInvocationInterceptorFactory";
-            try {
-                
-                Class<?> asyncIIFactoryClass = ClassLoaderUtils.loadClass(className,
-                                                                          MicroProfileClientProviderFactory.class);
-                if (asyncIIFactoryClass.isAssignableFrom(providerCls)) {
-                    addProviderToList(asyncInvocationInterceptorFactories, provider);
-                }
-            } catch (ClassNotFoundException ex) {
-                // expected if using the MP Rest Client 1.0 APIs
-                LOG.log(Level.FINEST, ex, () -> {
-                    return "Caught ClassNotFoundException - expected if using MP Rest Client 1.0 APIs"; });
+            if (ASYNC_II_FACTORY_CLASS != null && ASYNC_II_FACTORY_CLASS.isAssignableFrom(providerCls)) {
+                addProviderToList(asyncInvocationInterceptorFactories, provider);
             }
-
         }
         responseExceptionMappers.sort(comparator);
         asyncInvocationInterceptorFactories.sort(comparator);