You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by re...@apache.org on 2020/05/31 16:22:51 UTC
[cxf] branch master updated: CXF-8286:
AbstractStaticFailoverStrategy.getEndpoints() never returns anything for
JAX-RS clients (with RetryStrategy) (#674)
This is an automated email from the ASF dual-hosted git repository.
reta 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 29740df CXF-8286: AbstractStaticFailoverStrategy.getEndpoints() never returns anything for JAX-RS clients (with RetryStrategy) (#674)
29740df is described below
commit 29740df5fd2341230f357684b4c0c3b208a6a05a
Author: Andriy Redko <dr...@gmail.com>
AuthorDate: Sun May 31 12:22:41 2020 -0400
CXF-8286: AbstractStaticFailoverStrategy.getEndpoints() never returns anything for JAX-RS clients (with RetryStrategy) (#674)
---
.../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 229bbac..68535cc 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 7aae794..cc99065 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;
@@ -99,7 +100,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);
@@ -114,4 +114,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