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 2019/03/08 22:51:48 UTC

[cxf] branch master updated: [CXF-7992] Use only one instance of each async interceptor per request

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 eccb71e  [CXF-7992] Use only one instance of each async interceptor per request
eccb71e is described below

commit eccb71ea477a36747914d7f17908cc6d591d390b
Author: Andy McCright <j....@gmail.com>
AuthorDate: Fri Mar 8 16:51:22 2019 -0600

    [CXF-7992] Use only one instance of each async interceptor per request
---
 .../proxy/MPAsyncInvocationInterceptorImpl.java     |  2 +-
 .../MPAsyncInvocationInterceptorPostAsyncImpl.java  | 21 +++++++++++----------
 ...AsyncInvocationInterceptorRemoveContextImpl.java | 21 +++++++++++----------
 .../client/proxy/MicroProfileClientProxyImpl.java   | 18 +++++++++++-------
 systests/microprofile/pom.xml                       |  2 +-
 5 files changed, 35 insertions(+), 29 deletions(-)

diff --git a/rt/rs/microprofile-client/src/main/java/org/apache/cxf/microprofile/client/proxy/MPAsyncInvocationInterceptorImpl.java b/rt/rs/microprofile-client/src/main/java/org/apache/cxf/microprofile/client/proxy/MPAsyncInvocationInterceptorImpl.java
index 5871c8a..5c8c25f 100644
--- a/rt/rs/microprofile-client/src/main/java/org/apache/cxf/microprofile/client/proxy/MPAsyncInvocationInterceptorImpl.java
+++ b/rt/rs/microprofile-client/src/main/java/org/apache/cxf/microprofile/client/proxy/MPAsyncInvocationInterceptorImpl.java
@@ -40,7 +40,6 @@ public class MPAsyncInvocationInterceptorImpl extends AbstractPhaseInterceptor<M
 
     private final List<AsyncInvocationInterceptor> interceptors = new ArrayList<>();
 
-    
     MPAsyncInvocationInterceptorImpl(Message message) {
         super(Phase.POST_MARSHAL);
 
@@ -70,6 +69,7 @@ public class MPAsyncInvocationInterceptorImpl extends AbstractPhaseInterceptor<M
                         new Object[]{interceptors.get(i).getClass().getName(), t});
             }
         }
+        message.getExchange().put(MPAsyncInvocationInterceptorImpl.class, this);
     }
 
 }
