cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject cxf git commit: [CXF-7135] Updating JAX-RS code to wait until the exchange completes when JMS is used, with thanks to Dan Kulp
Date Fri, 25 Nov 2016 14:52:57 GMT
Repository: cxf
Updated Branches:
  refs/heads/3.0.x-fixes 33e428428 -> 062eea9c6


[CXF-7135] Updating JAX-RS code to wait until the exchange completes when JMS is used, with
thanks to Dan Kulp


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

Branch: refs/heads/3.0.x-fixes
Commit: 062eea9c61f9da913fd628b7ffe0984a435b8005
Parents: 33e4284
Author: Sergey Beryozkin <sberyozkin@gmail.com>
Authored: Fri Nov 25 14:52:40 2016 +0000
Committer: Sergey Beryozkin <sberyozkin@gmail.com>
Committed: Fri Nov 25 14:52:40 2016 +0000

----------------------------------------------------------------------
 .../apache/cxf/jaxrs/client/AbstractClient.java | 35 ++++++++++++++++++++
 1 file changed, 35 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/062eea9c/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/AbstractClient.java
----------------------------------------------------------------------
diff --git a/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/AbstractClient.java b/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/AbstractClient.java
index b162fc7..d37de1c 100644
--- a/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/AbstractClient.java
+++ b/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/AbstractClient.java
@@ -121,6 +121,7 @@ public abstract class AbstractClient implements Client {
     private AtomicBoolean closed = new AtomicBoolean(); 
     protected AbstractClient(ClientState initialState) {
         this.state = initialState;
+        cfg.getInInterceptors().add(new InChainCompleteResponseInterceptor());
     }
     
     /**
@@ -555,6 +556,18 @@ public abstract class AbstractClient implements Client {
         Exchange exchange = message.getExchange(); 
       
         Exception ex = message.getContent(Exception.class);
+        if (ex == null) {
+            ex = message.getExchange().get(Exception.class);
+        }
+        if (ex == null && !exchange.isOneWay()) {
+            synchronized (exchange) {
+                while (exchange.get("IN_CHAIN_COMPLETE") == null) {
+                    exchange.wait(cfg.getSynchronousTimeout());
+                }
+            }
+        }
+        ex = message.getContent(Exception.class);
+        
         if (ex != null
             || PropertyUtils.isTrue(exchange.get(SERVICE_NOT_AVAIL_PROPERTY))
                 && PropertyUtils.isTrue(exchange.get(COMPLETE_IF_SERVICE_NOT_AVAIL_PROPERTY)))
{
@@ -1135,4 +1148,26 @@ public abstract class AbstractClient implements Client {
             
         }
     }
+    protected static class InChainCompleteResponseInterceptor extends AbstractPhaseInterceptor<Message>
{
+        InChainCompleteResponseInterceptor() {
+            super(Phase.UNMARSHAL);
+        }
+
+        @Override
+        public void handleMessage(Message message) throws Fault {
+            synchronized (message.getExchange()) {
+                message.getExchange().put("IN_CHAIN_COMPLETE", Boolean.TRUE);
+                message.getExchange().notifyAll();
+            }
+        }
+
+        @Override
+        public void handleFault(Message message) {
+            synchronized (message.getExchange()) {
+                message.getExchange().put("IN_CHAIN_COMPLETE", Boolean.TRUE);
+                message.getExchange().notifyAll();
+            }
+        }
+
+    }
 }


Mime
View raw message