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

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


The following commit(s) were added to refs/heads/3.2.x-fixes by this push:
     new 0562c34  CXF-8286: AbstractStaticFailoverStrategy.getEndpoints() never 
returns anything for JAX-RS clients (with RetryStrategy) (#674)
0562c34 is described below

commit 0562c34824f0469b7df67042e1ecba868351925d
Author: Andriy Redko <[email protected]>
AuthorDate: Sun May 31 12:22:41 2020 -0400

    CXF-8286: AbstractStaticFailoverStrategy.getEndpoints() never returns 
anything for JAX-RS clients (with RetryStrategy) (#674)
    
    (cherry picked from commit 29740df5fd2341230f357684b4c0c3b208a6a05a)
    (cherry picked from commit 4a281debdff3b68679a353e88328b66a8524450f)
---
 .../clustering/AbstractStaticFailoverStrategy.java |  8 ++++
 .../jaxrs/failover/FailoverWebClientTest.java      | 50 +++++++++++++++++++++-
 2 files changed, 57 insertions(+), 1 deletion(-)

diff --git 
a/rt/features/clustering/src/main/java/org/apache/cxf/clustering/AbstractStaticFailoverStrategy.java
 
b/rt/features/clustering/src/main/java/org/apache/cxf/clustering/AbstractStaticFailoverStrategy.java
index 599f5e8..83049ff 100644
--- 
a/rt/features/clustering/src/main/java/org/apache/cxf/clustering/AbstractStaticFailoverStrategy.java
+++ 
b/rt/features/clustering/src/main/java/org/apache/cxf/clustering/AbstractStaticFailoverStrategy.java
@@ -21,6 +21,7 @@ package org.apache.cxf.clustering;
 
 import java.util.ArrayList;
 import java.util.Collection;
+import java.util.Collections;
 import java.util.List;
 import java.util.logging.Level;
 import java.util.logging.Logger;
@@ -133,6 +134,13 @@ public abstract class AbstractStaticFailoverStrategy 
implements FailoverStrategy
     protected List<Endpoint> getEndpoints(Exchange exchange, boolean 
acceptCandidatesWithSameAddress) {
         Endpoint endpoint = exchange.getEndpoint();
         Collection<ServiceInfo> services = 
endpoint.getService().getServiceInfos();
+        
+        // If there are no services associated with this endpoint (often in 
case of JAX-RS), 
+        // returning the endpoint itself if allowed.
+        if (services.isEmpty() && acceptCandidatesWithSameAddress) {
+            return Collections.singletonList(endpoint);
+        }
+        
         QName currentBinding = 
endpoint.getBinding().getBindingInfo().getName();
         List<Endpoint> alternates = new ArrayList<>();
         for (ServiceInfo service : services) {
diff --git 
a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/failover/FailoverWebClientTest.java
 
b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/failover/FailoverWebClientTest.java
index 7bcfbc2..2489dd3 100644
--- 
a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/failover/FailoverWebClientTest.java
+++ 
b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/failover/FailoverWebClientTest.java
@@ -27,6 +27,7 @@ import java.util.List;
 import org.apache.cxf.clustering.FailoverFeature;
 import org.apache.cxf.clustering.RetryStrategy;
 import org.apache.cxf.clustering.SequentialStrategy;
+import org.apache.cxf.clustering.circuitbreaker.CircuitBreakerFailoverFeature;
 import org.apache.cxf.jaxrs.client.JAXRSClientFactoryBean;
 import org.apache.cxf.jaxrs.client.WebClient;
 import org.apache.cxf.jaxrs.model.AbstractResourceInfo;
@@ -96,7 +97,6 @@ public class FailoverWebClientTest extends 
AbstractBusClientServerTestBase {
 
         final FailoverFeature feature = new FailoverFeature();
         RetryStrategy strategy = new RetryStrategy();
-        strategy.setAlternateAddresses(Arrays.asList(address));
         strategy.setMaxNumberOfRetries(5);
         feature.setStrategy(strategy);
 
@@ -111,4 +111,52 @@ public class FailoverWebClientTest extends 
AbstractBusClientServerTestBase {
         assertEquals("root", b.getName());
         assertEquals(address, webClient.getBaseURI().toString());
     }
+    
+    @Test
+    public void testCircuitBreakerRetryFailover() throws Exception {
+        String address = "http://localhost:"; + PORT1 + 
"/bookstore/unavailable";
+
+        final CircuitBreakerFailoverFeature feature = new 
CircuitBreakerFailoverFeature();
+        feature.setThreshold(5);
+        RetryStrategy strategy = new RetryStrategy();
+        strategy.setMaxNumberOfRetries(5);
+        strategy.setDelayBetweenRetries(1000);
+        feature.setStrategy(strategy);
+
+        final JAXRSClientFactoryBean bean = new JAXRSClientFactoryBean();
+        bean.setAddress(address);
+        bean.setFeatures(Arrays.asList(feature));
+        bean.setServiceClass(FailoverBookStore.class);
+        WebClient webClient = bean.createWebClient();
+        
+        final Book b = webClient.get(Book.class);
+        assertEquals(124L, b.getId());
+        assertEquals("root", b.getName());
+        assertEquals(address, webClient.getBaseURI().toString());
+    }
+
+    @Test
+    public void testRetryFailoverAlternateAddresses() throws Exception {
+        String address = "http://localhost:"; + AbstractFailoverTest.NON_PORT + 
"/bookstore/unavailable";
+
+        final FailoverFeature feature = new FailoverFeature();
+        RetryStrategy strategy = new RetryStrategy();
+        strategy.setAlternateAddresses(Arrays.asList("http://localhost:"; + 
PORT1 + "/bookstore/unavailable"));
+        strategy.setMaxNumberOfRetries(5);
+        strategy.setDelayBetweenRetries(500);
+        feature.setStrategy(strategy);
+
+        final JAXRSClientFactoryBean bean = new JAXRSClientFactoryBean();
+        bean.setAddress(address);
+        bean.setFeatures(Arrays.asList(feature));
+        bean.setServiceClass(FailoverBookStore.class);
+        WebClient webClient = bean.createWebClient();
+        
+        final Book b = webClient.get(Book.class);
+        assertEquals(124L, b.getId());
+        assertEquals("root", b.getName());
+        assertEquals("http://localhost:"; + PORT1 + "/bookstore/unavailable",
+            webClient.getBaseURI().toString());
+    }
+
 }
\ No newline at end of file

Reply via email to