diff --git a/rt/rs/microprofile-client/src/main/java/org/apache/cxf/microprofile/client/proxy/MPAsyncInvocationInterceptorPostAsyncImpl.java b/rt/rs/microprofile-client/src/main/java/org/apache/cxf/microprofile/client/proxy/MPAsyncInvocationInterceptorPostAsyncImpl.java
index d5c653b..86e722e 100644
--- a/rt/rs/microprofile-client/src/main/java/org/apache/cxf/microprofile/client/proxy/MPAsyncInvocationInterceptorPostAsyncImpl.java
+++ b/rt/rs/microprofile-client/src/main/java/org/apache/cxf/microprofile/client/proxy/MPAsyncInvocationInterceptorPostAsyncImpl.java
@@ -36,22 +36,23 @@ import org.eclipse.microprofile.rest.client.ext.AsyncInvocationInterceptor;
 public class MPAsyncInvocationInterceptorPostAsyncImpl extends AbstractPhaseInterceptor<Message> {
     private static final Logger LOG = LogUtils.getL7dLogger(MPAsyncInvocationInterceptorPostAsyncImpl.class);
 
-    private List<AsyncInvocationInterceptor> interceptors;
-
-    public MPAsyncInvocationInterceptorPostAsyncImpl(List<AsyncInvocationInterceptor> interceptors) {
+    public MPAsyncInvocationInterceptorPostAsyncImpl() {
         super(Phase.PRE_PROTOCOL);
-        this.interceptors = interceptors;
     }
 
     /** {@inheritDoc}*/
     @Override
     public void handleMessage(Message message) throws Fault {
-        for (AsyncInvocationInterceptor interceptor : interceptors) {
-            try {
-                interceptor.applyContext();
-            } catch (Throwable t) {
-                LOG.log(Level.WARNING, "ASYNC_INTERCEPTOR_EXCEPTION_APPLY_CONTEXT", 
-                        new Object[]{interceptor.getClass().getName(), t});
+        MPAsyncInvocationInterceptorImpl aiii = message.getExchange().get(MPAsyncInvocationInterceptorImpl.class);
+        if (aiii != null) {
+            List<AsyncInvocationInterceptor> interceptors = aiii.getInterceptors();
+            for (AsyncInvocationInterceptor interceptor : interceptors) {
+                try {
+                    interceptor.applyContext();
+                } catch (Throwable t) {
+                    LOG.log(Level.WARNING, "ASYNC_INTERCEPTOR_EXCEPTION_APPLY_CONTEXT", 
+                            new Object[]{interceptor.getClass().getName(), t});
+                }
             }
         }
     }
diff --git a/rt/rs/microprofile-client/src/main/java/org/apache/cxf/microprofile/client/proxy/MPAsyncInvocationInterceptorRemoveContextImpl.java b/rt/rs/microprofile-client/src/main/java/org/apache/cxf/microprofile/client/proxy/MPAsyncInvocationInterceptorRemoveContextImpl.java
index 8813ee4..9648388 100644
--- a/rt/rs/microprofile-client/src/main/java/org/apache/cxf/microprofile/client/proxy/MPAsyncInvocationInterceptorRemoveContextImpl.java
+++ b/rt/rs/microprofile-client/src/main/java/org/apache/cxf/microprofile/client/proxy/MPAsyncInvocationInterceptorRemoveContextImpl.java
@@ -36,22 +36,23 @@ import org.eclipse.microprofile.rest.client.ext.AsyncInvocationInterceptor;
 public class MPAsyncInvocationInterceptorRemoveContextImpl extends AbstractPhaseInterceptor<Message> {
     private static final Logger LOG = LogUtils.getL7dLogger(MPAsyncInvocationInterceptorRemoveContextImpl.class);
 
-    private List<AsyncInvocationInterceptor> interceptors;
-
-    public MPAsyncInvocationInterceptorRemoveContextImpl(List<AsyncInvocationInterceptor> interceptors) {
+    public MPAsyncInvocationInterceptorRemoveContextImpl() {
         super(Phase.POST_INVOKE);
-        this.interceptors = interceptors;
     }
 
     /** {@inheritDoc}*/
     @Override
     public void handleMessage(Message message) throws Fault {
-        for (AsyncInvocationInterceptor interceptor : interceptors) {
-            try {
-                interceptor.removeContext();
-            } catch (Throwable t) {
-                LOG.log(Level.WARNING, "ASYNC_INTERCEPTOR_EXCEPTION_REMOVE_CONTEXT", 
-                        new Object[]{interceptor.getClass().getName(), t});
+        MPAsyncInvocationInterceptorImpl aiii = message.getExchange().get(MPAsyncInvocationInterceptorImpl.class);
+        if (aiii != null) {
+            List<AsyncInvocationInterceptor> interceptors = aiii.getInterceptors();
+            for (AsyncInvocationInterceptor interceptor : interceptors) {
+                try {
+                    interceptor.removeContext();
+                } catch (Throwable t) {
+                    LOG.log(Level.WARNING, "ASYNC_INTERCEPTOR_EXCEPTION_REMOVE_CONTEXT", 
+                            new Object[]{interceptor.getClass().getName(), t});
+                }
             }
         }
     }
diff --git a/rt/rs/microprofile-client/src/main/java/org/apache/cxf/microprofile/client/proxy/MicroProfileClientProxyImpl.java b/rt/rs/microprofile-client/src/main/java/org/apache/cxf/microprofile/client/proxy/MicroProfileClientProxyImpl.java
index 81af0ed..98ff70b 100644
--- a/rt/rs/microprofile-client/src/main/java/org/apache/cxf/microprofile/client/proxy/MicroProfileClientProxyImpl.java
+++ b/rt/rs/microprofile-client/src/main/java/org/apache/cxf/microprofile/client/proxy/MicroProfileClientProxyImpl.java
@@ -93,6 +93,7 @@ public class MicroProfileClientProxyImpl extends ClientProxyImpl {
         }
         JAXRS_UTILS_GET_CURRENT_MESSAGE_METHOD = m;
     }
+
     private final CDIInterceptorWrapper interceptorWrapper;
     private Object objectInstance;
 
@@ -102,9 +103,8 @@ public class MicroProfileClientProxyImpl extends ClientProxyImpl {
                                        Configuration configuration, CDIInterceptorWrapper interceptorWrapper, 
                                        Object... varValues) {
         super(new LocalClientState(baseURI), loader, cri, isRoot, inheritHeaders, varValues);
-        cfg.getRequestContext().put(EXECUTOR_SERVICE_PROPERTY, executorService);
-        cfg.getRequestContext().putAll(configuration.getProperties());
         this.interceptorWrapper = interceptorWrapper;
+        init(executorService, configuration);
     }
 
     public MicroProfileClientProxyImpl(ClientState initialState, ClassLoader loader, ClassResourceInfo cri,
@@ -112,12 +112,19 @@ public class MicroProfileClientProxyImpl extends ClientProxyImpl {
                                        Configuration configuration, CDIInterceptorWrapper interceptorWrapper,
                                        Object... varValues) {
         super(initialState, loader, cri, isRoot, inheritHeaders, varValues);
-        cfg.getRequestContext().put(EXECUTOR_SERVICE_PROPERTY, executorService);
-        cfg.getRequestContext().putAll(configuration.getProperties());
         this.interceptorWrapper = interceptorWrapper;
+        init(executorService, configuration);
     }
     //CHECKSTYLE:ON
 
+    private void init(ExecutorService executorService, Configuration configuration) {
+        cfg.getRequestContext().put(EXECUTOR_SERVICE_PROPERTY, executorService);
+        cfg.getRequestContext().putAll(configuration.getProperties());
+
+        List<Interceptor<? extends Message>>inboundChain = cfg.getInInterceptors();
+        inboundChain.add(new MPAsyncInvocationInterceptorPostAsyncImpl());
+        inboundChain.add(new MPAsyncInvocationInterceptorRemoveContextImpl());
+    }
     @SuppressWarnings("unchecked")
     @Override
     protected InvocationCallback<Object> checkAsyncCallback(OperationResourceInfo ori,
@@ -142,9 +149,6 @@ public class MicroProfileClientProxyImpl extends ClientProxyImpl {
                                    InvocationCallback<Object> asyncCallback) {
         MPAsyncInvocationInterceptorImpl aiiImpl = new MPAsyncInvocationInterceptorImpl(outMessage);
         outMessage.getInterceptorChain().add(aiiImpl);
-        List<Interceptor<? extends Message>>inboundChain = cfg.getInInterceptors();
-        inboundChain.add(new MPAsyncInvocationInterceptorPostAsyncImpl(aiiImpl.getInterceptors()));
-        inboundChain.add(new MPAsyncInvocationInterceptorRemoveContextImpl(aiiImpl.getInterceptors()));
 
         setTimeouts(cfg.getRequestContext());
         super.doInvokeAsync(ori, outMessage, asyncCallback);
diff --git a/systests/microprofile/pom.xml b/systests/microprofile/pom.xml
index 2b9e2e5..ca32506 100644
--- a/systests/microprofile/pom.xml
+++ b/systests/microprofile/pom.xml
@@ -33,7 +33,7 @@
     <url>http://cxf.apache.org</url>
     <properties>
         <cxf.geronimo.config.version>1.0</cxf.geronimo.config.version>
-        <cxf.microprofile.rest.client.version>1.2.0</cxf.microprofile.rest.client.version>
+        <cxf.microprofile.rest.client.version>1.2.1</cxf.microprofile.rest.client.version>
         <cxf.wiremock.params>--port=8765</cxf.wiremock.params>
         <cxf.weld.se.version>2.4.5.Final</cxf.weld.se.version>
         <cxf.arquillian.weld.container.version>2.0.0.Final</cxf.arquillian.weld.container.version>