fallbackPublisher = fallback.apply(getExecutionException());
- return RxReactiveStreams.toObservable(fallbackPublisher);
- }
- return super.resumeWithFallback();
- }
-
- }
-
-}
diff --git a/spring-cloud-netflix-hystrix/src/main/java/org/springframework/cloud/netflix/hystrix/HystrixConstants.java b/spring-cloud-netflix-hystrix/src/main/java/org/springframework/cloud/netflix/hystrix/HystrixConstants.java
deleted file mode 100644
index f4a035b55..000000000
--- a/spring-cloud-netflix-hystrix/src/main/java/org/springframework/cloud/netflix/hystrix/HystrixConstants.java
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- * Copyright 2013-2019 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * https://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.springframework.cloud.netflix.hystrix;
-
-/**
- * @author Spencer Gibb
- */
-public final class HystrixConstants {
-
- /**
- * Hystrix stream destination name.
- */
- public static final String HYSTRIX_STREAM_DESTINATION = "springCloudHystrixStream";
-
- private HystrixConstants() {
- throw new AssertionError("Must not instantiate constant utility class");
- }
-
-}
diff --git a/spring-cloud-netflix-hystrix/src/main/java/org/springframework/cloud/netflix/hystrix/HystrixHealthIndicator.java b/spring-cloud-netflix-hystrix/src/main/java/org/springframework/cloud/netflix/hystrix/HystrixHealthIndicator.java
deleted file mode 100644
index 838ce1dbe..000000000
--- a/spring-cloud-netflix-hystrix/src/main/java/org/springframework/cloud/netflix/hystrix/HystrixHealthIndicator.java
+++ /dev/null
@@ -1,68 +0,0 @@
-/*
- * Copyright 2013-2019 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * https://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.springframework.cloud.netflix.hystrix;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import com.netflix.hystrix.HystrixCircuitBreaker;
-import com.netflix.hystrix.HystrixCommandMetrics;
-
-import org.springframework.boot.actuate.health.AbstractHealthIndicator;
-import org.springframework.boot.actuate.health.Health.Builder;
-import org.springframework.boot.actuate.health.HealthIndicator;
-import org.springframework.boot.actuate.health.Status;
-
-/**
- * A {@link HealthIndicator} implementation for Hystrix circuit breakers.
- *
- * This default implementation will not change the system state (e.g. OK) but
- * includes all open circuits by name.
- *
- * @author Christian Dupuis
- */
-public class HystrixHealthIndicator extends AbstractHealthIndicator {
-
- private static final Status CIRCUIT_OPEN = new Status("CIRCUIT_OPEN");
-
- @Override
- protected void doHealthCheck(Builder builder) throws Exception {
- List openCircuitBreakers = new ArrayList<>();
-
- // Collect all open circuit breakers from Hystrix
- for (HystrixCommandMetrics metrics : HystrixCommandMetrics.getInstances()) {
- HystrixCircuitBreaker circuitBreaker = HystrixCircuitBreaker.Factory
- .getInstance(metrics.getCommandKey());
- if (circuitBreaker != null && circuitBreaker.isOpen()) {
- openCircuitBreakers.add(metrics.getCommandGroup().name() + "::"
- + metrics.getCommandKey().name());
- }
- }
-
- // If there is at least one open circuit report OUT_OF_SERVICE adding the command
- // group
- // and key name
- if (!openCircuitBreakers.isEmpty()) {
- builder.status(CIRCUIT_OPEN).withDetail("openCircuitBreakers",
- openCircuitBreakers);
- }
- else {
- builder.up();
- }
- }
-
-}
diff --git a/spring-cloud-netflix-hystrix/src/main/java/org/springframework/cloud/netflix/hystrix/HystrixMetricsProperties.java b/spring-cloud-netflix-hystrix/src/main/java/org/springframework/cloud/netflix/hystrix/HystrixMetricsProperties.java
deleted file mode 100644
index dc45c3ead..000000000
--- a/spring-cloud-netflix-hystrix/src/main/java/org/springframework/cloud/netflix/hystrix/HystrixMetricsProperties.java
+++ /dev/null
@@ -1,77 +0,0 @@
-/*
- * Copyright 2013-2019 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * https://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.springframework.cloud.netflix.hystrix;
-
-import java.util.Objects;
-
-import org.springframework.boot.context.properties.ConfigurationProperties;
-
-/**
- * @author Venil Noronha
- * @author Gregor Zurowski
- */
-@ConfigurationProperties("hystrix.metrics")
-public class HystrixMetricsProperties {
-
- /** Enable Hystrix metrics polling. Defaults to true. */
- private boolean enabled = true;
-
- /** Interval between subsequent polling of metrics. Defaults to 2000 ms. */
- private Integer pollingIntervalMs = 2000;
-
- public boolean isEnabled() {
- return enabled;
- }
-
- public void setEnabled(boolean enabled) {
- this.enabled = enabled;
- }
-
- public Integer getPollingIntervalMs() {
- return pollingIntervalMs;
- }
-
- public void setPollingIntervalMs(Integer pollingIntervalMs) {
- this.pollingIntervalMs = pollingIntervalMs;
- }
-
- @Override
- public boolean equals(Object o) {
- if (this == o) {
- return true;
- }
- if (o == null || getClass() != o.getClass()) {
- return false;
- }
- HystrixMetricsProperties that = (HystrixMetricsProperties) o;
- return enabled == that.enabled
- && Objects.equals(pollingIntervalMs, that.pollingIntervalMs);
- }
-
- @Override
- public int hashCode() {
- return Objects.hash(enabled, pollingIntervalMs);
- }
-
- @Override
- public String toString() {
- return new StringBuilder("HystrixMetricsProperties{").append("enabled=")
- .append(enabled).append(", ").append("pollingIntervalMs=")
- .append(pollingIntervalMs).append("}").toString();
- }
-
-}
diff --git a/spring-cloud-netflix-hystrix/src/main/java/org/springframework/cloud/netflix/hystrix/HystrixProperties.java b/spring-cloud-netflix-hystrix/src/main/java/org/springframework/cloud/netflix/hystrix/HystrixProperties.java
deleted file mode 100644
index a08fb0ce0..000000000
--- a/spring-cloud-netflix-hystrix/src/main/java/org/springframework/cloud/netflix/hystrix/HystrixProperties.java
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- * Copyright 2013-2019 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * https://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.springframework.cloud.netflix.hystrix;
-
-import java.util.HashMap;
-import java.util.Map;
-
-import org.springframework.boot.context.properties.ConfigurationProperties;
-
-/**
- * Configuration properties for Hystrix Servlet.
- *
- * @author Spencer Gibb
- * @since 2.0.0
- */
-@ConfigurationProperties(prefix = "management.endpoint.hystrix")
-public class HystrixProperties {
-
- /**
- * Hystrix settings. These are traditionally set using servlet parameters. Refer to
- * the documentation of Hystrix for more details.
- */
- private final Map config = new HashMap<>();
-
- public Map getConfig() {
- return this.config;
- }
-
-}
diff --git a/spring-cloud-netflix-hystrix/src/main/java/org/springframework/cloud/netflix/hystrix/HystrixStreamEndpoint.java b/spring-cloud-netflix-hystrix/src/main/java/org/springframework/cloud/netflix/hystrix/HystrixStreamEndpoint.java
deleted file mode 100644
index f4982aaee..000000000
--- a/spring-cloud-netflix-hystrix/src/main/java/org/springframework/cloud/netflix/hystrix/HystrixStreamEndpoint.java
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * Copyright 2013-2019 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * https://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.springframework.cloud.netflix.hystrix;
-
-import java.util.Map;
-import java.util.function.Supplier;
-
-import com.netflix.hystrix.contrib.metrics.eventstream.HystrixMetricsStreamServlet;
-
-import org.springframework.boot.actuate.endpoint.web.EndpointServlet;
-import org.springframework.boot.actuate.endpoint.web.annotation.ServletEndpoint;
-
-/**
- * {@link org.springframework.boot.actuate.endpoint.annotation.Endpoint} to expose a
- * Jolokia {@link HystrixMetricsStreamServlet}.
- *
- * @author Phillip Webb
- * @since 2.0.0
- */
-@ServletEndpoint(id = "hystrix.stream")
-public class HystrixStreamEndpoint implements Supplier {
-
- private final Map initParameters;
-
- public HystrixStreamEndpoint(Map initParameters) {
- this.initParameters = initParameters;
- }
-
- @Override
- public EndpointServlet get() {
- return new EndpointServlet(HystrixMetricsStreamServlet.class)
- .withInitParameters(this.initParameters);
- }
-
-}
diff --git a/spring-cloud-netflix-hystrix/src/main/java/org/springframework/cloud/netflix/hystrix/HystrixWebfluxEndpoint.java b/spring-cloud-netflix-hystrix/src/main/java/org/springframework/cloud/netflix/hystrix/HystrixWebfluxEndpoint.java
deleted file mode 100644
index 80fda4ca0..000000000
--- a/spring-cloud-netflix-hystrix/src/main/java/org/springframework/cloud/netflix/hystrix/HystrixWebfluxEndpoint.java
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * Copyright 2013-2019 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * https://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.springframework.cloud.netflix.hystrix;
-
-import java.time.Duration;
-
-import org.reactivestreams.Publisher;
-import reactor.core.publisher.Flux;
-
-import org.springframework.boot.actuate.endpoint.web.annotation.RestControllerEndpoint;
-import org.springframework.http.MediaType;
-import org.springframework.web.bind.annotation.GetMapping;
-
-/**
- * @author Spencer Gibb
- */
-@RestControllerEndpoint(id = "hystrix.stream")
-public class HystrixWebfluxEndpoint {
-
- private final Flux stream;
-
- public HystrixWebfluxEndpoint(Publisher dashboardData) {
- stream = Flux.interval(Duration.ofMillis(500)).map(aLong -> "{\"type\":\"ping\"}")
- .mergeWith(dashboardData).share();
- }
-
- // path needs to be empty, so it registers correct as /actuator/hystrix.stream
- @GetMapping(path = "", produces = MediaType.TEXT_EVENT_STREAM_VALUE)
- public Flux hystrixStream() {
- return stream;
- }
-
-}
diff --git a/spring-cloud-netflix-hystrix/src/main/java/org/springframework/cloud/netflix/hystrix/ReactiveHystrixCircuitBreaker.java b/spring-cloud-netflix-hystrix/src/main/java/org/springframework/cloud/netflix/hystrix/ReactiveHystrixCircuitBreaker.java
deleted file mode 100644
index 699a0481f..000000000
--- a/spring-cloud-netflix-hystrix/src/main/java/org/springframework/cloud/netflix/hystrix/ReactiveHystrixCircuitBreaker.java
+++ /dev/null
@@ -1,84 +0,0 @@
-/*
- * Copyright 2013-2018 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * https://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.springframework.cloud.netflix.hystrix;
-
-import java.util.function.Function;
-
-import com.netflix.hystrix.HystrixObservableCommand;
-import org.reactivestreams.Publisher;
-import reactor.core.publisher.Flux;
-import reactor.core.publisher.Mono;
-import rx.Observable;
-import rx.RxReactiveStreams;
-import rx.Subscription;
-
-import org.springframework.cloud.client.circuitbreaker.ReactiveCircuitBreaker;
-
-/**
- * @author Ryan Baxter
- */
-public class ReactiveHystrixCircuitBreaker implements ReactiveCircuitBreaker {
-
- private HystrixObservableCommand.Setter setter;
-
- public ReactiveHystrixCircuitBreaker(HystrixObservableCommand.Setter setter) {
- this.setter = setter;
- }
-
- @Override
- public Mono run(Mono toRun, Function> fallback) {
- HystrixObservableCommand command = createCommand(toRun, fallback);
-
- return Mono.create(s -> {
- Subscription sub = command.toObservable().subscribe(s::success, s::error,
- s::success);
- s.onCancel(sub::unsubscribe);
- });
- }
-
- @Override
- public Flux run(Flux toRun, Function> fallback) {
- HystrixObservableCommand command = createCommand(toRun, fallback);
-
- return Flux.create(s -> {
- Subscription sub = command.toObservable().subscribe(s::next, s::error,
- s::complete);
- s.onCancel(sub::unsubscribe);
- });
- }
-
- private HystrixObservableCommand createCommand(Publisher toRun,
- Function fallback) {
- HystrixObservableCommand command = new HystrixObservableCommand(setter) {
- @Override
- protected Observable construct() {
- return RxReactiveStreams.toObservable(toRun);
- }
-
- @Override
- protected Observable resumeWithFallback() {
- if (fallback == null) {
- super.resumeWithFallback();
- }
- return RxReactiveStreams.toObservable(
- (Publisher) fallback.apply(this.getExecutionException()));
- }
- };
- return command;
- }
-
-}
diff --git a/spring-cloud-netflix-hystrix/src/main/java/org/springframework/cloud/netflix/hystrix/ReactiveHystrixCircuitBreakerAutoConfiguration.java b/spring-cloud-netflix-hystrix/src/main/java/org/springframework/cloud/netflix/hystrix/ReactiveHystrixCircuitBreakerAutoConfiguration.java
deleted file mode 100644
index ff9459a25..000000000
--- a/spring-cloud-netflix-hystrix/src/main/java/org/springframework/cloud/netflix/hystrix/ReactiveHystrixCircuitBreakerAutoConfiguration.java
+++ /dev/null
@@ -1,52 +0,0 @@
-/*
- * Copyright 2013-2019 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * https://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.springframework.cloud.netflix.hystrix;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
-import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
-import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
-import org.springframework.cloud.client.circuitbreaker.Customizer;
-import org.springframework.cloud.client.circuitbreaker.ReactiveCircuitBreakerFactory;
-import org.springframework.context.annotation.Bean;
-import org.springframework.context.annotation.Configuration;
-
-/**
- * @author Eric Bussieres
- */
-@Configuration(proxyBeanMethods = false)
-@ConditionalOnClass(name = { "reactor.core.publisher.Mono", "reactor.core.publisher.Flux",
- "com.netflix.hystrix.Hystrix" })
-@ConditionalOnProperty(name = "spring.cloud.circuitbreaker.hystrix.enabled",
- matchIfMissing = true)
-public class ReactiveHystrixCircuitBreakerAutoConfiguration {
-
- @Autowired(required = false)
- private List> customizers = new ArrayList<>();
-
- @Bean
- @ConditionalOnMissingBean(ReactiveCircuitBreakerFactory.class)
- public ReactiveHystrixCircuitBreakerFactory reactiveHystrixCircuitBreakerFactory() {
- ReactiveHystrixCircuitBreakerFactory factory = new ReactiveHystrixCircuitBreakerFactory();
- customizers.forEach(customizer -> customizer.customize(factory));
- return factory;
- }
-
-}
diff --git a/spring-cloud-netflix-hystrix/src/main/java/org/springframework/cloud/netflix/hystrix/ReactiveHystrixCircuitBreakerFactory.java b/spring-cloud-netflix-hystrix/src/main/java/org/springframework/cloud/netflix/hystrix/ReactiveHystrixCircuitBreakerFactory.java
deleted file mode 100644
index db8a70eb7..000000000
--- a/spring-cloud-netflix-hystrix/src/main/java/org/springframework/cloud/netflix/hystrix/ReactiveHystrixCircuitBreakerFactory.java
+++ /dev/null
@@ -1,75 +0,0 @@
-/*
- * Copyright 2013-2018 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * https://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.springframework.cloud.netflix.hystrix;
-
-import java.util.function.Function;
-
-import com.netflix.hystrix.HystrixCommandGroupKey;
-import com.netflix.hystrix.HystrixCommandKey;
-import com.netflix.hystrix.HystrixObservableCommand;
-
-import org.springframework.cloud.client.circuitbreaker.ReactiveCircuitBreaker;
-import org.springframework.cloud.client.circuitbreaker.ReactiveCircuitBreakerFactory;
-import org.springframework.util.Assert;
-
-/**
- * @author Ryan Baxter
- */
-public class ReactiveHystrixCircuitBreakerFactory extends
- ReactiveCircuitBreakerFactory {
-
- private Function defaultConfiguration = id -> HystrixObservableCommand.Setter
- .withGroupKey(
- HystrixCommandGroupKey.Factory.asKey(getClass().getSimpleName()))
- .andCommandKey(HystrixCommandKey.Factory.asKey(id));
-
- @Override
- protected ReactiveHystrixConfigBuilder configBuilder(String id) {
- return new ReactiveHystrixConfigBuilder(id);
- }
-
- @Override
- public void configureDefault(
- Function defaultConfiguration) {
- this.defaultConfiguration = defaultConfiguration;
- }
-
- @Override
- public ReactiveCircuitBreaker create(String id) {
- Assert.hasText(id, "A CircuitBreaker must have an id.");
- HystrixObservableCommand.Setter setter = getConfigurations().computeIfAbsent(id,
- defaultConfiguration);
- return new ReactiveHystrixCircuitBreaker(setter);
- }
-
- public static class ReactiveHystrixConfigBuilder
- extends AbstractHystrixConfigBuilder {
-
- public ReactiveHystrixConfigBuilder(String id) {
- super(id);
- }
-
- @Override
- public HystrixObservableCommand.Setter build() {
- return HystrixObservableCommand.Setter.withGroupKey(getGroupKey())
- .andCommandKey(getCommandKey())
- .andCommandPropertiesDefaults(getCommandPropertiesSetter());
- }
-
- }
-
-}
diff --git a/spring-cloud-netflix-hystrix/src/main/java/org/springframework/cloud/netflix/hystrix/security/HystrixSecurityAutoConfiguration.java b/spring-cloud-netflix-hystrix/src/main/java/org/springframework/cloud/netflix/hystrix/security/HystrixSecurityAutoConfiguration.java
deleted file mode 100644
index 8d4bb55ba..000000000
--- a/spring-cloud-netflix-hystrix/src/main/java/org/springframework/cloud/netflix/hystrix/security/HystrixSecurityAutoConfiguration.java
+++ /dev/null
@@ -1,111 +0,0 @@
-/*
- * Copyright 2013-2019 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * https://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.springframework.cloud.netflix.hystrix.security;
-
-import javax.annotation.PostConstruct;
-
-import com.netflix.hystrix.Hystrix;
-import com.netflix.hystrix.strategy.HystrixPlugins;
-import com.netflix.hystrix.strategy.concurrency.HystrixConcurrencyStrategy;
-import com.netflix.hystrix.strategy.concurrency.HystrixConcurrencyStrategyDefault;
-import com.netflix.hystrix.strategy.eventnotifier.HystrixEventNotifier;
-import com.netflix.hystrix.strategy.executionhook.HystrixCommandExecutionHook;
-import com.netflix.hystrix.strategy.metrics.HystrixMetricsPublisher;
-import com.netflix.hystrix.strategy.properties.HystrixPropertiesStrategy;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.boot.autoconfigure.condition.AllNestedConditions;
-import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
-import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
-import org.springframework.cloud.netflix.hystrix.security.HystrixSecurityAutoConfiguration.HystrixSecurityCondition;
-import org.springframework.context.annotation.Conditional;
-import org.springframework.context.annotation.Configuration;
-import org.springframework.security.core.context.SecurityContext;
-
-/**
- * @author Daniel Lavoie
- */
-@Configuration(proxyBeanMethods = false)
-@Conditional(HystrixSecurityCondition.class)
-@ConditionalOnClass({ Hystrix.class, SecurityContext.class })
-public class HystrixSecurityAutoConfiguration {
-
- private static final Log LOGGER = LogFactory
- .getLog(HystrixSecurityAutoConfiguration.class);
-
- @Autowired(required = false)
- private HystrixConcurrencyStrategy existingConcurrencyStrategy;
-
- @PostConstruct
- public void init() {
- // Keeps references of existing Hystrix plugins.
- HystrixEventNotifier eventNotifier = HystrixPlugins.getInstance()
- .getEventNotifier();
- HystrixMetricsPublisher metricsPublisher = HystrixPlugins.getInstance()
- .getMetricsPublisher();
- HystrixPropertiesStrategy propertiesStrategy = HystrixPlugins.getInstance()
- .getPropertiesStrategy();
- HystrixCommandExecutionHook commandExecutionHook = HystrixPlugins.getInstance()
- .getCommandExecutionHook();
- HystrixConcurrencyStrategy concurrencyStrategy = detectRegisteredConcurrencyStrategy();
-
- HystrixPlugins.reset();
-
- // Registers existing plugins excepts the Concurrent Strategy plugin.
- HystrixPlugins.getInstance().registerConcurrencyStrategy(
- new SecurityContextConcurrencyStrategy(concurrencyStrategy));
- HystrixPlugins.getInstance().registerEventNotifier(eventNotifier);
- HystrixPlugins.getInstance().registerMetricsPublisher(metricsPublisher);
- HystrixPlugins.getInstance().registerPropertiesStrategy(propertiesStrategy);
- HystrixPlugins.getInstance().registerCommandExecutionHook(commandExecutionHook);
- }
-
- private HystrixConcurrencyStrategy detectRegisteredConcurrencyStrategy() {
- HystrixConcurrencyStrategy registeredStrategy = HystrixPlugins.getInstance()
- .getConcurrencyStrategy();
- if (existingConcurrencyStrategy == null) {
- return registeredStrategy;
- }
- // Hystrix registered a default Strategy.
- if (registeredStrategy instanceof HystrixConcurrencyStrategyDefault) {
- return existingConcurrencyStrategy;
- }
- // If registeredStrategy not the default and not some use bean of
- // existingConcurrencyStrategy.
- if (!existingConcurrencyStrategy.equals(registeredStrategy)) {
- LOGGER.warn(
- "Multiple HystrixConcurrencyStrategy detected. Bean of HystrixConcurrencyStrategy was used.");
- }
- return existingConcurrencyStrategy;
- }
-
- static class HystrixSecurityCondition extends AllNestedConditions {
-
- HystrixSecurityCondition() {
- super(ConfigurationPhase.REGISTER_BEAN);
- }
-
- @ConditionalOnProperty(name = "hystrix.shareSecurityContext")
- static class ShareSecurityContext {
-
- }
-
- }
-
-}
diff --git a/spring-cloud-netflix-hystrix/src/main/java/org/springframework/cloud/netflix/hystrix/security/SecurityContextConcurrencyStrategy.java b/spring-cloud-netflix-hystrix/src/main/java/org/springframework/cloud/netflix/hystrix/security/SecurityContextConcurrencyStrategy.java
deleted file mode 100644
index 56235f0b5..000000000
--- a/spring-cloud-netflix-hystrix/src/main/java/org/springframework/cloud/netflix/hystrix/security/SecurityContextConcurrencyStrategy.java
+++ /dev/null
@@ -1,90 +0,0 @@
-/*
- * Copyright 2013-2019 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * https://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.springframework.cloud.netflix.hystrix.security;
-
-import java.util.concurrent.BlockingQueue;
-import java.util.concurrent.Callable;
-import java.util.concurrent.ThreadPoolExecutor;
-import java.util.concurrent.TimeUnit;
-
-import com.netflix.hystrix.HystrixThreadPoolKey;
-import com.netflix.hystrix.HystrixThreadPoolProperties;
-import com.netflix.hystrix.strategy.concurrency.HystrixConcurrencyStrategy;
-import com.netflix.hystrix.strategy.concurrency.HystrixRequestVariable;
-import com.netflix.hystrix.strategy.concurrency.HystrixRequestVariableLifecycle;
-import com.netflix.hystrix.strategy.properties.HystrixProperty;
-
-import org.springframework.security.concurrent.DelegatingSecurityContextCallable;
-
-/**
- * @author Daniel Lavoie
- */
-public class SecurityContextConcurrencyStrategy extends HystrixConcurrencyStrategy {
-
- private HystrixConcurrencyStrategy existingConcurrencyStrategy;
-
- public SecurityContextConcurrencyStrategy(
- HystrixConcurrencyStrategy existingConcurrencyStrategy) {
- this.existingConcurrencyStrategy = existingConcurrencyStrategy;
- }
-
- @Override
- public BlockingQueue getBlockingQueue(int maxQueueSize) {
- return existingConcurrencyStrategy != null
- ? existingConcurrencyStrategy.getBlockingQueue(maxQueueSize)
- : super.getBlockingQueue(maxQueueSize);
- }
-
- @Override
- public HystrixRequestVariable getRequestVariable(
- HystrixRequestVariableLifecycle rv) {
- return existingConcurrencyStrategy != null
- ? existingConcurrencyStrategy.getRequestVariable(rv)
- : super.getRequestVariable(rv);
- }
-
- @Override
- public ThreadPoolExecutor getThreadPool(HystrixThreadPoolKey threadPoolKey,
- HystrixProperty corePoolSize,
- HystrixProperty maximumPoolSize,
- HystrixProperty keepAliveTime, TimeUnit unit,
- BlockingQueue workQueue) {
- return existingConcurrencyStrategy != null
- ? existingConcurrencyStrategy.getThreadPool(threadPoolKey, corePoolSize,
- maximumPoolSize, keepAliveTime, unit, workQueue)
- : super.getThreadPool(threadPoolKey, corePoolSize, maximumPoolSize,
- keepAliveTime, unit, workQueue);
- }
-
- @Override
- public ThreadPoolExecutor getThreadPool(HystrixThreadPoolKey threadPoolKey,
- HystrixThreadPoolProperties threadPoolProperties) {
- return existingConcurrencyStrategy != null
- ? existingConcurrencyStrategy.getThreadPool(threadPoolKey,
- threadPoolProperties)
- : super.getThreadPool(threadPoolKey, threadPoolProperties);
- }
-
- @Override
- public Callable wrapCallable(Callable callable) {
- return existingConcurrencyStrategy != null
- ? existingConcurrencyStrategy
- .wrapCallable(new DelegatingSecurityContextCallable(callable))
- : super.wrapCallable(new DelegatingSecurityContextCallable(callable));
- }
-
-}
diff --git a/spring-cloud-netflix-hystrix/src/main/resources/META-INF/additional-spring-configuration-metadata.json b/spring-cloud-netflix-hystrix/src/main/resources/META-INF/additional-spring-configuration-metadata.json
deleted file mode 100644
index 216f5dfd8..000000000
--- a/spring-cloud-netflix-hystrix/src/main/resources/META-INF/additional-spring-configuration-metadata.json
+++ /dev/null
@@ -1,22 +0,0 @@
-{
- "properties": [
- {
- "defaultValue": "true",
- "name": "management.metrics.binders.hystrix.enabled",
- "description": "Enables creation of OK Http Client factory beans.",
- "type": "java.lang.Boolean"
- },
- {
- "defaultValue": false,
- "name": "hystrix.shareSecurityContext",
- "description": "Enables auto-configuration of the Hystrix concurrency strategy plugin hook who will transfer the `SecurityContext` from your main thread to the one used by the Hystrix command.",
- "type": "java.lang.Boolean"
- },
- {
- "defaultValue": true,
- "name": "spring.cloud.circuitbreaker.hystrix.enabled",
- "description": "Enables auto-configuration of the Hystrix Spring Cloud CircuitBreaker API implementation.",
- "type": "java.lang.Boolean"
- }
- ]
-}
\ No newline at end of file
diff --git a/spring-cloud-netflix-hystrix/src/main/resources/META-INF/spring.factories b/spring-cloud-netflix-hystrix/src/main/resources/META-INF/spring.factories
deleted file mode 100644
index 929e0a746..000000000
--- a/spring-cloud-netflix-hystrix/src/main/resources/META-INF/spring.factories
+++ /dev/null
@@ -1,8 +0,0 @@
-org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
-org.springframework.cloud.netflix.hystrix.HystrixAutoConfiguration,\
-org.springframework.cloud.netflix.hystrix.HystrixCircuitBreakerAutoConfiguration,\
-org.springframework.cloud.netflix.hystrix.ReactiveHystrixCircuitBreakerAutoConfiguration,\
-org.springframework.cloud.netflix.hystrix.security.HystrixSecurityAutoConfiguration
-
-org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker=\
-org.springframework.cloud.netflix.hystrix.HystrixCircuitBreakerConfiguration
diff --git a/spring-cloud-netflix-hystrix/src/test/java/org/springframework/cloud/netflix/AdhocTestSuite.java b/spring-cloud-netflix-hystrix/src/test/java/org/springframework/cloud/netflix/AdhocTestSuite.java
deleted file mode 100644
index 172b59509..000000000
--- a/spring-cloud-netflix-hystrix/src/test/java/org/springframework/cloud/netflix/AdhocTestSuite.java
+++ /dev/null
@@ -1,110 +0,0 @@
-/*
- * Copyright 2012-2013 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * https://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.springframework.cloud.netflix;
-
-import org.junit.Ignore;
-import org.junit.runner.RunWith;
-import org.junit.runners.Suite;
-import org.junit.runners.Suite.SuiteClasses;
-
-/**
- * A test suite for probing weird ordering problems in the tests.
- *
- * @author Dave Syer
- */
-@RunWith(Suite.class)
-@SuiteClasses({
- // org.springframework.cloud.netflix.test.OkHttpClientConfigurationTests.class,
- // org.springframework.cloud.netflix.test.ApacheHttpClientConfigurationTests.class,
- // org.springframework.cloud.netflix.hystrix.HystrixCommandsTests.class,
- // org.springframework.cloud.netflix.hystrix.HystrixOnlyTests.class,
- // org.springframework.cloud.netflix.hystrix.security.HystrixSecurityTests.class,
- // org.springframework.cloud.netflix.hystrix.security.HystrixSecurityNoFeignTests.class,
- // org.springframework.cloud.netflix.hystrix.HystrixStreamEndpointTests.class,
- // org.springframework.cloud.netflix.hystrix.HystrixConfigurationTests.class,
- // org.springframework.cloud.netflix.resttemplate.RestTemplateRetryTests.class,
- // org.springframework.cloud.netflix.ribbon.RibbonClientPreprocessorOverridesRetryTests.class,
- // org.springframework.cloud.netflix.ribbon.RibbonUtilsTests.class,
- // org.springframework.cloud.netflix.ribbon.test.RibbonClientDefaultConfigurationTests.class,
- // org.springframework.cloud.netflix.ribbon.RibbonClientConfigurationTests.class,
- // org.springframework.cloud.netflix.ribbon.RibbonClientHttpRequestFactoryTests.class,
- // org.springframework.cloud.netflix.ribbon.SpringRetryEnabledTests.class,
- // org.springframework.cloud.netflix.ribbon.PlainRibbonClientPreprocessorIntegrationTests.class,
- // org.springframework.cloud.netflix.ribbon.apache.RibbonLoadBalancingHttpClientTests.class,
- // org.springframework.cloud.netflix.ribbon.apache.RibbonApacheHttpRequestTests.class,
- // org.springframework.cloud.netflix.ribbon.apache.RibbonApacheHttpResponseTests.class,
- // org.springframework.cloud.netflix.ribbon.RibbonClientPreprocessorIntegrationTests.class,
- // org.springframework.cloud.netflix.ribbon.RibbonClientsPreprocessorIntegrationTests.class,
- // org.springframework.cloud.netflix.ribbon.RibbonClientsEagerInitializationTests.class,
- // org.springframework.cloud.netflix.ribbon.RibbonInterceptorTests.class,
- // org.springframework.cloud.netflix.ribbon.support.ContextAwareRequestTests.class,
- // org.springframework.cloud.netflix.ribbon.support.RibbonCommandContextTest.class,
- // org.springframework.cloud.netflix.ribbon.support.RetryableStatusCodeExceptionTests.class,
- // org.springframework.cloud.netflix.ribbon.ZonePreferenceServerListFilterTests.class,
- // org.springframework.cloud.netflix.ribbon.DefaultServerIntrospectorDefaultTests.class,
- // org.springframework.cloud.netflix.ribbon.RibbonClientPreprocessorPropertiesOverridesIntegrationTests.class,
- // org.springframework.cloud.netflix.ribbon.RibbonLoadBalancedRetryPolicyFactoryTests.class,
- // org.springframework.cloud.netflix.ribbon.SpringClientFactoryTests.class,
- // org.springframework.cloud.netflix.ribbon.RibbonAutoConfigurationIntegrationTests.class,
- // org.springframework.cloud.netflix.ribbon.RibbonLoadBalancerClientTests.class,
- // org.springframework.cloud.netflix.ribbon.RibbonClientPreprocessorOverridesIntegrationTests.class,
- // org.springframework.cloud.netflix.ribbon.RibbonApplicationContextInitializerTests.class,
- // org.springframework.cloud.netflix.ribbon.okhttp.SpringRetryDisableOkHttpClientTests.class,
- // org.springframework.cloud.netflix.ribbon.okhttp.OkHttpRibbonResponseTests.class,
- // org.springframework.cloud.netflix.ribbon.okhttp.OkHttpLoadBalancingClientTests.class,
- // org.springframework.cloud.netflix.ribbon.okhttp.OkHttpRibbonRequestTests.class,
- // org.springframework.cloud.netflix.ribbon.okhttp.SpringRetryEnabledOkHttpClientTests.class,
- // org.springframework.cloud.netflix.ribbon.RibbonClientConfigurationIntegrationTests.class,
- // org.springframework.cloud.netflix.ribbon.RibbonDisabledTests.class,
- // org.springframework.cloud.netflix.ribbon.DefaultServerIntrospectorTests.class,
- // org.springframework.cloud.netflix.ribbon.SpringRetryDisabledTests.class,
- // org.springframework.cloud.netflix.feign.beans.FeignClientTests.class,
- // org.springframework.cloud.netflix.feign.FeignClientsRegistrarTests.class,
- // org.springframework.cloud.netflix.feign.encoding.FeignAcceptEncodingTests.class,
- // org.springframework.cloud.netflix.feign.encoding.FeignContentEncodingTests.class,
- // org.springframework.cloud.netflix.feign.FeignLoggerFactoryTests.class,
- // org.springframework.cloud.netflix.feign.FeignCompressionTests.class,
- // org.springframework.cloud.netflix.feign.EnableFeignClientsTests.class,
- // org.springframework.cloud.netflix.feign.SpringDecoderTests.class,
- // org.springframework.cloud.netflix.feign.FeignClientUsingPropertiesTests.class,
- // org.springframework.cloud.netflix.feign.FeignHttpClientUrlTests.class,
- // org.springframework.cloud.netflix.feign.invalid.FeignClientValidationTests.class,
- // org.springframework.cloud.netflix.feign.support.FeignHttpClientPropertiesTests.class,
- // org.springframework.cloud.netflix.feign.support.SpringMvcContractTests.class,
- // org.springframework.cloud.netflix.feign.support.SpringEncoderTests.class,
- // org.springframework.cloud.netflix.feign.FeignClientOverrideDefaultsTests.class,
- // org.springframework.cloud.netflix.feign.ribbon.LoadBalancerFeignClientOverrideTests.class,
- // org.springframework.cloud.netflix.feign.ribbon.FeignRibbonClientPathTests.class,
- // org.springframework.cloud.netflix.feign.ribbon.RetryableFeignLoadBalancerTests.class,
- // org.springframework.cloud.netflix.feign.ribbon.FeignRibbonClientRetryTests.class,
- // org.springframework.cloud.netflix.feign.ribbon.FeignLoadBalancerTests.class,
- // org.springframework.cloud.netflix.feign.ribbon.FeignRibbonClientTests.class,
- // org.springframework.cloud.netflix.feign.ribbon.CachingSpringLoadBalancerFactoryTests.class,
- // org.springframework.cloud.netflix.feign.valid.scanning.FeignClientEnvVarTests.class,
- // org.springframework.cloud.netflix.feign.valid.scanning.FeignClientScanningTests.class,
- // org.springframework.cloud.netflix.feign.valid.FeignOkHttpTests.class,
- // org.springframework.cloud.netflix.feign.valid.FeignClientValidationTests.class,
- // org.springframework.cloud.netflix.feign.valid.FeignClientTests.class,
- // org.springframework.cloud.netflix.feign.valid.FeignHttpClientTests.class,
- // org.springframework.cloud.netflix.feign.valid.FeignClientNotPrimaryTests.class,
- // org.springframework.cloud.netflix.feign.FeignClientFactoryTests.class,
-
-})
-@Ignore
-public class AdhocTestSuite {
-
-}
diff --git a/spring-cloud-netflix-hystrix/src/test/java/org/springframework/cloud/netflix/hystrix/HystrixAutoConfigurationTests.java b/spring-cloud-netflix-hystrix/src/test/java/org/springframework/cloud/netflix/hystrix/HystrixAutoConfigurationTests.java
deleted file mode 100644
index c16111be4..000000000
--- a/spring-cloud-netflix-hystrix/src/test/java/org/springframework/cloud/netflix/hystrix/HystrixAutoConfigurationTests.java
+++ /dev/null
@@ -1,61 +0,0 @@
-/*
- * Copyright 2013-2019 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * https://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.springframework.cloud.netflix.hystrix;
-
-import org.junit.Ignore;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-
-import org.springframework.beans.factory.NoSuchBeanDefinitionException;
-import org.springframework.boot.SpringBootConfiguration;
-import org.springframework.boot.WebApplicationType;
-import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
-import org.springframework.boot.builder.SpringApplicationBuilder;
-import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker;
-import org.springframework.cloud.test.ClassPathExclusions;
-import org.springframework.cloud.test.ModifiedClassPathRunner;
-import org.springframework.context.ConfigurableApplicationContext;
-
-import static org.assertj.core.api.Assertions.fail;
-
-@RunWith(ModifiedClassPathRunner.class)
-@ClassPathExclusions({ "micrometer-core-*" })
-public class HystrixAutoConfigurationTests {
-
- @Test
- @Ignore // TODO: why does this test fail in maven, but not in IDE?
- public void contextStarts() {
- try (ConfigurableApplicationContext context = new SpringApplicationBuilder()
- .web(WebApplicationType.NONE).sources(TestApp.class).run()) {
- try {
- context.getBean("hystrixMetricsBinder");
- fail("HystrixMetricsBinder class should not be found");
- }
- catch (NoSuchBeanDefinitionException e) {
- // this is the correct case
- }
- }
- }
-
- @EnableCircuitBreaker
- @SpringBootConfiguration
- @EnableAutoConfiguration
- protected static class TestApp {
-
- }
-
-}
diff --git a/spring-cloud-netflix-hystrix/src/test/java/org/springframework/cloud/netflix/hystrix/HystrixCircuitBreakerIntegrationTest.java b/spring-cloud-netflix-hystrix/src/test/java/org/springframework/cloud/netflix/hystrix/HystrixCircuitBreakerIntegrationTest.java
deleted file mode 100644
index ddd432793..000000000
--- a/spring-cloud-netflix-hystrix/src/test/java/org/springframework/cloud/netflix/hystrix/HystrixCircuitBreakerIntegrationTest.java
+++ /dev/null
@@ -1,133 +0,0 @@
-/*
- * Copyright 2013-2018 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * https://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.springframework.cloud.netflix.hystrix;
-
-import com.netflix.hystrix.HystrixCommand;
-import com.netflix.hystrix.HystrixCommandGroupKey;
-import com.netflix.hystrix.HystrixCommandProperties;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
-import org.springframework.boot.test.context.SpringBootTest;
-import org.springframework.boot.test.web.client.TestRestTemplate;
-import org.springframework.cloud.client.circuitbreaker.CircuitBreaker;
-import org.springframework.cloud.client.circuitbreaker.CircuitBreakerFactory;
-import org.springframework.cloud.client.circuitbreaker.Customizer;
-import org.springframework.cloud.netflix.test.NoSecurityConfiguration;
-import org.springframework.context.annotation.Bean;
-import org.springframework.context.annotation.Configuration;
-import org.springframework.context.annotation.Import;
-import org.springframework.stereotype.Service;
-import org.springframework.test.annotation.DirtiesContext;
-import org.springframework.test.context.junit4.SpringRunner;
-import org.springframework.web.bind.annotation.GetMapping;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
-
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT;
-
-/**
- * @author Ryan Baxter
- */
-@RunWith(SpringRunner.class)
-@SpringBootTest(webEnvironment = RANDOM_PORT,
- classes = HystrixCircuitBreakerIntegrationTest.Application.class)
-@DirtiesContext
-@Import(NoSecurityConfiguration.class)
-public class HystrixCircuitBreakerIntegrationTest {
-
- @Autowired
- Application.DemoControllerService service;
-
- @Test
- public void testSlow() {
- assertThat(service.slow()).isEqualTo("fallback");
- }
-
- @Test
- public void testNormal() {
- assertThat(service.normal()).isEqualTo("normal");
- }
-
- @Configuration(proxyBeanMethods = false)
- @EnableAutoConfiguration
- @RestController
- protected static class Application {
-
- @RequestMapping("/slow")
- public String slow() throws InterruptedException {
- Thread.sleep(3000);
- return "slow";
- }
-
- @GetMapping("/normal")
- public String normal() {
- return "normal";
- }
-
- @Bean
- public Customizer customizer() {
- return factory -> factory
- .configure(
- builder -> builder.commandProperties(HystrixCommandProperties
- .Setter().withExecutionTimeoutInMilliseconds(2000)),
- "slow");
- }
-
- @Bean
- public Customizer defaultConfig() {
- return factory -> factory.configureDefault(id -> HystrixCommand.Setter
- .withGroupKey(HystrixCommandGroupKey.Factory.asKey(id))
- .andCommandPropertiesDefaults(HystrixCommandProperties.Setter()
- .withExecutionTimeoutInMilliseconds(4000)));
- }
-
- @Service
- public static class DemoControllerService {
-
- private TestRestTemplate rest;
-
- private final CircuitBreakerFactory cbFactory;
-
- private final CircuitBreaker circuitBreakerSlow;
-
- DemoControllerService(TestRestTemplate rest,
- CircuitBreakerFactory cbBuilder) {
- this.rest = rest;
- this.cbFactory = cbBuilder;
- this.circuitBreakerSlow = cbBuilder.create("slow");
- }
-
- public String slow() {
- return circuitBreakerSlow.run(
- () -> rest.getForObject("/slow", String.class), t -> "fallback");
- }
-
- public String normal() {
- return cbFactory.create("normal").run(
- () -> rest.getForObject("/normal", String.class),
- t -> "fallback");
- }
-
- }
-
- }
-
-}
diff --git a/spring-cloud-netflix-hystrix/src/test/java/org/springframework/cloud/netflix/hystrix/HystrixCircuitBreakerTest.java b/spring-cloud-netflix-hystrix/src/test/java/org/springframework/cloud/netflix/hystrix/HystrixCircuitBreakerTest.java
deleted file mode 100644
index 1a974c249..000000000
--- a/spring-cloud-netflix-hystrix/src/test/java/org/springframework/cloud/netflix/hystrix/HystrixCircuitBreakerTest.java
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * Copyright 2013-2018 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * https://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.springframework.cloud.netflix.hystrix;
-
-import org.junit.Test;
-
-import org.springframework.cloud.client.circuitbreaker.CircuitBreaker;
-
-import static org.assertj.core.api.Assertions.assertThat;
-
-/**
- * @author Ryan Baxter
- */
-public class HystrixCircuitBreakerTest {
-
- @Test
- public void run() {
- CircuitBreaker cb = new HystrixCircuitBreakerFactory().create("foo");
- String s = cb.run(() -> "foobar", t -> "fallback");
- assertThat(cb.run(() -> "foobar", t -> "fallback")).isEqualTo("foobar");
- }
-
- @Test
- public void fallback() {
- CircuitBreaker cb = new HystrixCircuitBreakerFactory().create("foo");
- assertThat((String) cb.run(() -> {
- throw new RuntimeException("Boom");
- }, t -> "fallback")).isEqualTo("fallback");
- }
-
-}
diff --git a/spring-cloud-netflix-hystrix/src/test/java/org/springframework/cloud/netflix/hystrix/HystrixCommandsTests.java b/spring-cloud-netflix-hystrix/src/test/java/org/springframework/cloud/netflix/hystrix/HystrixCommandsTests.java
deleted file mode 100644
index e92691093..000000000
--- a/spring-cloud-netflix-hystrix/src/test/java/org/springframework/cloud/netflix/hystrix/HystrixCommandsTests.java
+++ /dev/null
@@ -1,136 +0,0 @@
-/*
- * Copyright 2013-2019 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * https://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.springframework.cloud.netflix.hystrix;
-
-import java.time.Duration;
-
-import com.netflix.hystrix.exception.HystrixRuntimeException;
-import org.junit.Test;
-import reactor.core.publisher.Flux;
-import reactor.core.publisher.Mono;
-import reactor.test.StepVerifier;
-
-public class HystrixCommandsTests {
-
- @Test
- public void monoWorks() {
- StepVerifier.create(HystrixCommands.from(Flux.just("works"))
- .commandName("testworks").toMono()).expectNext("works").verifyComplete();
- }
-
- @Test
- public void eagerMonoWorks() {
- StepVerifier
- .create(HystrixCommands.from(Mono.just("works")).eager()
- .commandName("testworks").toMono())
- .expectNext("works").verifyComplete();
- }
-
- @Test
- public void monoTimesOut() {
- StepVerifier.create(HystrixCommands.from(Mono.fromCallable(() -> {
- Thread.sleep(1500);
- return "timeout";
- })).commandName("failcmd").toMono()).verifyError(HystrixRuntimeException.class);
- }
-
- @Test
- public void monoFallbackWorks() {
- StepVerifier
- .create(HystrixCommands.from(Mono.error(new Exception()))
- .commandName("failcmd").fallback(Mono.just("fallback")).toMono())
- .expectNext("fallback").verifyComplete();
- }
-
- @Test
- public void monoFallbackWithExceptionWorks() {
- StepVerifier.create(
- HystrixCommands.from(Mono.error(new IllegalStateException()))
- .commandName("failcmd").fallback(throwable -> {
- if (throwable instanceof IllegalStateException) {
- return Mono.just("specificfallback");
- }
- return Mono.just("genericfallback");
- }).toMono())
- .expectNext("specificfallback").verifyComplete();
- }
-
- @Test
- public void fluxWorks() {
- StepVerifier.create(HystrixCommands.from(Flux.just("1", "2"))
- .commandName("multiflux").toFlux()).expectNext("1").expectNext("2")
- .verifyComplete();
- }
-
- @Test
- public void fluxWorksDeferredRequest() {
- StepVerifier
- .create(HystrixCommands.from(Flux.just("1", "2")).commandName("multiflux")
- .build(), 1)
- .expectNext("1").thenAwait(Duration.ofSeconds(1)).thenRequest(1)
- .expectNext("2").verifyComplete();
- }
-
- @Test
- public void toObservableFunctionWorks() {
- StepVerifier
- .create(HystrixCommands.from(Flux.just("1", "2")).commandName("multiflux")
- .toObservable(cmd -> cmd.toObservable()).build(), 1)
- .expectNext("1").thenAwait(Duration.ofSeconds(1)).thenRequest(1)
- .verifyError();
- }
-
- @Test
- public void eagerFluxWorks() {
- StepVerifier
- .create(HystrixCommands.from(Flux.just("1", "2")).commandName("multiflux")
- .eager().toFlux())
- .expectNext("1").expectNext("2").verifyComplete();
- }
-
- @Test
- public void fluxTimesOut() {
- StepVerifier.create(HystrixCommands.from(Flux.from(s -> {
- try {
- Thread.sleep(1500);
- }
- catch (InterruptedException e) {
- throw new RuntimeException(e);
- }
- })).commandName("failcmd").toFlux()).verifyError(HystrixRuntimeException.class);
- }
-
- @Test
- public void fluxFallbackWorks() {
- StepVerifier
- .create(HystrixCommands.from(Flux.error(new Exception()))
- .commandName("multiflux").fallback(Flux.just("a", "b")).toFlux())
- .expectNext("a").expectNext("b").verifyComplete();
- }
-
- @Test
- public void extendTimeout() {
- StepVerifier.create(HystrixCommands.from(Mono.fromCallable(() -> {
- Thread.sleep(1500);
- return "works";
- })).commandName("extendTimeout")
- .commandProperties(
- setter -> setter.withExecutionTimeoutInMilliseconds(2000))
- .toMono()).expectNext("works").verifyComplete();
- }
-
-}
diff --git a/spring-cloud-netflix-hystrix/src/test/java/org/springframework/cloud/netflix/hystrix/HystrixConfigurationTests.java b/spring-cloud-netflix-hystrix/src/test/java/org/springframework/cloud/netflix/hystrix/HystrixConfigurationTests.java
deleted file mode 100644
index ccfa7be77..000000000
--- a/spring-cloud-netflix-hystrix/src/test/java/org/springframework/cloud/netflix/hystrix/HystrixConfigurationTests.java
+++ /dev/null
@@ -1,60 +0,0 @@
-/*
- * Copyright 2013-2019 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * https://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.springframework.cloud.netflix.hystrix;
-
-import com.netflix.hystrix.contrib.javanica.aop.aspectj.HystrixCommandAspect;
-import io.micrometer.core.instrument.binder.MeterBinder;
-import io.micrometer.core.instrument.binder.hystrix.HystrixMetricsBinder;
-import org.junit.Test;
-
-import org.springframework.boot.SpringBootConfiguration;
-import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
-import org.springframework.boot.test.context.runner.ApplicationContextRunner;
-import org.springframework.boot.test.context.runner.WebApplicationContextRunner;
-
-import static org.assertj.core.api.Assertions.assertThat;
-
-/**
- * @author Dave Syer
- * @author Biju Kunjummen
- */
-public class HystrixConfigurationTests {
-
- @Test
- public void nonWebAppStartsUp() {
- new ApplicationContextRunner()
- .withUserConfiguration(HystrixCircuitBreakerConfiguration.class)
- .run(c -> {
- assertThat(c).hasSingleBean(HystrixCommandAspect.class);
- });
- }
-
- @Test
- public void hystrixMetricsConfigured() {
- new WebApplicationContextRunner().withUserConfiguration(TestApp.class).run(c -> {
- assertThat(c.getBeansOfType(MeterBinder.class).values())
- .hasAtLeastOneElementOfType(HystrixMetricsBinder.class);
- });
- }
-
- @SpringBootConfiguration
- @EnableAutoConfiguration
- protected static class TestApp {
-
- }
-
-}
diff --git a/spring-cloud-netflix-hystrix/src/test/java/org/springframework/cloud/netflix/hystrix/HystrixOnlyTests.java b/spring-cloud-netflix-hystrix/src/test/java/org/springframework/cloud/netflix/hystrix/HystrixOnlyTests.java
deleted file mode 100644
index 7a1ad2732..000000000
--- a/spring-cloud-netflix-hystrix/src/test/java/org/springframework/cloud/netflix/hystrix/HystrixOnlyTests.java
+++ /dev/null
@@ -1,204 +0,0 @@
-/*
- * Copyright 2013-2019 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * https://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.springframework.cloud.netflix.hystrix;
-
-import java.util.Base64;
-import java.util.List;
-import java.util.Map;
-
-import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.boot.actuate.autoconfigure.endpoint.web.WebEndpointProperties;
-import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
-import org.springframework.boot.test.context.SpringBootTest;
-import org.springframework.boot.test.web.client.TestRestTemplate;
-import org.springframework.boot.web.server.LocalServerPort;
-import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker;
-import org.springframework.cloud.netflix.test.NoSecurityConfiguration;
-import org.springframework.context.annotation.Bean;
-import org.springframework.context.annotation.Configuration;
-import org.springframework.context.annotation.Import;
-import org.springframework.http.HttpEntity;
-import org.springframework.http.HttpHeaders;
-import org.springframework.http.HttpMethod;
-import org.springframework.http.HttpStatus;
-import org.springframework.http.ResponseEntity;
-import org.springframework.test.annotation.DirtiesContext;
-import org.springframework.test.context.ActiveProfiles;
-import org.springframework.test.context.junit4.SpringRunner;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
-
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT;
-import static org.springframework.cloud.netflix.test.TestAutoConfiguration.PASSWORD;
-import static org.springframework.cloud.netflix.test.TestAutoConfiguration.USER;
-
-/**
- * @author Spencer Gibb
- */
-@RunWith(SpringRunner.class)
-@SpringBootTest(classes = HystrixOnlyApplication.class, webEnvironment = RANDOM_PORT,
- properties = { "management.endpoint.health.show-details=ALWAYS" })
-@DirtiesContext
-@ActiveProfiles("proxysecurity")
-public class HystrixOnlyTests {
-
- private static final String BASE_PATH = new WebEndpointProperties().getBasePath();
-
- @LocalServerPort
- private int port;
-
- @Test
- public void testNormalExecution() {
- ResponseEntity res = new TestRestTemplate()
- .getForEntity("http://localhost:" + this.port + "/", String.class);
- assertThat(res.getBody()).as("incorrect response").isEqualTo("Hello world");
- }
-
- @Test
- public void testFailureFallback() {
- ResponseEntity res = new TestRestTemplate()
- .getForEntity("http://localhost:" + this.port + "/fail", String.class);
- assertThat(res.getBody()).as("incorrect fallback")
- .isEqualTo("Fallback Hello world");
- }
-
- @Test
- @SuppressWarnings("unchecked")
- public void testHystrixHealth() {
- Map map = getHealth();
- // https://github.com/spring-projects/spring-boot/issues/17929
- // if the default changes back, this will need to be reverted.
- assertThat(map).containsKeys("components");
- Map details = (Map) map.get("components");
- assertThat(details).containsKeys("hystrix");
- Map hystrix = (Map) details.get("hystrix");
- assertThat(hystrix).containsEntry("status", "UP");
- }
-
- @Test
- public void testNoDiscoveryHealth() {
- Map, ?> map = getHealth();
- // There is explicitly no discovery, so there should be no discovery health key
- assertThat(map.containsKey("discovery"))
- .as("Incorrect existing discovery health key").isFalse();
- }
-
- @Test
- public void testHystrixInnerMapMetrics() {
- // We have to hit any Hystrix command before Hystrix metrics to be populated
- String url = "http://localhost:" + this.port;
- ResponseEntity response = new TestRestTemplate().getForEntity(url,
- String.class);
- assertThat(response.getStatusCode()).as("bad response code")
- .isEqualTo(HttpStatus.OK);
-
- // Poller takes some time to realize for new metrics
- try {
- Thread.sleep(2000);
- }
- catch (InterruptedException e) {
- }
-
- Map> map = (Map>) getMetrics();
-
- assertThat(map.get("names").contains("hystrix.latency.total"))
- .as("There is no latencyTotal group key specified").isTrue();
- assertThat(map.get("names").contains("hystrix.latency.execution"))
- .as("There is no latencyExecute group key specified").isTrue();
- }
-
- private Map, ?> getMetrics() {
- return getAuthenticatedEndpoint("/metrics");
- }
-
- private Map, ?> getHealth() {
- return getAuthenticatedEndpoint("/health");
- }
-
- private Map, ?> getAuthenticatedEndpoint(String endpoint) {
- return new TestRestTemplate().exchange(
- "http://localhost:" + this.port + BASE_PATH + endpoint, HttpMethod.GET,
- new HttpEntity(createBasicAuthHeader(USER, PASSWORD)), Map.class)
- .getBody();
- }
-
- public static HttpHeaders createBasicAuthHeader(final String username,
- final String password) {
- return new HttpHeaders() {
- private static final long serialVersionUID = 1766341693637204893L;
-
- {
- String auth = username + ":" + password;
- byte[] encodedAuth = Base64.getEncoder().encode(auth.getBytes());
- String authHeader = "Basic " + new String(encodedAuth);
- this.set("Authorization", authHeader);
- }
- };
- }
-
-}
-
-class Service {
-
- @HystrixCommand
- public String hello() {
- return "Hello world";
- }
-
- @HystrixCommand(fallbackMethod = "fallback")
- public String fail() {
- throw new RuntimeException("Always fail");
- }
-
- public String fallback() {
- return "Fallback Hello world";
- }
-
-}
-
-// Don't use @SpringBootApplication because we don't want to component scan
-@Configuration(proxyBeanMethods = false)
-@EnableAutoConfiguration
-@EnableCircuitBreaker
-@RestController
-@Import(NoSecurityConfiguration.class)
-class HystrixOnlyApplication {
-
- @Bean
- public Service service() {
- return new Service();
- }
-
- @Autowired
- private Service service;
-
- @RequestMapping("/")
- public String home() {
- return this.service.hello();
- }
-
- @RequestMapping("/fail")
- public String fail() {
- return this.service.fail();
- }
-
-}
diff --git a/spring-cloud-netflix-hystrix/src/test/java/org/springframework/cloud/netflix/hystrix/HystrixStreamEndpointTests.java b/spring-cloud-netflix-hystrix/src/test/java/org/springframework/cloud/netflix/hystrix/HystrixStreamEndpointTests.java
deleted file mode 100644
index bc0edf471..000000000
--- a/spring-cloud-netflix-hystrix/src/test/java/org/springframework/cloud/netflix/hystrix/HystrixStreamEndpointTests.java
+++ /dev/null
@@ -1,132 +0,0 @@
-/*
- * Copyright 2013-2019 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * https://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.springframework.cloud.netflix.hystrix;
-
-import java.io.InputStream;
-import java.net.URL;
-import java.util.ArrayList;
-import java.util.List;
-
-import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.boot.actuate.autoconfigure.endpoint.web.WebEndpointProperties;
-import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
-import org.springframework.boot.test.context.SpringBootTest;
-import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
-import org.springframework.boot.test.web.client.TestRestTemplate;
-import org.springframework.boot.web.server.LocalServerPort;
-import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker;
-import org.springframework.cloud.netflix.test.NoSecurityConfiguration;
-import org.springframework.context.annotation.Bean;
-import org.springframework.context.annotation.Configuration;
-import org.springframework.context.annotation.Import;
-import org.springframework.http.HttpStatus;
-import org.springframework.http.ResponseEntity;
-import org.springframework.test.annotation.DirtiesContext;
-import org.springframework.test.context.junit4.SpringRunner;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
-
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.assertj.core.api.Assertions.fail;
-
-/**
- * @author Dave Syer
- * @author Spencer Gibb
- */
-@RunWith(SpringRunner.class)
-@SpringBootTest(classes = HystrixStreamEndpointTests.Application.class,
- webEnvironment = WebEnvironment.RANDOM_PORT,
- value = { "spring.application.name=hystrixstreamtest" })
-@DirtiesContext
-public class HystrixStreamEndpointTests {
-
- private static final String BASE_PATH = new WebEndpointProperties().getBasePath();
-
- private static final Log log = LogFactory.getLog(HystrixStreamEndpointTests.class);
-
- @LocalServerPort
- private int port = 0;
-
- @Test
- public void hystrixStreamWorks() throws Exception {
- String url = "http://localhost:" + port;
- // you have to hit a Hystrix circuit breaker before the stream sends anything
- ResponseEntity response = new TestRestTemplate().getForEntity(url,
- String.class);
- assertThat(response.getStatusCode()).as("bad response code")
- .isEqualTo(HttpStatus.OK);
-
- URL hystrixUrl = new URL(url + BASE_PATH + "/hystrix.stream");
-
- List data = new ArrayList<>();
- for (int i = 0; i < 5; i++) {
- try (InputStream in = hystrixUrl.openStream()) {
- byte[] buffer = new byte[1024];
- in.read(buffer);
- data.add(new String(buffer));
- }
- catch (Exception e) {
- log.error("Error getting hystrix stream, try " + i, e);
- }
- }
-
- for (String item : data) {
- if (item.contains("data:")) {
- return; // test passed
- }
- }
- fail("/hystrix.stream didn't contain 'data:' was " + data);
- }
-
- @Configuration(proxyBeanMethods = false)
- @EnableAutoConfiguration
- @RestController
- @EnableCircuitBreaker
- @Import(NoSecurityConfiguration.class)
- protected static class Application {
-
- @Autowired
- Service service;
-
- @Bean
- Service service() {
- return new Service();
- }
-
- @RequestMapping("/")
- public String hello() {
- return service.hello();
- }
-
- }
-
- protected static class Service {
-
- @HystrixCommand
- public String hello() {
- return "Hello World";
- }
-
- }
-
-}
diff --git a/spring-cloud-netflix-hystrix/src/test/java/org/springframework/cloud/netflix/hystrix/HystrixWebfluxEndpointTests.java b/spring-cloud-netflix-hystrix/src/test/java/org/springframework/cloud/netflix/hystrix/HystrixWebfluxEndpointTests.java
deleted file mode 100644
index 82f68fcd3..000000000
--- a/spring-cloud-netflix-hystrix/src/test/java/org/springframework/cloud/netflix/hystrix/HystrixWebfluxEndpointTests.java
+++ /dev/null
@@ -1,99 +0,0 @@
-/*
- * Copyright 2013-2019 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * https://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.springframework.cloud.netflix.hystrix;
-
-import java.util.Map;
-
-import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import reactor.core.publisher.Flux;
-import reactor.test.StepVerifier;
-
-import org.springframework.boot.SpringBootConfiguration;
-import org.springframework.boot.actuate.autoconfigure.endpoint.web.WebEndpointProperties;
-import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
-import org.springframework.boot.test.context.SpringBootTest;
-import org.springframework.boot.web.server.LocalServerPort;
-import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker;
-import org.springframework.cloud.netflix.test.TestAutoConfiguration;
-import org.springframework.http.MediaType;
-import org.springframework.test.annotation.DirtiesContext;
-import org.springframework.test.context.junit4.SpringRunner;
-import org.springframework.test.web.reactive.server.WebTestClient;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
-import org.springframework.web.reactive.function.client.WebClient;
-
-import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT;
-
-/**
- * @author Dave Syer
- * @author Spencer Gibb
- */
-@RunWith(SpringRunner.class)
-@SpringBootTest(webEnvironment = RANDOM_PORT,
- properties = { "spring.main.web-application-type=reactive",
- "spring.application.name=hystrixstreamwebfluxtest" /* "debug=true" */ })
-@DirtiesContext
-public class HystrixWebfluxEndpointTests {
-
- private static final String BASE_PATH = new WebEndpointProperties().getBasePath();
-
- private static final Log log = LogFactory.getLog(HystrixWebfluxEndpointTests.class);
-
- @LocalServerPort
- private int port;
-
- @Test
- public void hystrixStreamWorks() {
- String url = "http://localhost:" + port;
- // you have to hit a Hystrix circuit breaker before the stream sends anything
- WebTestClient testClient = WebTestClient.bindToServer().baseUrl(url).build();
- testClient.get().uri("/").exchange().expectStatus().isOk();
-
- WebClient client = WebClient.create(url);
-
- Flux result = client.get().uri(BASE_PATH + "/hystrix.stream")
- .accept(MediaType.TEXT_EVENT_STREAM).exchange()
- .flatMapMany(res -> res.bodyToFlux(Map.class)).take(5)
- .filter(map -> "HystrixCommand".equals(map.get("type")))
- .map(map -> (String) map.get("type"));
-
- StepVerifier.create(result).expectNext("HystrixCommand").thenCancel().verify();
- }
-
- @RestController
- @EnableCircuitBreaker
- @EnableAutoConfiguration(exclude = TestAutoConfiguration.class, excludeName = {
- "org.springframework.boot.autoconfigure.security.reactive.ReactiveSecurityAutoConfiguration",
- "org.springframework.boot.autoconfigure.security.SecurityAutoConfiguration",
- "org.springframework.boot.actuate.autoconfigure.security.reactive.ReactiveManagementWebSecurityAutoConfiguration" })
- @SpringBootConfiguration
- protected static class Config {
-
- @HystrixCommand
- @RequestMapping("/")
- public String hi() {
- return "hi";
- }
-
- }
-
-}
diff --git a/spring-cloud-netflix-hystrix/src/test/java/org/springframework/cloud/netflix/hystrix/ReactiveHystrixCircuitBreakerIntegrationTest.java b/spring-cloud-netflix-hystrix/src/test/java/org/springframework/cloud/netflix/hystrix/ReactiveHystrixCircuitBreakerIntegrationTest.java
deleted file mode 100644
index 4cd3ebeb4..000000000
--- a/spring-cloud-netflix-hystrix/src/test/java/org/springframework/cloud/netflix/hystrix/ReactiveHystrixCircuitBreakerIntegrationTest.java
+++ /dev/null
@@ -1,155 +0,0 @@
-/*
- * Copyright 2013-2018 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * https://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.springframework.cloud.netflix.hystrix;
-
-import java.time.Duration;
-
-import com.netflix.hystrix.HystrixCommandGroupKey;
-import com.netflix.hystrix.HystrixCommandProperties;
-import com.netflix.hystrix.HystrixObservableCommand;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import reactor.core.publisher.Mono;
-
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
-import org.springframework.boot.test.context.SpringBootTest;
-import org.springframework.boot.web.server.LocalServerPort;
-import org.springframework.cloud.client.circuitbreaker.Customizer;
-import org.springframework.cloud.client.circuitbreaker.ReactiveCircuitBreaker;
-import org.springframework.cloud.client.circuitbreaker.ReactiveCircuitBreakerFactory;
-import org.springframework.cloud.netflix.test.NoSecurityConfiguration;
-import org.springframework.context.annotation.Bean;
-import org.springframework.context.annotation.Configuration;
-import org.springframework.context.annotation.Import;
-import org.springframework.stereotype.Service;
-import org.springframework.test.annotation.DirtiesContext;
-import org.springframework.test.context.junit4.SpringRunner;
-import org.springframework.web.bind.annotation.GetMapping;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
-import org.springframework.web.reactive.function.client.WebClient;
-
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT;
-
-/**
- * @author Ryan Baxter
- */
-@RunWith(SpringRunner.class)
-@SpringBootTest(webEnvironment = RANDOM_PORT,
- classes = ReactiveHystrixCircuitBreakerIntegrationTest.Application.class)
-@DirtiesContext
-@Import(NoSecurityConfiguration.class)
-public class ReactiveHystrixCircuitBreakerIntegrationTest {
-
- @LocalServerPort
- int port = 0;
-
- @Autowired
- ReactiveHystrixCircuitBreakerIntegrationTest.Application.DemoControllerService service;
-
- @Before
- public void setup() {
- service.setPort(port);
- }
-
- @Test
- public void testSlow() {
- assertThat(service.slow().block()).isEqualTo("fallback");
- }
-
- @Test
- public void testNormal() {
- assertThat(service.normal().block()).isEqualTo("normal");
- }
-
- @Configuration(proxyBeanMethods = false)
- @EnableAutoConfiguration
- @RestController
- protected static class Application {
-
- @RequestMapping("/slow")
- public Mono slow() {
- return Mono.just("slow").delayElement(Duration.ofSeconds(3));
- }
-
- @GetMapping("/normal")
- public Mono normal() {
- return Mono.just("normal");
- }
-
- @Bean
- public Customizer customizer() {
- return factory -> factory
- .configure(
- builder -> builder.commandProperties(HystrixCommandProperties
- .Setter().withExecutionTimeoutInMilliseconds(2000)),
- "slow");
- }
-
- @Bean
- public Customizer defaultConfig() {
- return factory -> factory
- .configureDefault(id -> HystrixObservableCommand.Setter
- .withGroupKey(HystrixCommandGroupKey.Factory.asKey(id))
- .andCommandPropertiesDefaults(HystrixCommandProperties
- .Setter().withExecutionTimeoutInMilliseconds(4000)));
- }
-
- @Service
- public static class DemoControllerService {
-
- private int port = 0;
-
- private final ReactiveCircuitBreakerFactory cbFactory;
-
- private final ReactiveCircuitBreaker circuitBreakerSlow;
-
- DemoControllerService(ReactiveCircuitBreakerFactory cbBuilder) {
- this.cbFactory = cbBuilder;
- this.circuitBreakerSlow = cbBuilder.create("slow");
- }
-
- public Mono slow() {
- return WebClient.builder().baseUrl("http://localhost:" + port).build()
- .get().uri("/slow").retrieve().bodyToMono(String.class)
- .transform(it -> circuitBreakerSlow.run(it, t -> {
- t.printStackTrace();
- return Mono.just("fallback");
- }));
- }
-
- public Mono normal() {
- return WebClient.builder().baseUrl("http://localhost:" + port).build()
- .get().uri("/normal").retrieve().bodyToMono(String.class)
- .transform(it -> cbFactory.create("normal").run(it, t -> {
- t.printStackTrace();
- return Mono.just("fallback");
- }));
- }
-
- public void setPort(int port) {
- this.port = port;
- }
-
- }
-
- }
-
-}
diff --git a/spring-cloud-netflix-hystrix/src/test/java/org/springframework/cloud/netflix/hystrix/ReactiveHystrixCircuitBreakerTest.java b/spring-cloud-netflix-hystrix/src/test/java/org/springframework/cloud/netflix/hystrix/ReactiveHystrixCircuitBreakerTest.java
deleted file mode 100644
index f14c47131..000000000
--- a/spring-cloud-netflix-hystrix/src/test/java/org/springframework/cloud/netflix/hystrix/ReactiveHystrixCircuitBreakerTest.java
+++ /dev/null
@@ -1,70 +0,0 @@
-/*
- * Copyright 2013-2018 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * https://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.springframework.cloud.netflix.hystrix;
-
-import org.assertj.core.util.Arrays;
-import org.junit.Test;
-import reactor.core.publisher.Flux;
-import reactor.core.publisher.Mono;
-
-import org.springframework.cloud.client.circuitbreaker.ReactiveCircuitBreaker;
-
-import static org.assertj.core.api.Assertions.assertThat;
-
-/**
- * @author Ryan Baxter
- */
-public class ReactiveHystrixCircuitBreakerTest {
-
- @Test
- public void monoRun() {
- ReactiveCircuitBreaker cb = new ReactiveHystrixCircuitBreakerFactory()
- .create("foo");
- Mono s = Mono.just("foobar")
- .transform(it -> cb.run(it, t -> Mono.just("fallback")));
- assertThat(s.block()).isEqualTo("foobar");
- }
-
- @Test
- public void monoFallback() {
- ReactiveCircuitBreaker cb = new ReactiveHystrixCircuitBreakerFactory()
- .create("foo");
- assertThat(Mono.error(new RuntimeException("boom"))
- .transform(it -> cb.run(it, t -> Mono.just("fallback"))).block())
- .isEqualTo("fallback");
- }
-
- @Test
- public void fluxRun() {
- ReactiveCircuitBreaker cb = new ReactiveHystrixCircuitBreakerFactory()
- .create("foo");
- Flux s = Flux.just("foobar", "hello world")
- .transform(it -> cb.run(it, t -> Flux.just("fallback")));
- assertThat(s.collectList().block())
- .isEqualTo(Arrays.asList(new String[] { "foobar", "hello world" }));
- }
-
- @Test
- public void fluxFallback() {
- ReactiveCircuitBreaker cb = new ReactiveHystrixCircuitBreakerFactory()
- .create("foo");
- assertThat(Flux.error(new RuntimeException("boom"))
- .transform(it -> cb.run(it, t -> Flux.just("fallback"))).collectList()
- .block()).isEqualTo(Arrays.asList(new String[] { "fallback" }));
- }
-
-}
diff --git a/spring-cloud-netflix-hystrix/src/test/java/org/springframework/cloud/netflix/hystrix/security/HystrixSecurityApplication.java b/spring-cloud-netflix-hystrix/src/test/java/org/springframework/cloud/netflix/hystrix/security/HystrixSecurityApplication.java
deleted file mode 100644
index ff2904ca6..000000000
--- a/spring-cloud-netflix-hystrix/src/test/java/org/springframework/cloud/netflix/hystrix/security/HystrixSecurityApplication.java
+++ /dev/null
@@ -1,29 +0,0 @@
-/*
- * Copyright 2013-2016 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * https://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.springframework.cloud.netflix.hystrix.security;
-
-import org.springframework.boot.autoconfigure.SpringBootApplication;
-import org.springframework.context.annotation.Configuration;
-
-/**
- * @author Daniel Lavoie
- */
-@Configuration(proxyBeanMethods = false)
-@SpringBootApplication
-public class HystrixSecurityApplication {
-
-}
diff --git a/spring-cloud-netflix-hystrix/src/test/java/org/springframework/cloud/netflix/hystrix/security/HystrixSecurityAutoConfigurationTest.java b/spring-cloud-netflix-hystrix/src/test/java/org/springframework/cloud/netflix/hystrix/security/HystrixSecurityAutoConfigurationTest.java
deleted file mode 100644
index b1d0cf982..000000000
--- a/spring-cloud-netflix-hystrix/src/test/java/org/springframework/cloud/netflix/hystrix/security/HystrixSecurityAutoConfigurationTest.java
+++ /dev/null
@@ -1,125 +0,0 @@
-/*
- * Copyright 2013-2019 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * https://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.springframework.cloud.netflix.hystrix.security;
-
-import java.lang.reflect.Field;
-
-import com.netflix.hystrix.strategy.HystrixPlugins;
-import com.netflix.hystrix.strategy.concurrency.HystrixConcurrencyStrategy;
-import com.netflix.hystrix.strategy.concurrency.HystrixConcurrencyStrategyDefault;
-import com.netflix.hystrix.strategy.eventnotifier.HystrixEventNotifier;
-import com.netflix.hystrix.strategy.executionhook.HystrixCommandExecutionHook;
-import com.netflix.hystrix.strategy.metrics.HystrixMetricsPublisher;
-import com.netflix.hystrix.strategy.properties.HystrixPropertiesStrategy;
-import org.junit.Test;
-import org.mockito.internal.util.reflection.FieldSetter;
-
-import static org.assertj.core.api.Assertions.assertThat;
-
-/**
- * @author : ailin.zhou
- */
-public class HystrixSecurityAutoConfigurationTest {
-
- @Test
- public void testInit() throws NoSuchFieldException, IllegalAccessException {
-
- // save test context
- HystrixEventNotifier eventNotifier = HystrixPlugins.getInstance()
- .getEventNotifier();
- HystrixMetricsPublisher metricsPublisher = HystrixPlugins.getInstance()
- .getMetricsPublisher();
- HystrixPropertiesStrategy propertiesStrategy = HystrixPlugins.getInstance()
- .getPropertiesStrategy();
- HystrixCommandExecutionHook commandExecutionHook = HystrixPlugins.getInstance()
- .getCommandExecutionHook();
- HystrixConcurrencyStrategy concurrencyStrategy = HystrixPlugins.getInstance()
- .getConcurrencyStrategy();
-
- // test
- testForMultiConcurrentStrategy();
-
- // recover test context
- HystrixPlugins.reset();
- HystrixPlugins.getInstance().registerConcurrencyStrategy(concurrencyStrategy);
- HystrixPlugins.getInstance().registerEventNotifier(eventNotifier);
- HystrixPlugins.getInstance().registerMetricsPublisher(metricsPublisher);
- HystrixPlugins.getInstance().registerPropertiesStrategy(propertiesStrategy);
- HystrixPlugins.getInstance().registerCommandExecutionHook(commandExecutionHook);
-
- }
-
- private void testForMultiConcurrentStrategy()
- throws IllegalAccessException, NoSuchFieldException {
- HystrixSecurityAutoConfiguration securityStrategy = new HystrixSecurityAutoConfiguration();
-
- // 1.existingConcurrencyStrategy is null, registeredStrategy is default
- HystrixPlugins.reset();
- securityStrategy.init();
- // result is default
- assertThat(getOriginalInSecurityConcurrencyStrategy())
- .isEqualTo(HystrixConcurrencyStrategyDefault.getInstance());
-
- // 2.existingConcurrencyStrategy is null, registered strategy is customized
- HystrixPlugins.reset();
- HystrixConcurrencyStrategy customized = new HystrixConcurrencyStrategy() {
- };
- HystrixPlugins.getInstance().registerConcurrencyStrategy(customized);
- securityStrategy.init();
- // result is customized
- assertThat(getOriginalInSecurityConcurrencyStrategy()).isEqualTo(customized);
-
- // 3.existingConcurrencyStrategy is not null, registeredStrategy is default.
- HystrixPlugins.reset();
- HystrixConcurrencyStrategy existingConcurrencyStrategy = new HystrixConcurrencyStrategy() {
- };
- FieldSetter
- .setField(securityStrategy,
- securityStrategy.getClass()
- .getDeclaredField("existingConcurrencyStrategy"),
- existingConcurrencyStrategy);
- securityStrategy.init();
- // result is existingConcurrencyStrategy
- assertThat(getOriginalInSecurityConcurrencyStrategy())
- .isEqualTo(existingConcurrencyStrategy);
-
- // 4.existingConcurrencyStrategy is not null, registeredStrategy is customized.
- HystrixPlugins.reset();
- HystrixPlugins.getInstance().registerConcurrencyStrategy(customized);
- FieldSetter
- .setField(securityStrategy,
- securityStrategy.getClass()
- .getDeclaredField("existingConcurrencyStrategy"),
- existingConcurrencyStrategy);
- securityStrategy.init();
- assertThat(getOriginalInSecurityConcurrencyStrategy())
- .isEqualTo(existingConcurrencyStrategy);
- }
-
- private HystrixConcurrencyStrategy getOriginalInSecurityConcurrencyStrategy()
- throws IllegalAccessException, NoSuchFieldException {
- HystrixConcurrencyStrategy concurrencyStrategy = HystrixPlugins.getInstance()
- .getConcurrencyStrategy();
- Field existingConcurrencyStrategy = concurrencyStrategy.getClass()
- .getDeclaredField("existingConcurrencyStrategy");
- existingConcurrencyStrategy.setAccessible(true);
- HystrixConcurrencyStrategy strategyInSecurityStrategy = (HystrixConcurrencyStrategy) existingConcurrencyStrategy
- .get(concurrencyStrategy);
- return strategyInSecurityStrategy;
- }
-
-}
diff --git a/spring-cloud-netflix-hystrix/src/test/java/org/springframework/cloud/netflix/hystrix/security/HystrixSecurityNoFeignTests.java b/spring-cloud-netflix-hystrix/src/test/java/org/springframework/cloud/netflix/hystrix/security/HystrixSecurityNoFeignTests.java
deleted file mode 100644
index e79b80333..000000000
--- a/spring-cloud-netflix-hystrix/src/test/java/org/springframework/cloud/netflix/hystrix/security/HystrixSecurityNoFeignTests.java
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- * Copyright 2013-2019 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * https://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.springframework.cloud.netflix.hystrix.security;
-
-import com.netflix.hystrix.strategy.HystrixPlugins;
-import com.netflix.hystrix.strategy.concurrency.HystrixConcurrencyStrategy;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-
-import org.springframework.boot.test.context.SpringBootTest;
-import org.springframework.test.annotation.DirtiesContext;
-import org.springframework.test.context.junit4.SpringRunner;
-
-import static org.assertj.core.api.Assertions.assertThat;
-
-@RunWith(SpringRunner.class)
-@DirtiesContext
-@SpringBootTest(classes = HystrixSecurityApplication.class)
-public class HystrixSecurityNoFeignTests {
-
- @Test
- public void testSecurityConcurrencyStrategyInstalled() {
- HystrixConcurrencyStrategy concurrencyStrategy = HystrixPlugins.getInstance()
- .getConcurrencyStrategy();
- assertThat(concurrencyStrategy)
- .isInstanceOf(SecurityContextConcurrencyStrategy.class);
- }
-
-}
diff --git a/spring-cloud-netflix-hystrix/src/test/java/org/springframework/cloud/netflix/hystrix/security/app/CustomConcurrenyStrategy.java b/spring-cloud-netflix-hystrix/src/test/java/org/springframework/cloud/netflix/hystrix/security/app/CustomConcurrenyStrategy.java
deleted file mode 100644
index 5884ffcb5..000000000
--- a/spring-cloud-netflix-hystrix/src/test/java/org/springframework/cloud/netflix/hystrix/security/app/CustomConcurrenyStrategy.java
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * Copyright 2016-2019 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * https://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.springframework.cloud.netflix.hystrix.security.app;
-
-import java.util.concurrent.Callable;
-
-import com.netflix.hystrix.strategy.concurrency.HystrixConcurrencyStrategy;
-
-import org.springframework.stereotype.Component;
-
-@Component
-public class CustomConcurrenyStrategy extends HystrixConcurrencyStrategy {
-
- private boolean hookCalled;
-
- @Override
- public Callable wrapCallable(Callable callable) {
- this.hookCalled = true;
-
- return super.wrapCallable(callable);
- }
-
- public boolean isHookCalled() {
- return hookCalled;
- }
-
-}
diff --git a/spring-cloud-netflix-hystrix/src/test/java/org/springframework/cloud/netflix/hystrix/security/app/UsernameController.java b/spring-cloud-netflix-hystrix/src/test/java/org/springframework/cloud/netflix/hystrix/security/app/UsernameController.java
deleted file mode 100644
index 91806236f..000000000
--- a/spring-cloud-netflix-hystrix/src/test/java/org/springframework/cloud/netflix/hystrix/security/app/UsernameController.java
+++ /dev/null
@@ -1,35 +0,0 @@
-/*
- * Copyright 2013-2019 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * https://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.springframework.cloud.netflix.hystrix.security.app;
-
-import org.springframework.web.bind.annotation.RequestHeader;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
-
-/**
- * @author Daniel Lavoie
- */
-@RestController
-@RequestMapping("/username")
-public class UsernameController {
-
- @RequestMapping
- public String getUsername(@RequestHeader String username) {
- return username;
- }
-
-}
diff --git a/spring-cloud-netflix-hystrix/src/test/java/org/springframework/cloud/netflix/resttemplate/RestTemplateRetryTests.java b/spring-cloud-netflix-hystrix/src/test/java/org/springframework/cloud/netflix/resttemplate/RestTemplateRetryTests.java
deleted file mode 100644
index 9b990457f..000000000
--- a/spring-cloud-netflix-hystrix/src/test/java/org/springframework/cloud/netflix/resttemplate/RestTemplateRetryTests.java
+++ /dev/null
@@ -1,314 +0,0 @@
-/*
- * Copyright 2013-2019 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * https://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.springframework.cloud.netflix.resttemplate;
-
-import java.net.UnknownHostException;
-import java.util.Arrays;
-import java.util.concurrent.atomic.AtomicInteger;
-
-import com.netflix.client.RetryHandler;
-import com.netflix.client.config.IClientConfig;
-import com.netflix.loadbalancer.AvailabilityFilteringRule;
-import com.netflix.loadbalancer.BaseLoadBalancer;
-import com.netflix.loadbalancer.ILoadBalancer;
-import com.netflix.loadbalancer.IPing;
-import com.netflix.loadbalancer.IRule;
-import com.netflix.loadbalancer.LoadBalancerBuilder;
-import com.netflix.loadbalancer.LoadBalancerStats;
-import com.netflix.loadbalancer.Server;
-import com.netflix.loadbalancer.ServerList;
-import com.netflix.loadbalancer.ServerStats;
-import com.netflix.niws.client.http.HttpClientLoadBalancerErrorHandler;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.beans.factory.annotation.Value;
-import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
-import org.springframework.boot.test.context.SpringBootTest;
-import org.springframework.cloud.client.loadbalancer.LoadBalanced;
-import org.springframework.cloud.netflix.ribbon.RibbonClient;
-import org.springframework.cloud.netflix.test.NoSecurityConfiguration;
-import org.springframework.context.annotation.Bean;
-import org.springframework.context.annotation.Configuration;
-import org.springframework.context.annotation.Import;
-import org.springframework.test.annotation.DirtiesContext;
-import org.springframework.test.context.junit4.SpringRunner;
-import org.springframework.util.SocketUtils;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RequestMethod;
-import org.springframework.web.bind.annotation.RestController;
-import org.springframework.web.client.RestTemplate;
-
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT;
-
-@RunWith(SpringRunner.class)
-@SpringBootTest(classes = RestTemplateRetryTests.Application.class,
- webEnvironment = RANDOM_PORT,
- properties = { "spring.application.name=resttemplatetest",
- "logging.level.com.netflix=DEBUG",
- "logging.level.org.springframework.cloud.netflix.resttemplate=DEBUG",
- "logging.level.com.netflix=DEBUG", "badClients.ribbon.MaxAutoRetries=25",
- "badClients.ribbon.OkToRetryOnAllOperations=true",
- "ribbon.http.client.enabled" })
-@DirtiesContext
-public class RestTemplateRetryTests {
-
- private static final Log logger = LogFactory.getLog(RestTemplateRetryTests.class);
-
- @Autowired
- private RestTemplate testClient;
-
- @Before
- public void setup() throws Exception {
- // Force Ribbon configuration by making one call.
- this.testClient.getForObject("http://badClients/ping", Integer.class);
- }
-
- @Test
- public void testNullPointer() throws Exception {
-
- LoadBalancerStats stats = LocalBadClientConfiguration.balancer
- .getLoadBalancerStats();
- ServerStats badServer1Stats = stats
- .getSingleServerStat(LocalBadClientConfiguration.badServer);
- ServerStats badServer2Stats = stats
- .getSingleServerStat(LocalBadClientConfiguration.badServer2);
- ServerStats goodServerStats = stats
- .getSingleServerStat(LocalBadClientConfiguration.goodServer);
-
- badServer1Stats.clearSuccessiveConnectionFailureCount();
- badServer2Stats.clearSuccessiveConnectionFailureCount();
- int numCalls = 10;
- long targetConnectionCount = goodServerStats.getTotalRequestsCount() + numCalls;
-
- // A null pointer should NOT trigger a circuit breaker.
- for (int index = 0; index < numCalls; index++) {
- try {
- this.testClient.getForObject("http://badClients/null", Integer.class);
- }
- catch (Exception exception) {
- }
- }
- logServerStats(LocalBadClientConfiguration.badServer);
- logServerStats(LocalBadClientConfiguration.badServer2);
- logServerStats(LocalBadClientConfiguration.goodServer);
-
- assertThat(badServer1Stats.isCircuitBreakerTripped()).isTrue();
- assertThat(badServer2Stats.isCircuitBreakerTripped()).isTrue();
- assertThat(targetConnectionCount)
- .isLessThanOrEqualTo(goodServerStats.getTotalRequestsCount());
-
- // Wait for any timeout thread to finish.
-
- }
-
- private void logServerStats(Server server) {
- LoadBalancerStats stats = LocalBadClientConfiguration.balancer
- .getLoadBalancerStats();
- ServerStats serverStats = stats.getSingleServerStat(server);
- logger.debug("Server : " + server.toString() + " : Total Count == "
- + serverStats.getTotalRequestsCount() + ", Failure Count == "
- + serverStats.getFailureCount() + ", Successive Connection Failure == "
- + serverStats.getSuccessiveConnectionFailureCount()
- + ", Circuit Breaker ? == " + serverStats.isCircuitBreakerTripped());
- }
-
- @Test
- public void testRestRetries() {
-
- LoadBalancerStats stats = LocalBadClientConfiguration.balancer
- .getLoadBalancerStats();
- ServerStats badServer1Stats = stats
- .getSingleServerStat(LocalBadClientConfiguration.badServer);
- ServerStats badServer2Stats = stats
- .getSingleServerStat(LocalBadClientConfiguration.badServer2);
- ServerStats goodServerStats = stats
- .getSingleServerStat(LocalBadClientConfiguration.goodServer);
-
- badServer1Stats.clearSuccessiveConnectionFailureCount();
- badServer2Stats.clearSuccessiveConnectionFailureCount();
- int numCalls = 20;
- long targetConnectionCount = goodServerStats.getTotalRequestsCount() + numCalls;
-
- int hits = 0;
-
- for (int index = 0; index < numCalls; index++) {
- hits = this.testClient.getForObject("http://badClients/good", Integer.class);
- }
-
- logServerStats(LocalBadClientConfiguration.badServer);
- logServerStats(LocalBadClientConfiguration.badServer2);
- logServerStats(LocalBadClientConfiguration.goodServer);
-
- assertThat(badServer1Stats.isCircuitBreakerTripped()).isTrue();
- assertThat(badServer2Stats.isCircuitBreakerTripped()).isTrue();
- assertThat(targetConnectionCount)
- .isLessThanOrEqualTo(goodServerStats.getTotalRequestsCount());
- assertThat(hits).isGreaterThanOrEqualTo(numCalls);
- logger.debug("Retry Hits: " + hits);
- }
-
- @Test
- public void testRestRetriesWithReadTimeout() throws Exception {
-
- LoadBalancerStats stats = LocalBadClientConfiguration.balancer
- .getLoadBalancerStats();
- ServerStats badServer1Stats = stats
- .getSingleServerStat(LocalBadClientConfiguration.badServer);
- ServerStats badServer2Stats = stats
- .getSingleServerStat(LocalBadClientConfiguration.badServer2);
- ServerStats goodServerStats = stats
- .getSingleServerStat(LocalBadClientConfiguration.goodServer);
-
- badServer1Stats.clearSuccessiveConnectionFailureCount();
- badServer2Stats.clearSuccessiveConnectionFailureCount();
- assertThat(!badServer1Stats.isCircuitBreakerTripped()).isTrue();
- assertThat(!badServer2Stats.isCircuitBreakerTripped()).isTrue();
-
- int hits = 0;
-
- int numCalls = 15;
- for (int index = 0; index < numCalls; index++) {
- hits = this.testClient.getForObject("http://badClients/timeout",
- Integer.class);
- }
- logServerStats(LocalBadClientConfiguration.badServer);
- logServerStats(LocalBadClientConfiguration.badServer2);
- logServerStats(LocalBadClientConfiguration.goodServer);
-
- assertThat(badServer1Stats.isCircuitBreakerTripped()).isTrue();
- assertThat(badServer2Stats.isCircuitBreakerTripped()).isTrue();
- assertThat(!goodServerStats.isCircuitBreakerTripped()).isTrue();
-
- // 15 + 4 timeouts. See the endpoint for timeout conditions.
- assertThat(hits).isGreaterThanOrEqualTo(numCalls + 4);
-
- // Wait for any timeout thread to finish.
- Thread.sleep(600);
-
- }
-
- @Configuration(proxyBeanMethods = false)
- @EnableAutoConfiguration
- @RestController
- @RibbonClient(name = "badClients", configuration = LocalBadClientConfiguration.class)
- @Import(NoSecurityConfiguration.class)
- public static class Application {
-
- private AtomicInteger hits = new AtomicInteger(1);
-
- private AtomicInteger retryHits = new AtomicInteger(1);
-
- @RequestMapping(method = RequestMethod.GET, value = "/ping")
- public int ping() {
- return 0;
- }
-
- @RequestMapping(method = RequestMethod.GET, value = "/good")
- public int good() {
- int lValue = this.hits.getAndIncrement();
- return lValue;
- }
-
- @RequestMapping(method = RequestMethod.GET, value = "/timeout")
- public int timeout() throws Exception {
- int lValue = this.retryHits.getAndIncrement();
-
- // Force the good server to have 2 consecutive errors a couple of times.
- if (lValue == 2 || lValue == 3 || lValue == 5 || lValue == 6) {
- Thread.sleep(500);
- }
- return lValue;
- }
-
- @RequestMapping(method = RequestMethod.GET, value = "/null")
- public int isNull() throws Exception {
- throw new NullPointerException("Null");
- }
-
- @LoadBalanced
- @Bean
- RestTemplate restTemplate() {
- return new RestTemplate();
- }
-
- }
-
- // Load balancer with fixed server list for "local" pointing to localhost
- // and some bogus servers are thrown in to test retry
- @Configuration(proxyBeanMethods = false)
- static class LocalBadClientConfiguration {
-
- static BaseLoadBalancer balancer;
- static Server goodServer;
- static Server badServer;
- static Server badServer2;
-
- LocalBadClientConfiguration() {
- }
-
- @Value("${local.server.port}")
- private int port = 0;
-
- @Bean
- public IRule loadBalancerRule() {
- // This is a good place to try different load balancing rules and how those
- // rules
- // behave in failure states: BestAvailableRule, WeightedResponseTimeRule, etc
-
- // This rule just uses a round robin and will skip servers that are in circuit
- // breaker state.
- return new AvailabilityFilteringRule();
-
- }
-
- @Bean
- public ILoadBalancer ribbonLoadBalancer(IClientConfig config,
- ServerList serverList, IRule rule, IPing ping) {
-
- goodServer = new Server("localhost", this.port);
- badServer = new Server("mybadhost", 10001);
- badServer2 = new Server("localhost", SocketUtils.findAvailableTcpPort());
-
- balancer = LoadBalancerBuilder.newBuilder().withClientConfig(config)
- .withRule(rule).withPing(ping).buildFixedServerListLoadBalancer(
- Arrays.asList(badServer, badServer2, goodServer));
- return balancer;
- }
-
- @Bean
- public RetryHandler retryHandler() {
- return new OverrideRetryHandler();
- }
-
- static class OverrideRetryHandler extends HttpClientLoadBalancerErrorHandler {
-
- OverrideRetryHandler() {
- this.circuitRelated.add(UnknownHostException.class);
- this.retriable.add(UnknownHostException.class);
- }
-
- }
-
- }
-
-}
diff --git a/spring-cloud-netflix-hystrix/src/test/java/org/springframework/cloud/netflix/ribbon/apache/HttpClientStatusCodeExceptionTest.java b/spring-cloud-netflix-hystrix/src/test/java/org/springframework/cloud/netflix/ribbon/apache/HttpClientStatusCodeExceptionTest.java
deleted file mode 100644
index 8a5778754..000000000
--- a/spring-cloud-netflix-hystrix/src/test/java/org/springframework/cloud/netflix/ribbon/apache/HttpClientStatusCodeExceptionTest.java
+++ /dev/null
@@ -1,80 +0,0 @@
-/*
- * Copyright 2013-2019 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * https://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.springframework.cloud.netflix.ribbon.apache;
-
-import java.io.ByteArrayInputStream;
-import java.net.URI;
-import java.util.Locale;
-
-import org.apache.http.Header;
-import org.apache.http.HttpEntity;
-import org.apache.http.ProtocolVersion;
-import org.apache.http.StatusLine;
-import org.apache.http.client.methods.CloseableHttpResponse;
-import org.apache.http.entity.BasicHttpEntity;
-import org.apache.http.message.BasicHeader;
-import org.apache.http.message.BasicStatusLine;
-import org.apache.http.util.EntityUtils;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.junit.MockitoJUnitRunner;
-
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.mockito.Mockito.doReturn;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.times;
-import static org.mockito.Mockito.verify;
-
-/**
- * @author Ryan Baxter
- */
-@RunWith(MockitoJUnitRunner.class)
-public class HttpClientStatusCodeExceptionTest {
-
- @Test
- public void getResponse() throws Exception {
- CloseableHttpResponse response = mock(CloseableHttpResponse.class);
- doReturn(new Locale("en")).when(response).getLocale();
- Header foo = new BasicHeader("foo", "bar");
- Header[] headers = new Header[] { foo };
- doReturn(headers).when(response).getAllHeaders();
- StatusLine statusLine = new BasicStatusLine(new ProtocolVersion("http", 1, 1),
- 200, "Success");
- doReturn(statusLine).when(response).getStatusLine();
- BasicHttpEntity entity = new BasicHttpEntity();
- entity.setContent(new ByteArrayInputStream("foo".getBytes()));
- entity.setContentLength(3);
- doReturn(entity).when(response).getEntity();
- HttpEntity copiedEntity = HttpClientUtils.createEntity(response);
- HttpClientStatusCodeException ex = new HttpClientStatusCodeException("service",
- response, copiedEntity, new URI("https://service.com"));
- assertThat(ex.getResponse().getLocale().toString()).isEqualTo("en");
- assertThat(ex.getResponse().getAllHeaders()).isEqualTo(headers);
- assertThat(ex.getResponse().getStatusLine().getReasonPhrase())
- .isEqualTo("Success");
- assertThat(ex.getResponse().getStatusLine().getStatusCode()).isEqualTo(200);
- assertThat(ex.getResponse().getStatusLine().getProtocolVersion().getProtocol())
- .isEqualTo("http");
- assertThat(ex.getResponse().getStatusLine().getProtocolVersion().getMajor())
- .isEqualTo(1);
- assertThat(ex.getResponse().getStatusLine().getProtocolVersion().getMinor())
- .isEqualTo(1);
- assertThat(EntityUtils.toString(ex.getResponse().getEntity())).isEqualTo("foo");
- verify(response, times(1)).close();
- }
-
-}
diff --git a/spring-cloud-netflix-hystrix/src/test/java/org/springframework/cloud/netflix/ribbon/okhttp/OkHttpStatusCodeExceptionTest.java b/spring-cloud-netflix-hystrix/src/test/java/org/springframework/cloud/netflix/ribbon/okhttp/OkHttpStatusCodeExceptionTest.java
deleted file mode 100644
index 31a231462..000000000
--- a/spring-cloud-netflix-hystrix/src/test/java/org/springframework/cloud/netflix/ribbon/okhttp/OkHttpStatusCodeExceptionTest.java
+++ /dev/null
@@ -1,58 +0,0 @@
-/*
- * Copyright 2013-2019 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * https://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.springframework.cloud.netflix.ribbon.okhttp;
-
-import java.net.URI;
-
-import okhttp3.Headers;
-import okhttp3.MediaType;
-import okhttp3.Protocol;
-import okhttp3.Request;
-import okhttp3.Response;
-import okhttp3.ResponseBody;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.junit.MockitoJUnitRunner;
-
-import static org.assertj.core.api.Assertions.assertThat;
-
-/**
- * @author Ryan Baxter
- */
-@RunWith(MockitoJUnitRunner.class)
-public class OkHttpStatusCodeExceptionTest {
-
- @Test
- public void getResponse() throws Exception {
- Headers headers = new Headers.Builder().add("foo", "bar").build();
- Response response = new Response.Builder().code(200).headers(headers).code(200)
- .message("Success")
- .body(ResponseBody.create(MediaType.parse("text/plain"), "foo"))
- .protocol(Protocol.HTTP_1_1)
- .request(new Request.Builder().url("https://service.com").build())
- .build();
- ResponseBody body = response.peekBody(Integer.MAX_VALUE);
- OkHttpStatusCodeException ex = new OkHttpStatusCodeException("service", response,
- body, new URI("https://service.com"));
- assertThat(ex.getResponse().headers()).isEqualTo(headers);
- assertThat(ex.getResponse().code()).isEqualTo(200);
- assertThat(ex.getResponse().message()).isEqualTo("Success");
- assertThat(ex.getResponse().body().string()).isEqualTo("foo");
- assertThat(ex.getResponse().protocol()).isEqualTo(Protocol.HTTP_1_1);
- }
-
-}
diff --git a/spring-cloud-netflix-hystrix/src/test/java/org/springframework/cloud/netflix/test/NoSecurityConfiguration.java b/spring-cloud-netflix-hystrix/src/test/java/org/springframework/cloud/netflix/test/NoSecurityConfiguration.java
deleted file mode 100644
index 889476863..000000000
--- a/spring-cloud-netflix-hystrix/src/test/java/org/springframework/cloud/netflix/test/NoSecurityConfiguration.java
+++ /dev/null
@@ -1,31 +0,0 @@
-/*
- * Copyright 2013-2019 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * https://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.springframework.cloud.netflix.test;
-
-import org.springframework.context.annotation.Configuration;
-import org.springframework.security.config.annotation.web.builders.HttpSecurity;
-import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
-
-@Configuration(proxyBeanMethods = false)
-public class NoSecurityConfiguration extends WebSecurityConfigurerAdapter {
-
- @Override
- protected void configure(HttpSecurity http) throws Exception {
- http.authorizeRequests().anyRequest().permitAll().and().csrf().disable();
- }
-
-}
diff --git a/spring-cloud-netflix-hystrix/src/test/java/org/springframework/cloud/netflix/test/TestAutoConfiguration.java b/spring-cloud-netflix-hystrix/src/test/java/org/springframework/cloud/netflix/test/TestAutoConfiguration.java
deleted file mode 100644
index 3b56a87b9..000000000
--- a/spring-cloud-netflix-hystrix/src/test/java/org/springframework/cloud/netflix/test/TestAutoConfiguration.java
+++ /dev/null
@@ -1,71 +0,0 @@
-/*
- * Copyright 2013-2019 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * https://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.springframework.cloud.netflix.test;
-
-import org.springframework.boot.autoconfigure.AutoConfigureBefore;
-import org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration;
-import org.springframework.cloud.client.discovery.noop.NoopDiscoveryClientAutoConfiguration;
-import org.springframework.context.annotation.Bean;
-import org.springframework.context.annotation.Configuration;
-import org.springframework.context.annotation.Import;
-import org.springframework.core.Ordered;
-import org.springframework.core.annotation.Order;
-import org.springframework.security.config.annotation.web.builders.HttpSecurity;
-import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
-import org.springframework.security.core.userdetails.User;
-import org.springframework.security.core.userdetails.UserDetailsService;
-import org.springframework.security.provisioning.InMemoryUserDetailsManager;
-
-/**
- * @author Spencer Gibb
- */
-@Configuration(proxyBeanMethods = false)
-@Import({ NoopDiscoveryClientAutoConfiguration.class })
-@AutoConfigureBefore(SecurityAutoConfiguration.class)
-public class TestAutoConfiguration {
-
- public static final String USER = "user";
-
- public static final String PASSWORD = "{noop}password";
-
- @Configuration(proxyBeanMethods = false)
- @Order(Ordered.HIGHEST_PRECEDENCE)
- protected static class TestSecurityConfiguration
- extends WebSecurityConfigurerAdapter {
-
- TestSecurityConfiguration() {
- super(true);
- }
-
- @Bean
- public UserDetailsService userDetailsService() {
- InMemoryUserDetailsManager manager = new InMemoryUserDetailsManager();
- manager.createUser(
- User.withUsername(USER).password(PASSWORD).roles("USER").build());
- return manager;
- }
-
- @Override
- protected void configure(HttpSecurity http) throws Exception {
- // super.configure(http);
- http.antMatcher("/proxy-username").httpBasic().and().authorizeRequests()
- .antMatchers("/**").permitAll();
- }
-
- }
-
-}
diff --git a/spring-cloud-netflix-hystrix/src/test/resources/META-INF/spring.factories b/spring-cloud-netflix-hystrix/src/test/resources/META-INF/spring.factories
deleted file mode 100644
index 60ea354e8..000000000
--- a/spring-cloud-netflix-hystrix/src/test/resources/META-INF/spring.factories
+++ /dev/null
@@ -1,2 +0,0 @@
-org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
-org.springframework.cloud.netflix.test.TestAutoConfiguration
diff --git a/spring-cloud-netflix-hystrix/src/test/resources/application.yml b/spring-cloud-netflix-hystrix/src/test/resources/application.yml
deleted file mode 100644
index 82d37798a..000000000
--- a/spring-cloud-netflix-hystrix/src/test/resources/application.yml
+++ /dev/null
@@ -1,35 +0,0 @@
-server:
- port: 9999
- compression:
- enabled: true
- min-response-size: 1024
- mime-types: application/xml,application/json
-spring:
- application:
- name: testclient
-eureka:
- server:
- enabled: false
- client:
- registerWithEureka: false
- fetchRegistry: false
-#error:
-# path: /myerror
-hystrix.command.default.execution.isolation.thread.timeoutInMilliseconds: 60000
-ribbon:
- ConnectTimeout: 3001
- ReadTimeout: 60001
-foo:
- ribbon:
- ConnectTimeout: 7
- ReadTimeout: 17
-badClients:
- ribbon:
- MaxAutoRetriesNextServer: 10
- ReadTimeout: 200
-endpoints:
- health:
- sensitive: false
-hystrix:
- shareSecurityContext: true
-management.endpoints.web.exposure.include: '*'
diff --git a/spring-cloud-netflix-hystrix/src/test/resources/archaius_db_store.sql b/spring-cloud-netflix-hystrix/src/test/resources/archaius_db_store.sql
deleted file mode 100644
index 6b914cb50..000000000
--- a/spring-cloud-netflix-hystrix/src/test/resources/archaius_db_store.sql
+++ /dev/null
@@ -1,8 +0,0 @@
-create table if not exists properties (
- property_key VARCHAR(40) NOT NULL PRIMARY KEY,
- property_value VARCHAR(255) NOT NULL,
-);
-
-insert into properties(property_key, property_value) values ('db.property','this is a db property');
-insert into properties(property_key, property_value) values ('db.second.property','this is another db property');
-
diff --git a/spring-cloud-netflix-hystrix/src/test/resources/config.properties.bak b/spring-cloud-netflix-hystrix/src/test/resources/config.properties.bak
deleted file mode 100644
index 1e9c021f4..000000000
--- a/spring-cloud-netflix-hystrix/src/test/resources/config.properties.bak
+++ /dev/null
@@ -1,2 +0,0 @@
-archaius.file.property=Static config file property
-db.second.property=It should be overridden
diff --git a/spring-cloud-netflix-hystrix/src/test/resources/static/index.html b/spring-cloud-netflix-hystrix/src/test/resources/static/index.html
deleted file mode 100644
index 27f581907..000000000
--- a/spring-cloud-netflix-hystrix/src/test/resources/static/index.html
+++ /dev/null
@@ -1,28 +0,0 @@
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/spring-cloud-netflix-ribbon/pom.xml b/spring-cloud-netflix-ribbon/pom.xml
deleted file mode 100644
index fa9d6440c..000000000
--- a/spring-cloud-netflix-ribbon/pom.xml
+++ /dev/null
@@ -1,128 +0,0 @@
-
-
-
- spring-cloud-netflix
- org.springframework.cloud
- 2.2.2.BUILD-SNAPSHOT
- ..
-
- 4.0.0
-
- org.springframework.cloud
- spring-cloud-netflix-ribbon
-
-
-
- org.springframework.boot
- spring-boot-starter-web
- true
-
-
- org.springframework.boot
- spring-boot
- true
-
-
- org.springframework.boot
- spring-boot-autoconfigure
- true
-
-
- org.springframework.boot
- spring-boot-configuration-processor
- true
-
-
- org.springframework.cloud
- spring-cloud-commons
- true
-
-
- org.springframework.cloud
- spring-cloud-context
- true
-
-
- org.springframework.cloud
- spring-cloud-netflix-archaius
-
-
- com.netflix.ribbon
- ribbon
- true
-
-
- com.netflix.ribbon
- ribbon-core
- true
-
-
- com.netflix.ribbon
- ribbon-httpclient
- true
-
-
- com.netflix.ribbon
- ribbon-loadbalancer
- true
-
-
-
- com.sun.jersey.contribs
- jersey-apache-client4
- true
-
-
- com.squareup.okhttp3
- okhttp
- true
-
-
- org.springframework.retry
- spring-retry
- true
-
-
- commons-configuration
- commons-configuration
- true
-
-
- com.netflix.servo
- servo-core
- true
-
-
- com.netflix.netflix-commons
- netflix-commons-util
- true
-
-
- com.netflix.hystrix
- hystrix-javanica
- true
-
-
- org.springframework.cloud
- spring-cloud-test-support
- test
-
-
- org.springframework.boot
- spring-boot-starter-test
- test
-
-
- org.springframework.boot
- spring-boot-starter-security
- test
-
-
- org.springframework.boot
- spring-boot-starter-actuator
- test
-
-
-
\ No newline at end of file
diff --git a/spring-cloud-netflix-ribbon/src/main/java/org/springframework/cloud/netflix/ribbon/DefaultServerIntrospector.java b/spring-cloud-netflix-ribbon/src/main/java/org/springframework/cloud/netflix/ribbon/DefaultServerIntrospector.java
deleted file mode 100644
index 222a832a2..000000000
--- a/spring-cloud-netflix-ribbon/src/main/java/org/springframework/cloud/netflix/ribbon/DefaultServerIntrospector.java
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * Copyright 2013-2019 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * https://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.springframework.cloud.netflix.ribbon;
-
-import java.util.Collections;
-import java.util.Map;
-
-import com.netflix.loadbalancer.Server;
-
-import org.springframework.beans.factory.annotation.Autowired;
-
-/**
- * @author Spencer Gibb
- */
-public class DefaultServerIntrospector implements ServerIntrospector {
-
- private ServerIntrospectorProperties serverIntrospectorProperties = new ServerIntrospectorProperties();
-
- @Autowired(required = false)
- public void setServerIntrospectorProperties(
- ServerIntrospectorProperties serverIntrospectorProperties) {
- this.serverIntrospectorProperties = serverIntrospectorProperties;
- }
-
- @Override
- public boolean isSecure(Server server) {
- return serverIntrospectorProperties.getSecurePorts().contains(server.getPort());
- }
-
- @Override
- public Map getMetadata(Server server) {
- return Collections.emptyMap();
- }
-
-}
diff --git a/spring-cloud-netflix-ribbon/src/main/java/org/springframework/cloud/netflix/ribbon/PropertiesFactory.java b/spring-cloud-netflix-ribbon/src/main/java/org/springframework/cloud/netflix/ribbon/PropertiesFactory.java
deleted file mode 100644
index 9786a4e55..000000000
--- a/spring-cloud-netflix-ribbon/src/main/java/org/springframework/cloud/netflix/ribbon/PropertiesFactory.java
+++ /dev/null
@@ -1,84 +0,0 @@
-/*
- * Copyright 2016-2019 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * https://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.springframework.cloud.netflix.ribbon;
-
-import java.util.HashMap;
-import java.util.Map;
-
-import com.netflix.client.config.IClientConfig;
-import com.netflix.loadbalancer.ILoadBalancer;
-import com.netflix.loadbalancer.IPing;
-import com.netflix.loadbalancer.IRule;
-import com.netflix.loadbalancer.ServerList;
-import com.netflix.loadbalancer.ServerListFilter;
-
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.core.env.Environment;
-import org.springframework.util.StringUtils;
-
-import static org.springframework.cloud.netflix.ribbon.SpringClientFactory.NAMESPACE;
-
-/**
- * @author Spencer Gibb
- */
-public class PropertiesFactory {
-
- @Autowired
- private Environment environment;
-
- private Map classToProperty = new HashMap<>();
-
- public PropertiesFactory() {
- classToProperty.put(ILoadBalancer.class, "NFLoadBalancerClassName");
- classToProperty.put(IPing.class, "NFLoadBalancerPingClassName");
- classToProperty.put(IRule.class, "NFLoadBalancerRuleClassName");
- classToProperty.put(ServerList.class, "NIWSServerListClassName");
- classToProperty.put(ServerListFilter.class, "NIWSServerListFilterClassName");
- }
-
- public boolean isSet(Class clazz, String name) {
- return StringUtils.hasText(getClassName(clazz, name));
- }
-
- public String getClassName(Class clazz, String name) {
- if (this.classToProperty.containsKey(clazz)) {
- String classNameProperty = this.classToProperty.get(clazz);
- String className = environment
- .getProperty(name + "." + NAMESPACE + "." + classNameProperty);
- return className;
- }
- return null;
- }
-
- @SuppressWarnings("unchecked")
- public C get(Class clazz, IClientConfig config, String name) {
- String className = getClassName(clazz, name);
- if (StringUtils.hasText(className)) {
- try {
- Class> toInstantiate = Class.forName(className);
- return (C) SpringClientFactory.instantiateWithConfig(toInstantiate,
- config);
- }
- catch (ClassNotFoundException e) {
- throw new IllegalArgumentException("Unknown class to load " + className
- + " for class " + clazz + " named " + name);
- }
- }
- return null;
- }
-
-}
diff --git a/spring-cloud-netflix-ribbon/src/main/java/org/springframework/cloud/netflix/ribbon/RestClientRibbonConfiguration.java b/spring-cloud-netflix-ribbon/src/main/java/org/springframework/cloud/netflix/ribbon/RestClientRibbonConfiguration.java
deleted file mode 100644
index 4260027e6..000000000
--- a/spring-cloud-netflix-ribbon/src/main/java/org/springframework/cloud/netflix/ribbon/RestClientRibbonConfiguration.java
+++ /dev/null
@@ -1,64 +0,0 @@
-/*
- * Copyright 2013-2019 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * https://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.springframework.cloud.netflix.ribbon;
-
-import com.netflix.client.AbstractLoadBalancerAwareClient;
-import com.netflix.client.RetryHandler;
-import com.netflix.client.config.IClientConfig;
-import com.netflix.loadbalancer.ILoadBalancer;
-import com.netflix.niws.client.http.RestClient;
-
-import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
-import org.springframework.context.annotation.Bean;
-import org.springframework.context.annotation.Configuration;
-import org.springframework.context.annotation.Lazy;
-
-/**
- * @author Spencer Gibb
- */
-@SuppressWarnings("deprecation")
-@Configuration(proxyBeanMethods = false)
-@RibbonAutoConfiguration.ConditionalOnRibbonRestClient
-class RestClientRibbonConfiguration {
-
- @RibbonClientName
- private String name = "client";
-
- /**
- * Create a Netflix {@link RestClient} integrated with Ribbon if none already exists
- * in the application context. It is not required for Ribbon to work properly and is
- * therefore created lazily if ever another component requires it.
- * @param config the configuration to use by the underlying Ribbon instance
- * @param loadBalancer the load balancer to use by the underlying Ribbon instance
- * @param serverIntrospector server introspector to use by the underlying Ribbon
- * instance
- * @param retryHandler retry handler to use by the underlying Ribbon instance
- * @return a {@link RestClient} instances backed by Ribbon
- */
- @Bean
- @Lazy
- @ConditionalOnMissingBean(AbstractLoadBalancerAwareClient.class)
- public RestClient ribbonRestClient(IClientConfig config, ILoadBalancer loadBalancer,
- ServerIntrospector serverIntrospector, RetryHandler retryHandler) {
- RestClient client = new RibbonClientConfiguration.OverrideRestClient(config,
- serverIntrospector);
- client.setLoadBalancer(loadBalancer);
- client.setRetryHandler(retryHandler);
- return client;
- }
-
-}
diff --git a/spring-cloud-netflix-ribbon/src/main/java/org/springframework/cloud/netflix/ribbon/RibbonApplicationContextInitializer.java b/spring-cloud-netflix-ribbon/src/main/java/org/springframework/cloud/netflix/ribbon/RibbonApplicationContextInitializer.java
deleted file mode 100644
index 1a54530a4..000000000
--- a/spring-cloud-netflix-ribbon/src/main/java/org/springframework/cloud/netflix/ribbon/RibbonApplicationContextInitializer.java
+++ /dev/null
@@ -1,57 +0,0 @@
-/*
- * Copyright 2017-2019 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * https://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.springframework.cloud.netflix.ribbon;
-
-import java.util.List;
-
-import org.springframework.boot.context.event.ApplicationReadyEvent;
-import org.springframework.context.ApplicationListener;
-
-/**
- * Responsible for eagerly creating the child application context holding the Ribbon
- * related configuration.
- *
- * @author Biju Kunjummen
- */
-public class RibbonApplicationContextInitializer
- implements ApplicationListener {
-
- private final SpringClientFactory springClientFactory;
-
- // List of Ribbon client names
- private final List clientNames;
-
- public RibbonApplicationContextInitializer(SpringClientFactory springClientFactory,
- List clientNames) {
- this.springClientFactory = springClientFactory;
- this.clientNames = clientNames;
- }
-
- protected void initialize() {
- if (clientNames != null) {
- for (String clientName : clientNames) {
- this.springClientFactory.getContext(clientName);
- }
- }
- }
-
- @Override
- public void onApplicationEvent(ApplicationReadyEvent event) {
- initialize();
- }
-
-}
diff --git a/spring-cloud-netflix-ribbon/src/main/java/org/springframework/cloud/netflix/ribbon/RibbonAutoConfiguration.java b/spring-cloud-netflix-ribbon/src/main/java/org/springframework/cloud/netflix/ribbon/RibbonAutoConfiguration.java
deleted file mode 100644
index 3755b8750..000000000
--- a/spring-cloud-netflix-ribbon/src/main/java/org/springframework/cloud/netflix/ribbon/RibbonAutoConfiguration.java
+++ /dev/null
@@ -1,198 +0,0 @@
-/*
- * Copyright 2013-2019 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * https://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.springframework.cloud.netflix.ribbon;
-
-import java.lang.annotation.Documented;
-import java.lang.annotation.ElementType;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.lang.annotation.Target;
-import java.util.ArrayList;
-import java.util.List;
-
-import com.netflix.client.IClient;
-import com.netflix.client.http.HttpRequest;
-import com.netflix.ribbon.Ribbon;
-
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.boot.autoconfigure.AutoConfigureAfter;
-import org.springframework.boot.autoconfigure.AutoConfigureBefore;
-import org.springframework.boot.autoconfigure.condition.AllNestedConditions;
-import org.springframework.boot.autoconfigure.condition.AnyNestedCondition;
-import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
-import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
-import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
-import org.springframework.boot.context.properties.EnableConfigurationProperties;
-import org.springframework.cloud.client.actuator.HasFeatures;
-import org.springframework.cloud.client.loadbalancer.AsyncLoadBalancerAutoConfiguration;
-import org.springframework.cloud.client.loadbalancer.LoadBalancedRetryFactory;
-import org.springframework.cloud.client.loadbalancer.LoadBalancerAutoConfiguration;
-import org.springframework.cloud.client.loadbalancer.LoadBalancerClient;
-import org.springframework.cloud.client.loadbalancer.RestTemplateCustomizer;
-import org.springframework.context.annotation.Bean;
-import org.springframework.context.annotation.Conditional;
-import org.springframework.context.annotation.Configuration;
-import org.springframework.web.client.AsyncRestTemplate;
-import org.springframework.web.client.RestTemplate;
-
-/**
- * Auto configuration for Ribbon (client side load balancing).
- *
- * @author Spencer Gibb
- * @author Dave Syer
- * @author Biju Kunjummen
- */
-@Configuration
-@Conditional(RibbonAutoConfiguration.RibbonClassesConditions.class)
-@RibbonClients
-@AutoConfigureAfter(
- name = "org.springframework.cloud.netflix.eureka.EurekaClientAutoConfiguration")
-@AutoConfigureBefore({ LoadBalancerAutoConfiguration.class,
- AsyncLoadBalancerAutoConfiguration.class })
-@EnableConfigurationProperties({ RibbonEagerLoadProperties.class,
- ServerIntrospectorProperties.class })
-public class RibbonAutoConfiguration {
-
- @Autowired(required = false)
- private List configurations = new ArrayList<>();
-
- @Autowired
- private RibbonEagerLoadProperties ribbonEagerLoadProperties;
-
- @Bean
- public HasFeatures ribbonFeature() {
- return HasFeatures.namedFeature("Ribbon", Ribbon.class);
- }
-
- @Bean
- public SpringClientFactory springClientFactory() {
- SpringClientFactory factory = new SpringClientFactory();
- factory.setConfigurations(this.configurations);
- return factory;
- }
-
- @Bean
- @ConditionalOnMissingBean(LoadBalancerClient.class)
- public LoadBalancerClient loadBalancerClient() {
- return new RibbonLoadBalancerClient(springClientFactory());
- }
-
- @Bean
- @ConditionalOnClass(name = "org.springframework.retry.support.RetryTemplate")
- @ConditionalOnMissingBean
- public LoadBalancedRetryFactory loadBalancedRetryPolicyFactory(
- final SpringClientFactory clientFactory) {
- return new RibbonLoadBalancedRetryFactory(clientFactory);
- }
-
- @Bean
- @ConditionalOnMissingBean
- public PropertiesFactory propertiesFactory() {
- return new PropertiesFactory();
- }
-
- @Bean
- @ConditionalOnProperty("ribbon.eager-load.enabled")
- public RibbonApplicationContextInitializer ribbonApplicationContextInitializer() {
- return new RibbonApplicationContextInitializer(springClientFactory(),
- ribbonEagerLoadProperties.getClients());
- }
-
- @Configuration(proxyBeanMethods = false)
- @ConditionalOnClass(HttpRequest.class)
- @ConditionalOnRibbonRestClient
- protected static class RibbonClientHttpRequestFactoryConfiguration {
-
- @Autowired
- private SpringClientFactory springClientFactory;
-
- @Bean
- public RestTemplateCustomizer restTemplateCustomizer(
- final RibbonClientHttpRequestFactory ribbonClientHttpRequestFactory) {
- return restTemplate -> restTemplate
- .setRequestFactory(ribbonClientHttpRequestFactory);
- }
-
- @Bean
- public RibbonClientHttpRequestFactory ribbonClientHttpRequestFactory() {
- return new RibbonClientHttpRequestFactory(this.springClientFactory);
- }
-
- }
-
- // TODO: support for autoconfiguring restemplate to use apache http client or okhttp
-
- @Target({ ElementType.TYPE, ElementType.METHOD })
- @Retention(RetentionPolicy.RUNTIME)
- @Documented
- @Conditional(OnRibbonRestClientCondition.class)
- @interface ConditionalOnRibbonRestClient {
-
- }
-
- private static class OnRibbonRestClientCondition extends AnyNestedCondition {
-
- OnRibbonRestClientCondition() {
- super(ConfigurationPhase.REGISTER_BEAN);
- }
-
- @Deprecated // remove in Edgware"
- @ConditionalOnProperty("ribbon.http.client.enabled")
- static class ZuulProperty {
-
- }
-
- @ConditionalOnProperty("ribbon.restclient.enabled")
- static class RibbonProperty {
-
- }
-
- }
-
- /**
- * {@link AllNestedConditions} that checks that either multiple classes are present.
- */
- static class RibbonClassesConditions extends AllNestedConditions {
-
- RibbonClassesConditions() {
- super(ConfigurationPhase.PARSE_CONFIGURATION);
- }
-
- @ConditionalOnClass(IClient.class)
- static class IClientPresent {
-
- }
-
- @ConditionalOnClass(RestTemplate.class)
- static class RestTemplatePresent {
-
- }
-
- @SuppressWarnings("deprecation")
- @ConditionalOnClass(AsyncRestTemplate.class)
- static class AsyncRestTemplatePresent {
-
- }
-
- @ConditionalOnClass(Ribbon.class)
- static class RibbonPresent {
-
- }
-
- }
-
-}
diff --git a/spring-cloud-netflix-ribbon/src/main/java/org/springframework/cloud/netflix/ribbon/RibbonClient.java b/spring-cloud-netflix-ribbon/src/main/java/org/springframework/cloud/netflix/ribbon/RibbonClient.java
deleted file mode 100644
index d2da7ae58..000000000
--- a/spring-cloud-netflix-ribbon/src/main/java/org/springframework/cloud/netflix/ribbon/RibbonClient.java
+++ /dev/null
@@ -1,71 +0,0 @@
-/*
- * Copyright 2013-2019 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * https://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.springframework.cloud.netflix.ribbon;
-
-import java.lang.annotation.Documented;
-import java.lang.annotation.ElementType;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.lang.annotation.Target;
-
-import com.netflix.loadbalancer.ILoadBalancer;
-import com.netflix.loadbalancer.IRule;
-import com.netflix.loadbalancer.ServerListFilter;
-
-import org.springframework.context.annotation.Configuration;
-import org.springframework.context.annotation.Import;
-
-/**
- * Declarative configuration for a ribbon client. Add this annotation to any
- * @Configuration and then inject a {@link SpringClientFactory} to access the
- * client that is created.
- *
- * @author Dave Syer
- */
-@Configuration(proxyBeanMethods = false)
-@Import(RibbonClientConfigurationRegistrar.class)
-@Target(ElementType.TYPE)
-@Retention(RetentionPolicy.RUNTIME)
-@Documented
-public @interface RibbonClient {
-
- /**
- * Synonym for name (the name of the client).
- *
- * @see #name()
- * @return name of the Ribbon client
- */
- String value() default "";
-
- /**
- * The name of the ribbon client, uniquely identifying a set of client resources,
- * including a load balancer.
- * @return name of the Ribbon client
- */
- String name() default "";
-
- /**
- * A custom @Configuration for the ribbon client. Can contain override
- * @Bean definition for the pieces that make up the client, for instance
- * {@link ILoadBalancer}, {@link ServerListFilter}, {@link IRule}.
- *
- * @see RibbonClientConfiguration for the defaults
- * @return the custom Ribbon client configuration
- */
- Class>[] configuration() default {};
-
-}
diff --git a/spring-cloud-netflix-ribbon/src/main/java/org/springframework/cloud/netflix/ribbon/RibbonClientConfiguration.java b/spring-cloud-netflix-ribbon/src/main/java/org/springframework/cloud/netflix/ribbon/RibbonClientConfiguration.java
deleted file mode 100644
index 91198a8f4..000000000
--- a/spring-cloud-netflix-ribbon/src/main/java/org/springframework/cloud/netflix/ribbon/RibbonClientConfiguration.java
+++ /dev/null
@@ -1,226 +0,0 @@
-/*
- * Copyright 2013-2019 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * https://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.springframework.cloud.netflix.ribbon;
-
-import java.net.URI;
-
-import javax.annotation.PostConstruct;
-
-import com.netflix.client.DefaultLoadBalancerRetryHandler;
-import com.netflix.client.RetryHandler;
-import com.netflix.client.config.CommonClientConfigKey;
-import com.netflix.client.config.DefaultClientConfigImpl;
-import com.netflix.client.config.IClientConfig;
-import com.netflix.loadbalancer.ConfigurationBasedServerList;
-import com.netflix.loadbalancer.DummyPing;
-import com.netflix.loadbalancer.ILoadBalancer;
-import com.netflix.loadbalancer.IPing;
-import com.netflix.loadbalancer.IRule;
-import com.netflix.loadbalancer.PollingServerListUpdater;
-import com.netflix.loadbalancer.Server;
-import com.netflix.loadbalancer.ServerList;
-import com.netflix.loadbalancer.ServerListFilter;
-import com.netflix.loadbalancer.ServerListUpdater;
-import com.netflix.loadbalancer.ZoneAvoidanceRule;
-import com.netflix.loadbalancer.ZoneAwareLoadBalancer;
-import com.netflix.niws.client.http.RestClient;
-import com.sun.jersey.api.client.Client;
-import com.sun.jersey.client.apache4.ApacheHttpClient4;
-import org.apache.http.client.params.ClientPNames;
-import org.apache.http.client.params.CookiePolicy;
-
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
-import org.springframework.boot.context.properties.EnableConfigurationProperties;
-import org.springframework.cloud.commons.httpclient.HttpClientConfiguration;
-import org.springframework.cloud.netflix.ribbon.apache.HttpClientRibbonConfiguration;
-import org.springframework.cloud.netflix.ribbon.okhttp.OkHttpRibbonConfiguration;
-import org.springframework.context.annotation.Bean;
-import org.springframework.context.annotation.Configuration;
-import org.springframework.context.annotation.Import;
-
-import static com.netflix.client.config.CommonClientConfigKey.DeploymentContextBasedVipAddresses;
-import static org.springframework.cloud.netflix.ribbon.RibbonUtils.setRibbonProperty;
-import static org.springframework.cloud.netflix.ribbon.RibbonUtils.updateToSecureConnectionIfNeeded;
-
-/**
- * @author Dave Syer
- * @author Tim Ysewyn
- */
-@SuppressWarnings("deprecation")
-@Configuration(proxyBeanMethods = false)
-@EnableConfigurationProperties
-// Order is important here, last should be the default, first should be optional
-// see
-// https://github.com/spring-cloud/spring-cloud-netflix/issues/2086#issuecomment-316281653
-@Import({ HttpClientConfiguration.class, OkHttpRibbonConfiguration.class,
- RestClientRibbonConfiguration.class, HttpClientRibbonConfiguration.class })
-public class RibbonClientConfiguration {
-
- /**
- * Ribbon client default connect timeout.
- */
- public static final int DEFAULT_CONNECT_TIMEOUT = 1000;
-
- /**
- * Ribbon client default read timeout.
- */
- public static final int DEFAULT_READ_TIMEOUT = 1000;
-
- /**
- * Ribbon client default Gzip Payload flag.
- */
- public static final boolean DEFAULT_GZIP_PAYLOAD = true;
-
- @RibbonClientName
- private String name = "client";
-
- // TODO: maybe re-instate autowired load balancers: identified by name they could be
- // associated with ribbon clients
-
- @Autowired
- private PropertiesFactory propertiesFactory;
-
- @Bean
- @ConditionalOnMissingBean
- public IClientConfig ribbonClientConfig() {
- DefaultClientConfigImpl config = new DefaultClientConfigImpl();
- config.loadProperties(this.name);
- config.set(CommonClientConfigKey.ConnectTimeout, DEFAULT_CONNECT_TIMEOUT);
- config.set(CommonClientConfigKey.ReadTimeout, DEFAULT_READ_TIMEOUT);
- config.set(CommonClientConfigKey.GZipPayload, DEFAULT_GZIP_PAYLOAD);
- return config;
- }
-
- @Bean
- @ConditionalOnMissingBean
- public IRule ribbonRule(IClientConfig config) {
- if (this.propertiesFactory.isSet(IRule.class, name)) {
- return this.propertiesFactory.get(IRule.class, config, name);
- }
- ZoneAvoidanceRule rule = new ZoneAvoidanceRule();
- rule.initWithNiwsConfig(config);
- return rule;
- }
-
- @Bean
- @ConditionalOnMissingBean
- public IPing ribbonPing(IClientConfig config) {
- if (this.propertiesFactory.isSet(IPing.class, name)) {
- return this.propertiesFactory.get(IPing.class, config, name);
- }
- return new DummyPing();
- }
-
- @Bean
- @ConditionalOnMissingBean
- @SuppressWarnings("unchecked")
- public ServerList ribbonServerList(IClientConfig config) {
- if (this.propertiesFactory.isSet(ServerList.class, name)) {
- return this.propertiesFactory.get(ServerList.class, config, name);
- }
- ConfigurationBasedServerList serverList = new ConfigurationBasedServerList();
- serverList.initWithNiwsConfig(config);
- return serverList;
- }
-
- @Bean
- @ConditionalOnMissingBean
- public ServerListUpdater ribbonServerListUpdater(IClientConfig config) {
- return new PollingServerListUpdater(config);
- }
-
- @Bean
- @ConditionalOnMissingBean
- public ILoadBalancer ribbonLoadBalancer(IClientConfig config,
- ServerList serverList, ServerListFilter serverListFilter,
- IRule rule, IPing ping, ServerListUpdater serverListUpdater) {
- if (this.propertiesFactory.isSet(ILoadBalancer.class, name)) {
- return this.propertiesFactory.get(ILoadBalancer.class, config, name);
- }
- return new ZoneAwareLoadBalancer<>(config, rule, ping, serverList,
- serverListFilter, serverListUpdater);
- }
-
- @Bean
- @ConditionalOnMissingBean
- @SuppressWarnings("unchecked")
- public ServerListFilter ribbonServerListFilter(IClientConfig config) {
- if (this.propertiesFactory.isSet(ServerListFilter.class, name)) {
- return this.propertiesFactory.get(ServerListFilter.class, config, name);
- }
- ZonePreferenceServerListFilter filter = new ZonePreferenceServerListFilter();
- filter.initWithNiwsConfig(config);
- return filter;
- }
-
- @Bean
- @ConditionalOnMissingBean
- public RibbonLoadBalancerContext ribbonLoadBalancerContext(ILoadBalancer loadBalancer,
- IClientConfig config, RetryHandler retryHandler) {
- return new RibbonLoadBalancerContext(loadBalancer, config, retryHandler);
- }
-
- @Bean
- @ConditionalOnMissingBean
- public RetryHandler retryHandler(IClientConfig config) {
- return new DefaultLoadBalancerRetryHandler(config);
- }
-
- @Bean
- @ConditionalOnMissingBean
- public ServerIntrospector serverIntrospector() {
- return new DefaultServerIntrospector();
- }
-
- @PostConstruct
- public void preprocess() {
- setRibbonProperty(name, DeploymentContextBasedVipAddresses.key(), name);
- }
-
- static class OverrideRestClient extends RestClient {
-
- private IClientConfig config;
-
- private ServerIntrospector serverIntrospector;
-
- protected OverrideRestClient(IClientConfig config,
- ServerIntrospector serverIntrospector) {
- super();
- this.config = config;
- this.serverIntrospector = serverIntrospector;
- initWithNiwsConfig(this.config);
- }
-
- @Override
- public URI reconstructURIWithServer(Server server, URI original) {
- URI uri = updateToSecureConnectionIfNeeded(original, this.config,
- this.serverIntrospector, server);
- return super.reconstructURIWithServer(server, uri);
- }
-
- @Override
- protected Client apacheHttpClientSpecificInitialization() {
- ApacheHttpClient4 apache = (ApacheHttpClient4) super.apacheHttpClientSpecificInitialization();
- apache.getClientHandler().getHttpClient().getParams().setParameter(
- ClientPNames.COOKIE_POLICY, CookiePolicy.IGNORE_COOKIES);
- return apache;
- }
-
- }
-
-}
diff --git a/spring-cloud-netflix-ribbon/src/main/java/org/springframework/cloud/netflix/ribbon/RibbonClientConfigurationRegistrar.java b/spring-cloud-netflix-ribbon/src/main/java/org/springframework/cloud/netflix/ribbon/RibbonClientConfigurationRegistrar.java
deleted file mode 100644
index e58ba0a22..000000000
--- a/spring-cloud-netflix-ribbon/src/main/java/org/springframework/cloud/netflix/ribbon/RibbonClientConfigurationRegistrar.java
+++ /dev/null
@@ -1,89 +0,0 @@
-/*
- * Copyright 2013-2019 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * https://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.springframework.cloud.netflix.ribbon;
-
-import java.util.Map;
-
-import org.springframework.beans.factory.support.BeanDefinitionBuilder;
-import org.springframework.beans.factory.support.BeanDefinitionRegistry;
-import org.springframework.context.annotation.ImportBeanDefinitionRegistrar;
-import org.springframework.core.annotation.AnnotationAttributes;
-import org.springframework.core.type.AnnotationMetadata;
-import org.springframework.util.StringUtils;
-
-/**
- * @author Dave Syer
- */
-public class RibbonClientConfigurationRegistrar implements ImportBeanDefinitionRegistrar {
-
- @Override
- public void registerBeanDefinitions(AnnotationMetadata metadata,
- BeanDefinitionRegistry registry) {
- Map attrs = metadata
- .getAnnotationAttributes(RibbonClients.class.getName(), true);
- if (attrs != null && attrs.containsKey("value")) {
- AnnotationAttributes[] clients = (AnnotationAttributes[]) attrs.get("value");
- for (AnnotationAttributes client : clients) {
- registerClientConfiguration(registry, getClientName(client),
- client.get("configuration"));
- }
- }
- if (attrs != null && attrs.containsKey("defaultConfiguration")) {
- String name;
- if (metadata.hasEnclosingClass()) {
- name = "default." + metadata.getEnclosingClassName();
- }
- else {
- name = "default." + metadata.getClassName();
- }
- registerClientConfiguration(registry, name,
- attrs.get("defaultConfiguration"));
- }
- Map client = metadata
- .getAnnotationAttributes(RibbonClient.class.getName(), true);
- String name = getClientName(client);
- if (name != null) {
- registerClientConfiguration(registry, name, client.get("configuration"));
- }
- }
-
- private String getClientName(Map client) {
- if (client == null) {
- return null;
- }
- String value = (String) client.get("value");
- if (!StringUtils.hasText(value)) {
- value = (String) client.get("name");
- }
- if (StringUtils.hasText(value)) {
- return value;
- }
- throw new IllegalStateException(
- "Either 'name' or 'value' must be provided in @RibbonClient");
- }
-
- private void registerClientConfiguration(BeanDefinitionRegistry registry, Object name,
- Object configuration) {
- BeanDefinitionBuilder builder = BeanDefinitionBuilder
- .genericBeanDefinition(RibbonClientSpecification.class);
- builder.addConstructorArgValue(name);
- builder.addConstructorArgValue(configuration);
- registry.registerBeanDefinition(name + ".RibbonClientSpecification",
- builder.getBeanDefinition());
- }
-
-}
diff --git a/spring-cloud-netflix-ribbon/src/main/java/org/springframework/cloud/netflix/ribbon/RibbonClientHttpRequestFactory.java b/spring-cloud-netflix-ribbon/src/main/java/org/springframework/cloud/netflix/ribbon/RibbonClientHttpRequestFactory.java
deleted file mode 100644
index 2974cd130..000000000
--- a/spring-cloud-netflix-ribbon/src/main/java/org/springframework/cloud/netflix/ribbon/RibbonClientHttpRequestFactory.java
+++ /dev/null
@@ -1,57 +0,0 @@
-/*
- * Copyright 2013-2019 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * https://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.springframework.cloud.netflix.ribbon;
-
-import java.io.IOException;
-import java.net.URI;
-
-import com.netflix.client.config.IClientConfig;
-import com.netflix.client.http.HttpRequest;
-import com.netflix.niws.client.http.RestClient;
-
-import org.springframework.http.HttpMethod;
-import org.springframework.http.client.ClientHttpRequest;
-import org.springframework.http.client.ClientHttpRequestFactory;
-
-/**
- * @author Spencer Gibb
- */
-public class RibbonClientHttpRequestFactory implements ClientHttpRequestFactory {
-
- private final SpringClientFactory clientFactory;
-
- public RibbonClientHttpRequestFactory(SpringClientFactory clientFactory) {
- this.clientFactory = clientFactory;
- }
-
- @Override
- @SuppressWarnings("deprecation")
- public ClientHttpRequest createRequest(URI originalUri, HttpMethod httpMethod)
- throws IOException {
- String serviceId = originalUri.getHost();
- if (serviceId == null) {
- throw new IOException(
- "Invalid hostname in the URI [" + originalUri.toASCIIString() + "]");
- }
- IClientConfig clientConfig = this.clientFactory.getClientConfig(serviceId);
- RestClient client = this.clientFactory.getClient(serviceId, RestClient.class);
- HttpRequest.Verb verb = HttpRequest.Verb.valueOf(httpMethod.name());
-
- return new RibbonHttpRequest(originalUri, verb, client, clientConfig);
- }
-
-}
diff --git a/spring-cloud-netflix-ribbon/src/main/java/org/springframework/cloud/netflix/ribbon/RibbonClientName.java b/spring-cloud-netflix-ribbon/src/main/java/org/springframework/cloud/netflix/ribbon/RibbonClientName.java
deleted file mode 100644
index 4ed945ed8..000000000
--- a/spring-cloud-netflix-ribbon/src/main/java/org/springframework/cloud/netflix/ribbon/RibbonClientName.java
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * Copyright 2018-2019 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * https://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.springframework.cloud.netflix.ribbon;
-
-import java.lang.annotation.Documented;
-import java.lang.annotation.ElementType;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.lang.annotation.Target;
-
-import org.springframework.beans.factory.annotation.Value;
-
-/**
- * Annotation at the field or method/constructor parameter level that injects the Ribbon
- * Client Name that got allocated at runtime. Provides a convenient alternative for
- * @Value("${ribbon.client.name}").
- *
- * @author Spencer Gibb
- * @since 2.0.0
- */
-@Target({ ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER,
- ElementType.ANNOTATION_TYPE })
-@Retention(RetentionPolicy.RUNTIME)
-@Documented
-@Value("${ribbon.client.name}")
-public @interface RibbonClientName {
-
-}
diff --git a/spring-cloud-netflix-ribbon/src/main/java/org/springframework/cloud/netflix/ribbon/RibbonClientSpecification.java b/spring-cloud-netflix-ribbon/src/main/java/org/springframework/cloud/netflix/ribbon/RibbonClientSpecification.java
deleted file mode 100644
index c092ea006..000000000
--- a/spring-cloud-netflix-ribbon/src/main/java/org/springframework/cloud/netflix/ribbon/RibbonClientSpecification.java
+++ /dev/null
@@ -1,82 +0,0 @@
-/*
- * Copyright 2013-2014 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * https://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.springframework.cloud.netflix.ribbon;
-
-import java.util.Arrays;
-import java.util.Objects;
-
-import org.springframework.cloud.context.named.NamedContextFactory;
-
-/**
- * @author Dave Syer
- */
-public class RibbonClientSpecification implements NamedContextFactory.Specification {
-
- private String name;
-
- private Class>[] configuration;
-
- public RibbonClientSpecification() {
- }
-
- public RibbonClientSpecification(String name, Class>[] configuration) {
- this.name = name;
- this.configuration = configuration;
- }
-
- public String getName() {
- return name;
- }
-
- public void setName(String name) {
- this.name = name;
- }
-
- public Class>[] getConfiguration() {
- return configuration;
- }
-
- public void setConfiguration(Class>[] configuration) {
- this.configuration = configuration;
- }
-
- @Override
- public boolean equals(Object o) {
- if (this == o) {
- return true;
- }
- if (o == null || getClass() != o.getClass()) {
- return false;
- }
- RibbonClientSpecification that = (RibbonClientSpecification) o;
- return Arrays.equals(configuration, that.configuration)
- && Objects.equals(name, that.name);
- }
-
- @Override
- public int hashCode() {
- return Objects.hash(configuration, name);
- }
-
- @Override
- public String toString() {
- return new StringBuilder("RibbonClientSpecification{").append("name='")
- .append(name).append("', ").append("configuration=")
- .append(Arrays.toString(configuration)).append("}").toString();
- }
-
-}
diff --git a/spring-cloud-netflix-ribbon/src/main/java/org/springframework/cloud/netflix/ribbon/RibbonClients.java b/spring-cloud-netflix-ribbon/src/main/java/org/springframework/cloud/netflix/ribbon/RibbonClients.java
deleted file mode 100644
index 8843d4e3f..000000000
--- a/spring-cloud-netflix-ribbon/src/main/java/org/springframework/cloud/netflix/ribbon/RibbonClients.java
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * Copyright 2013-2019 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * https://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.springframework.cloud.netflix.ribbon;
-
-import java.lang.annotation.Documented;
-import java.lang.annotation.ElementType;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.lang.annotation.Target;
-
-import org.springframework.context.annotation.Configuration;
-import org.springframework.context.annotation.Import;
-
-/**
- * Convenience annotation that allows user to combine multiple @RibbonClient
- * annotations on a single class (including in Java 7).
- *
- * @author Dave Syer
- */
-@Configuration(proxyBeanMethods = false)
-@Retention(RetentionPolicy.RUNTIME)
-@Target({ ElementType.TYPE })
-@Documented
-@Import(RibbonClientConfigurationRegistrar.class)
-public @interface RibbonClients {
-
- RibbonClient[] value() default {};
-
- Class>[] defaultConfiguration() default {};
-
-}
diff --git a/spring-cloud-netflix-ribbon/src/main/java/org/springframework/cloud/netflix/ribbon/RibbonEagerLoadProperties.java b/spring-cloud-netflix-ribbon/src/main/java/org/springframework/cloud/netflix/ribbon/RibbonEagerLoadProperties.java
deleted file mode 100644
index 453e1db5e..000000000
--- a/spring-cloud-netflix-ribbon/src/main/java/org/springframework/cloud/netflix/ribbon/RibbonEagerLoadProperties.java
+++ /dev/null
@@ -1,52 +0,0 @@
-/*
- * Copyright 2017-2019 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * https://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.springframework.cloud.netflix.ribbon;
-
-import java.util.List;
-
-import org.springframework.boot.context.properties.ConfigurationProperties;
-
-/**
- * Configuration Properties to indicate which Ribbon configurations should be eagerly
- * loaded up.
- *
- * @author Biju Kunjummen
- */
-@ConfigurationProperties(prefix = "ribbon.eager-load")
-public class RibbonEagerLoadProperties {
-
- private boolean enabled = false;
-
- private List clients;
-
- public boolean isEnabled() {
- return enabled;
- }
-
- public void setEnabled(boolean enabled) {
- this.enabled = enabled;
- }
-
- public List getClients() {
- return clients;
- }
-
- public void setClients(List clients) {
- this.clients = clients;
- }
-
-}
diff --git a/spring-cloud-netflix-ribbon/src/main/java/org/springframework/cloud/netflix/ribbon/RibbonHttpRequest.java b/spring-cloud-netflix-ribbon/src/main/java/org/springframework/cloud/netflix/ribbon/RibbonHttpRequest.java
deleted file mode 100644
index b321c9c17..000000000
--- a/spring-cloud-netflix-ribbon/src/main/java/org/springframework/cloud/netflix/ribbon/RibbonHttpRequest.java
+++ /dev/null
@@ -1,126 +0,0 @@
-/*
- * Copyright 2013-2019 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * https://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.springframework.cloud.netflix.ribbon;
-
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.io.OutputStream;
-import java.net.URI;
-import java.util.List;
-
-import com.netflix.client.config.IClientConfig;
-import com.netflix.client.http.HttpRequest;
-import com.netflix.client.http.HttpResponse;
-import com.netflix.niws.client.http.RestClient;
-
-import org.springframework.http.HttpHeaders;
-import org.springframework.http.HttpMethod;
-import org.springframework.http.client.AbstractClientHttpRequest;
-import org.springframework.http.client.ClientHttpResponse;
-
-/**
- * @author Spencer Gibb
- */
-@SuppressWarnings("deprecation")
-public class RibbonHttpRequest extends AbstractClientHttpRequest {
-
- private HttpRequest.Builder builder;
-
- private URI uri;
-
- private HttpRequest.Verb verb;
-
- private RestClient client;
-
- private IClientConfig config;
-
- private ByteArrayOutputStream outputStream = null;
-
- public RibbonHttpRequest(URI uri, HttpRequest.Verb verb, RestClient client,
- IClientConfig config) {
- this.uri = uri;
- this.verb = verb;
- this.client = client;
- this.config = config;
- this.builder = HttpRequest.newBuilder().uri(uri).verb(verb);
- }
-
- @Override
- public HttpMethod getMethod() {
- return HttpMethod.valueOf(verb.name());
- }
-
- @Override
- public String getMethodValue() {
- return getMethod().name();
- }
-
- @Override
- public URI getURI() {
- return uri;
- }
-
- @Override
- protected OutputStream getBodyInternal(HttpHeaders headers) throws IOException {
- if (outputStream == null) {
- outputStream = new ByteArrayOutputStream();
- }
- return outputStream;
- }
-
- @Override
- protected ClientHttpResponse executeInternal(HttpHeaders headers) throws IOException {
- try {
- addHeaders(headers);
- if (outputStream != null) {
- outputStream.close();
- builder.entity(outputStream.toByteArray());
- }
- HttpRequest request = builder.build();
- HttpResponse response = client.executeWithLoadBalancer(request, config);
- return new RibbonHttpResponse(response);
- }
- catch (Exception e) {
- throw new IOException(e);
- }
- }
-
- private void addHeaders(HttpHeaders headers) {
- for (String name : headers.keySet()) {
- // apache http RequestContent pukes if there is a body and
- // the dynamic headers are already present
- if (isDynamic(name) && outputStream != null) {
- continue;
- }
- // Don't add content-length if the output stream is null. The RibbonClient
- // does this for us.
- if (name.equals("Content-Length") && outputStream == null) {
- continue;
- }
- List values = headers.get(name);
- for (String value : values) {
- builder.header(name, value);
- }
- }
- }
-
- private boolean isDynamic(String name) {
- return "Content-Length".equalsIgnoreCase(name)
- || "Transfer-Encoding".equalsIgnoreCase(name);
- }
-
-}
diff --git a/spring-cloud-netflix-ribbon/src/main/java/org/springframework/cloud/netflix/ribbon/RibbonHttpResponse.java b/spring-cloud-netflix-ribbon/src/main/java/org/springframework/cloud/netflix/ribbon/RibbonHttpResponse.java
deleted file mode 100644
index 27b1e7302..000000000
--- a/spring-cloud-netflix-ribbon/src/main/java/org/springframework/cloud/netflix/ribbon/RibbonHttpResponse.java
+++ /dev/null
@@ -1,74 +0,0 @@
-/*
- * Copyright 2013-2019 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * https://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.springframework.cloud.netflix.ribbon;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.List;
-import java.util.Map;
-
-import com.netflix.client.http.HttpResponse;
-
-import org.springframework.http.HttpHeaders;
-import org.springframework.http.HttpStatus;
-import org.springframework.http.client.AbstractClientHttpResponse;
-
-/**
- * @author Spencer Gibb
- */
-public class RibbonHttpResponse extends AbstractClientHttpResponse {
-
- private HttpResponse response;
-
- private HttpHeaders httpHeaders;
-
- public RibbonHttpResponse(HttpResponse response) {
- this.response = response;
- this.httpHeaders = new HttpHeaders();
- List> headers = response.getHttpHeaders()
- .getAllHeaders();
- for (Map.Entry header : headers) {
- this.httpHeaders.add(header.getKey(), header.getValue());
- }
- }
-
- @Override
- public InputStream getBody() throws IOException {
- return response.getInputStream();
- }
-
- @Override
- public HttpHeaders getHeaders() {
- return this.httpHeaders;
- }
-
- @Override
- public int getRawStatusCode() throws IOException {
- return response.getStatus();
- }
-
- @Override
- public String getStatusText() throws IOException {
- return HttpStatus.valueOf(response.getStatus()).name();
- }
-
- @Override
- public void close() {
- response.close();
- }
-
-}
diff --git a/spring-cloud-netflix-ribbon/src/main/java/org/springframework/cloud/netflix/ribbon/RibbonLoadBalancedRetryFactory.java b/spring-cloud-netflix-ribbon/src/main/java/org/springframework/cloud/netflix/ribbon/RibbonLoadBalancedRetryFactory.java
deleted file mode 100644
index 6e069f97d..000000000
--- a/spring-cloud-netflix-ribbon/src/main/java/org/springframework/cloud/netflix/ribbon/RibbonLoadBalancedRetryFactory.java
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * Copyright 2013-2019 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * https://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.springframework.cloud.netflix.ribbon;
-
-import org.springframework.cloud.client.loadbalancer.LoadBalancedRetryFactory;
-import org.springframework.cloud.client.loadbalancer.LoadBalancedRetryPolicy;
-import org.springframework.cloud.client.loadbalancer.ServiceInstanceChooser;
-import org.springframework.retry.RetryListener;
-import org.springframework.retry.backoff.BackOffPolicy;
-
-/**
- * @author Ryan Baxter
- */
-public class RibbonLoadBalancedRetryFactory implements LoadBalancedRetryFactory {
-
- private SpringClientFactory clientFactory;
-
- public RibbonLoadBalancedRetryFactory(SpringClientFactory clientFactory) {
- this.clientFactory = clientFactory;
- }
-
- @Override
- public LoadBalancedRetryPolicy createRetryPolicy(String service,
- ServiceInstanceChooser serviceInstanceChooser) {
- RibbonLoadBalancerContext lbContext = this.clientFactory
- .getLoadBalancerContext(service);
- return new RibbonLoadBalancedRetryPolicy(service, lbContext,
- serviceInstanceChooser, clientFactory.getClientConfig(service));
- }
-
- @Override
- public RetryListener[] createRetryListeners(String service) {
- return new RetryListener[0];
- }
-
- @Override
- public BackOffPolicy createBackOffPolicy(String service) {
- return null;
- }
-
-}
diff --git a/spring-cloud-netflix-ribbon/src/main/java/org/springframework/cloud/netflix/ribbon/RibbonLoadBalancedRetryPolicy.java b/spring-cloud-netflix-ribbon/src/main/java/org/springframework/cloud/netflix/ribbon/RibbonLoadBalancedRetryPolicy.java
deleted file mode 100644
index d04872891..000000000
--- a/spring-cloud-netflix-ribbon/src/main/java/org/springframework/cloud/netflix/ribbon/RibbonLoadBalancedRetryPolicy.java
+++ /dev/null
@@ -1,178 +0,0 @@
-/*
- * Copyright 2013-2019 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * https://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.springframework.cloud.netflix.ribbon;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import com.netflix.client.config.CommonClientConfigKey;
-import com.netflix.client.config.IClientConfig;
-import com.netflix.client.config.IClientConfigKey;
-import com.netflix.loadbalancer.Server;
-import com.netflix.loadbalancer.ServerStats;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-import org.springframework.cloud.client.ServiceInstance;
-import org.springframework.cloud.client.loadbalancer.LoadBalancedRetryContext;
-import org.springframework.cloud.client.loadbalancer.LoadBalancedRetryPolicy;
-import org.springframework.cloud.client.loadbalancer.ServiceInstanceChooser;
-import org.springframework.cloud.netflix.ribbon.RibbonLoadBalancerClient.RibbonServer;
-import org.springframework.http.HttpMethod;
-import org.springframework.util.StringUtils;
-
-/**
- * {@link LoadBalancedRetryPolicy} for Ribbon clients.
- *
- * @author Ryan Baxter
- */
-public class RibbonLoadBalancedRetryPolicy implements LoadBalancedRetryPolicy {
-
- /**
- * Retrayable status codes config key.
- */
- public static final IClientConfigKey RETRYABLE_STATUS_CODES = new CommonClientConfigKey(
- "retryableStatusCodes") {
- };
-
- private static final Log log = LogFactory.getLog(RibbonLoadBalancedRetryPolicy.class);
-
- private int sameServerCount = 0;
-
- private int nextServerCount = 0;
-
- private String serviceId;
-
- private RibbonLoadBalancerContext lbContext;
-
- private ServiceInstanceChooser loadBalanceChooser;
-
- List retryableStatusCodes = new ArrayList<>();
-
- private static final Log LOGGER = LogFactory
- .getLog(RibbonLoadBalancedRetryPolicy.class);
-
- public RibbonLoadBalancedRetryPolicy(String serviceId,
- RibbonLoadBalancerContext context,
- ServiceInstanceChooser loadBalanceChooser) {
- this.serviceId = serviceId;
- this.lbContext = context;
- this.loadBalanceChooser = loadBalanceChooser;
- }
-
- public RibbonLoadBalancedRetryPolicy(String serviceId,
- RibbonLoadBalancerContext context, ServiceInstanceChooser loadBalanceChooser,
- IClientConfig clientConfig) {
- this.serviceId = serviceId;
- this.lbContext = context;
- this.loadBalanceChooser = loadBalanceChooser;
- String retryableStatusCodesProp = clientConfig
- .getPropertyAsString(RETRYABLE_STATUS_CODES, "");
- String[] retryableStatusCodesArray = retryableStatusCodesProp.split(",");
- for (String code : retryableStatusCodesArray) {
- if (!StringUtils.isEmpty(code)) {
- try {
- retryableStatusCodes.add(Integer.valueOf(code.trim()));
- }
- catch (NumberFormatException e) {
- log.warn("We cant add the status code because the code [ " + code
- + " ] could not be converted to an integer. ", e);
- }
- }
- }
- }
-
- public boolean canRetry(LoadBalancedRetryContext context) {
- HttpMethod method = context.getRequest().getMethod();
- return HttpMethod.GET == method || lbContext.isOkToRetryOnAllOperations();
- }
-
- @Override
- public boolean canRetrySameServer(LoadBalancedRetryContext context) {
- return sameServerCount < lbContext.getRetryHandler().getMaxRetriesOnSameServer()
- && canRetry(context);
- }
-
- @Override
- public boolean canRetryNextServer(LoadBalancedRetryContext context) {
- // this will be called after a failure occurs and we increment the counter
- // so we check that the count is less than or equals to too make sure
- // we try the next server the right number of times
- return nextServerCount <= lbContext.getRetryHandler().getMaxRetriesOnNextServer()
- && canRetry(context);
- }
-
- @Override
- public void close(LoadBalancedRetryContext context) {
-
- }
-
- @Override
- public void registerThrowable(LoadBalancedRetryContext context, Throwable throwable) {
- // if this is a circuit tripping exception then notify the load balancer
- if (lbContext.getRetryHandler().isCircuitTrippingException(throwable)) {
- updateServerInstanceStats(context);
- }
-
- // Check if we need to ask the load balancer for a new server.
- // Do this before we increment the counters because the first call to this method
- // is not a retry it is just an initial failure.
- if (!canRetrySameServer(context) && canRetryNextServer(context)) {
- context.setServiceInstance(loadBalanceChooser.choose(serviceId));
- }
- // This method is called regardless of whether we are retrying or making the first
- // request.
- // Since we do not count the initial request in the retry count we don't reset the
- // counter
- // until we actually equal the same server count limit. This will allow us to make
- // the initial
- // request plus the right number of retries.
- if (sameServerCount >= lbContext.getRetryHandler().getMaxRetriesOnSameServer()
- && canRetry(context)) {
- // reset same server since we are moving to a new server
- sameServerCount = 0;
- nextServerCount++;
- if (!canRetryNextServer(context)) {
- context.setExhaustedOnly();
- }
- }
- else {
- sameServerCount++;
- }
-
- }
-
- private void updateServerInstanceStats(LoadBalancedRetryContext context) {
- ServiceInstance serviceInstance = context.getServiceInstance();
- if (serviceInstance instanceof RibbonServer) {
- Server lbServer = ((RibbonServer) serviceInstance).getServer();
- ServerStats serverStats = lbContext.getServerStats(lbServer);
- serverStats.incrementSuccessiveConnectionFailureCount();
- serverStats.addToFailureCount();
- LOGGER.debug(lbServer.getHostPort() + " RetryCount: "
- + context.getRetryCount() + " Successive Failures: "
- + serverStats.getSuccessiveConnectionFailureCount()
- + " CircuitBreakerTripped:" + serverStats.isCircuitBreakerTripped());
- }
- }
-
- @Override
- public boolean retryableStatusCode(int statusCode) {
- return retryableStatusCodes.contains(statusCode);
- }
-
-}
diff --git a/spring-cloud-netflix-ribbon/src/main/java/org/springframework/cloud/netflix/ribbon/RibbonLoadBalancerClient.java b/spring-cloud-netflix-ribbon/src/main/java/org/springframework/cloud/netflix/ribbon/RibbonLoadBalancerClient.java
deleted file mode 100644
index 27006ab09..000000000
--- a/spring-cloud-netflix-ribbon/src/main/java/org/springframework/cloud/netflix/ribbon/RibbonLoadBalancerClient.java
+++ /dev/null
@@ -1,278 +0,0 @@
-/*
- * Copyright 2013-2019 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * https://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.springframework.cloud.netflix.ribbon;
-
-import java.io.IOException;
-import java.net.URI;
-import java.util.Collections;
-import java.util.Map;
-
-import com.netflix.client.config.IClientConfig;
-import com.netflix.loadbalancer.ILoadBalancer;
-import com.netflix.loadbalancer.Server;
-
-import org.springframework.cloud.client.DefaultServiceInstance;
-import org.springframework.cloud.client.ServiceInstance;
-import org.springframework.cloud.client.loadbalancer.LoadBalancerClient;
-import org.springframework.cloud.client.loadbalancer.LoadBalancerRequest;
-import org.springframework.util.Assert;
-import org.springframework.util.ReflectionUtils;
-
-import static org.springframework.cloud.netflix.ribbon.RibbonUtils.updateToSecureConnectionIfNeeded;
-
-/**
- * @author Spencer Gibb
- * @author Dave Syer
- * @author Ryan Baxter
- * @author Tim Ysewyn
- */
-public class RibbonLoadBalancerClient implements LoadBalancerClient {
-
- private SpringClientFactory clientFactory;
-
- public RibbonLoadBalancerClient(SpringClientFactory clientFactory) {
- this.clientFactory = clientFactory;
- }
-
- @Override
- public URI reconstructURI(ServiceInstance instance, URI original) {
- Assert.notNull(instance, "instance can not be null");
- String serviceId = instance.getServiceId();
- RibbonLoadBalancerContext context = this.clientFactory
- .getLoadBalancerContext(serviceId);
-
- URI uri;
- Server server;
- if (instance instanceof RibbonServer) {
- RibbonServer ribbonServer = (RibbonServer) instance;
- server = ribbonServer.getServer();
- uri = updateToSecureConnectionIfNeeded(original, ribbonServer);
- }
- else {
- server = new Server(instance.getScheme(), instance.getHost(),
- instance.getPort());
- IClientConfig clientConfig = clientFactory.getClientConfig(serviceId);
- ServerIntrospector serverIntrospector = serverIntrospector(serviceId);
- uri = updateToSecureConnectionIfNeeded(original, clientConfig,
- serverIntrospector, server);
- }
- return context.reconstructURIWithServer(server, uri);
- }
-
- @Override
- public ServiceInstance choose(String serviceId) {
- return choose(serviceId, null);
- }
-
- /**
- * New: Select a server using a 'key'.
- * @param serviceId of the service to choose an instance for
- * @param hint to specify the service instance
- * @return the selected {@link ServiceInstance}
- */
- public ServiceInstance choose(String serviceId, Object hint) {
- Server server = getServer(getLoadBalancer(serviceId), hint);
- if (server == null) {
- return null;
- }
- return new RibbonServer(serviceId, server, isSecure(server, serviceId),
- serverIntrospector(serviceId).getMetadata(server));
- }
-
- @Override
- public T execute(String serviceId, LoadBalancerRequest request)
- throws IOException {
- return execute(serviceId, request, null);
- }
-
- /**
- * New: Execute a request by selecting server using a 'key'. The hint will have to be
- * the last parameter to not mess with the `execute(serviceId, ServiceInstance,
- * request)` method. This somewhat breaks the fluent coding style when using a lambda
- * to define the LoadBalancerRequest.
- * @param returned request execution result type
- * @param serviceId id of the service to execute the request to
- * @param request to be executed
- * @param hint used to choose appropriate {@link Server} instance
- * @return request execution result
- * @throws IOException executing the request may result in an {@link IOException}
- */
- public T execute(String serviceId, LoadBalancerRequest request, Object hint)
- throws IOException {
- ILoadBalancer loadBalancer = getLoadBalancer(serviceId);
- Server server = getServer(loadBalancer, hint);
- if (server == null) {
- throw new IllegalStateException("No instances available for " + serviceId);
- }
- RibbonServer ribbonServer = new RibbonServer(serviceId, server,
- isSecure(server, serviceId),
- serverIntrospector(serviceId).getMetadata(server));
-
- return execute(serviceId, ribbonServer, request);
- }
-
- @Override
- public T execute(String serviceId, ServiceInstance serviceInstance,
- LoadBalancerRequest request) throws IOException {
- Server server = null;
- if (serviceInstance instanceof RibbonServer) {
- server = ((RibbonServer) serviceInstance).getServer();
- }
- if (server == null) {
- throw new IllegalStateException("No instances available for " + serviceId);
- }
-
- RibbonLoadBalancerContext context = this.clientFactory
- .getLoadBalancerContext(serviceId);
- RibbonStatsRecorder statsRecorder = new RibbonStatsRecorder(context, server);
-
- try {
- T returnVal = request.apply(serviceInstance);
- statsRecorder.recordStats(returnVal);
- return returnVal;
- }
- // catch IOException and rethrow so RestTemplate behaves correctly
- catch (IOException ex) {
- statsRecorder.recordStats(ex);
- throw ex;
- }
- catch (Exception ex) {
- statsRecorder.recordStats(ex);
- ReflectionUtils.rethrowRuntimeException(ex);
- }
- return null;
- }
-
- private ServerIntrospector serverIntrospector(String serviceId) {
- ServerIntrospector serverIntrospector = this.clientFactory.getInstance(serviceId,
- ServerIntrospector.class);
- if (serverIntrospector == null) {
- serverIntrospector = new DefaultServerIntrospector();
- }
- return serverIntrospector;
- }
-
- private boolean isSecure(Server server, String serviceId) {
- IClientConfig config = this.clientFactory.getClientConfig(serviceId);
- ServerIntrospector serverIntrospector = serverIntrospector(serviceId);
- return RibbonUtils.isSecure(config, serverIntrospector, server);
- }
-
- // Note: This method could be removed?
- protected Server getServer(String serviceId) {
- return getServer(getLoadBalancer(serviceId), null);
- }
-
- protected Server getServer(ILoadBalancer loadBalancer) {
- return getServer(loadBalancer, null);
- }
-
- protected Server getServer(ILoadBalancer loadBalancer, Object hint) {
- if (loadBalancer == null) {
- return null;
- }
- // Use 'default' on a null hint, or just pass it on?
- return loadBalancer.chooseServer(hint != null ? hint : "default");
- }
-
- protected ILoadBalancer getLoadBalancer(String serviceId) {
- return this.clientFactory.getLoadBalancer(serviceId);
- }
-
- /**
- * Ribbon-server-specific {@link ServiceInstance} implementation.
- */
- public static class RibbonServer implements ServiceInstance {
-
- private final String serviceId;
-
- private final Server server;
-
- private final boolean secure;
-
- private Map metadata;
-
- public RibbonServer(String serviceId, Server server) {
- this(serviceId, server, false, Collections.emptyMap());
- }
-
- public RibbonServer(String serviceId, Server server, boolean secure,
- Map metadata) {
- this.serviceId = serviceId;
- this.server = server;
- this.secure = secure;
- this.metadata = metadata;
- }
-
- @Override
- public String getInstanceId() {
- return this.server.getId();
- }
-
- @Override
- public String getServiceId() {
- return this.serviceId;
- }
-
- @Override
- public String getHost() {
- return this.server.getHost();
- }
-
- @Override
- public int getPort() {
- return this.server.getPort();
- }
-
- @Override
- public boolean isSecure() {
- return this.secure;
- }
-
- @Override
- public URI getUri() {
- return DefaultServiceInstance.getUri(this);
- }
-
- @Override
- public Map getMetadata() {
- return this.metadata;
- }
-
- public Server getServer() {
- return this.server;
- }
-
- @Override
- public String getScheme() {
- return this.server.getScheme();
- }
-
- @Override
- public String toString() {
- final StringBuilder sb = new StringBuilder("RibbonServer{");
- sb.append("serviceId='").append(serviceId).append('\'');
- sb.append(", server=").append(server);
- sb.append(", secure=").append(secure);
- sb.append(", metadata=").append(metadata);
- sb.append('}');
- return sb.toString();
- }
-
- }
-
-}
diff --git a/spring-cloud-netflix-ribbon/src/main/java/org/springframework/cloud/netflix/ribbon/RibbonLoadBalancerContext.java b/spring-cloud-netflix-ribbon/src/main/java/org/springframework/cloud/netflix/ribbon/RibbonLoadBalancerContext.java
deleted file mode 100644
index 08138a111..000000000
--- a/spring-cloud-netflix-ribbon/src/main/java/org/springframework/cloud/netflix/ribbon/RibbonLoadBalancerContext.java
+++ /dev/null
@@ -1,66 +0,0 @@
-/*
- * Copyright 2013-2019 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * https://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.springframework.cloud.netflix.ribbon;
-
-import com.netflix.client.RetryHandler;
-import com.netflix.client.config.IClientConfig;
-import com.netflix.loadbalancer.ILoadBalancer;
-import com.netflix.loadbalancer.LoadBalancerContext;
-import com.netflix.loadbalancer.ServerStats;
-import com.netflix.servo.monitor.Timer;
-
-/**
- * @author Spencer Gibb
- */
-public class RibbonLoadBalancerContext extends LoadBalancerContext {
-
- public RibbonLoadBalancerContext(ILoadBalancer lb) {
- super(lb);
- }
-
- public RibbonLoadBalancerContext(ILoadBalancer lb, IClientConfig clientConfig) {
- super(lb, clientConfig);
- }
-
- public RibbonLoadBalancerContext(ILoadBalancer lb, IClientConfig clientConfig,
- RetryHandler handler) {
- super(lb, clientConfig, handler);
- }
-
- @Override
- public void noteOpenConnection(ServerStats serverStats) {
- super.noteOpenConnection(serverStats);
- }
-
- @Override
- public Timer getExecuteTracer() {
- return super.getExecuteTracer();
- }
-
- @Override
- public void noteRequestCompletion(ServerStats stats, Object response, Throwable e,
- long responseTime) {
- super.noteRequestCompletion(stats, response, e, responseTime);
- }
-
- @Override
- public void noteRequestCompletion(ServerStats stats, Object response, Throwable e,
- long responseTime, RetryHandler errorHandler) {
- super.noteRequestCompletion(stats, response, e, responseTime, errorHandler);
- }
-
-}
diff --git a/spring-cloud-netflix-ribbon/src/main/java/org/springframework/cloud/netflix/ribbon/RibbonProperties.java b/spring-cloud-netflix-ribbon/src/main/java/org/springframework/cloud/netflix/ribbon/RibbonProperties.java
deleted file mode 100644
index 5e6437996..000000000
--- a/spring-cloud-netflix-ribbon/src/main/java/org/springframework/cloud/netflix/ribbon/RibbonProperties.java
+++ /dev/null
@@ -1,222 +0,0 @@
-/*
- * Copyright 2018-2019 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * https://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.springframework.cloud.netflix.ribbon;
-
-import java.util.concurrent.TimeUnit;
-
-import com.netflix.client.config.CommonClientConfigKey;
-import com.netflix.client.config.IClientConfig;
-import com.netflix.client.config.IClientConfigKey;
-
-import static com.netflix.client.config.CommonClientConfigKey.PoolKeepAliveTime;
-import static com.netflix.client.config.CommonClientConfigKey.PoolKeepAliveTimeUnits;
-import static com.netflix.client.config.CommonClientConfigKey.Port;
-import static com.netflix.client.config.CommonClientConfigKey.SecurePort;
-import static com.netflix.client.config.DefaultClientConfigImpl.DEFAULT_CONNECTION_IDLE_TIMERTASK_REPEAT_IN_MSECS;
-import static com.netflix.client.config.DefaultClientConfigImpl.DEFAULT_CONNECT_TIMEOUT;
-import static com.netflix.client.config.DefaultClientConfigImpl.DEFAULT_FOLLOW_REDIRECTS;
-import static com.netflix.client.config.DefaultClientConfigImpl.DEFAULT_MAX_CONNECTIONS_PER_HOST;
-import static com.netflix.client.config.DefaultClientConfigImpl.DEFAULT_MAX_TOTAL_CONNECTIONS;
-import static com.netflix.client.config.DefaultClientConfigImpl.DEFAULT_OK_TO_RETRY_ON_ALL_OPERATIONS;
-import static com.netflix.client.config.DefaultClientConfigImpl.DEFAULT_POOL_KEEP_ALIVE_TIME;
-import static com.netflix.client.config.DefaultClientConfigImpl.DEFAULT_POOL_KEEP_ALIVE_TIME_UNITS;
-import static com.netflix.client.config.DefaultClientConfigImpl.DEFAULT_PORT;
-import static com.netflix.client.config.DefaultClientConfigImpl.DEFAULT_READ_TIMEOUT;
-
-/**
- * Stores and allows the access to Ribbon {@link IClientConfig}.
- *
- * @author Spencer Gibb
- * @author Tomasz Juchniewicz
- */
-public class RibbonProperties {
-
- private final IClientConfig config;
-
- public static RibbonProperties from(IClientConfig config) {
- return new RibbonProperties(config);
- }
-
- RibbonProperties(IClientConfig config) {
- this.config = config;
- }
-
- public Integer getConnectionCleanerRepeatInterval() {
- return get(CommonClientConfigKey.ConnectionCleanerRepeatInterval);
- }
-
- public int connectionCleanerRepeatInterval() {
- return get(CommonClientConfigKey.ConnectionCleanerRepeatInterval,
- DEFAULT_CONNECTION_IDLE_TIMERTASK_REPEAT_IN_MSECS);
- }
-
- public Integer getConnectTimeout() {
- return get(CommonClientConfigKey.ConnectTimeout);
- }
-
- public int connectTimeout() {
- return connectTimeout(DEFAULT_CONNECT_TIMEOUT);
- }
-
- public int connectTimeout(int defaultValue) {
- return get(CommonClientConfigKey.ConnectTimeout, defaultValue);
- }
-
- public Boolean getFollowRedirects() {
- return get(CommonClientConfigKey.FollowRedirects);
- }
-
- public boolean isFollowRedirects() {
- return isFollowRedirects(DEFAULT_FOLLOW_REDIRECTS);
- }
-
- public boolean isFollowRedirects(boolean defaultValue) {
- return get(CommonClientConfigKey.FollowRedirects, defaultValue);
- }
-
- public boolean isGZipPayload() {
- return isGZipPayload(RibbonClientConfiguration.DEFAULT_GZIP_PAYLOAD);
- }
-
- public boolean isGZipPayload(boolean defaultValue) {
- return get(CommonClientConfigKey.GZipPayload, defaultValue);
- }
-
- public Integer getMaxConnectionsPerHost() {
- return get(CommonClientConfigKey.MaxConnectionsPerHost);
- }
-
- public int maxConnectionsPerHost() {
- return maxConnectionsPerHost(DEFAULT_MAX_CONNECTIONS_PER_HOST);
- }
-
- public int maxConnectionsPerHost(int defaultValue) {
- return get(CommonClientConfigKey.MaxConnectionsPerHost, defaultValue);
- }
-
- public Integer getMaxTotalConnections() {
- return get(CommonClientConfigKey.MaxTotalConnections);
- }
-
- public int maxTotalConnections() {
- return maxTotalConnections(DEFAULT_MAX_TOTAL_CONNECTIONS);
- }
-
- public int maxTotalConnections(int defaultValue) {
- return get(CommonClientConfigKey.MaxTotalConnections, defaultValue);
- }
-
- public Boolean getOkToRetryOnAllOperations() {
- return get(CommonClientConfigKey.OkToRetryOnAllOperations);
- }
-
- public boolean isOkToRetryOnAllOperations() {
- return get(CommonClientConfigKey.OkToRetryOnAllOperations,
- DEFAULT_OK_TO_RETRY_ON_ALL_OPERATIONS);
- }
-
- @SuppressWarnings("deprecation")
- public Long getPoolKeepAliveTime() {
- Object property = this.config.getProperty(PoolKeepAliveTime);
- if (property instanceof Long) {
- return (Long) property;
- }
- else if (property instanceof String) {
- return Long.valueOf((String) property);
- }
- return null;
- }
-
- public long poolKeepAliveTime() {
- Long poolKeepAliveTime = getPoolKeepAliveTime();
- if (poolKeepAliveTime != null) {
- return poolKeepAliveTime;
- }
-
- return DEFAULT_POOL_KEEP_ALIVE_TIME;
- }
-
- @SuppressWarnings("deprecation")
- public TimeUnit getPoolKeepAliveTimeUnits() {
- Object property = this.config.getProperty(PoolKeepAliveTimeUnits);
- if (property instanceof TimeUnit) {
- return (TimeUnit) property;
- }
- return DEFAULT_POOL_KEEP_ALIVE_TIME_UNITS;
- }
-
- public Integer getPort() {
- return get(Port);
- }
-
- public int port() {
- return get(Port, DEFAULT_PORT);
- }
-
- public Integer getReadTimeout() {
- return get(CommonClientConfigKey.ReadTimeout);
- }
-
- public int readTimeout() {
- return readTimeout(DEFAULT_READ_TIMEOUT);
- }
-
- public int readTimeout(int defaultValue) {
- return get(CommonClientConfigKey.ReadTimeout, defaultValue);
- }
-
- public Boolean getSecure() {
- return get(CommonClientConfigKey.IsSecure);
- }
-
- public boolean isSecure() {
- return isSecure(false);
- }
-
- public boolean isSecure(boolean defaultValue) {
- return get(CommonClientConfigKey.IsSecure, defaultValue);
- }
-
- public Integer getSecurePort() {
- return this.config.get(SecurePort);
- }
-
- public Boolean getUseIPAddrForServer() {
- return get(CommonClientConfigKey.UseIPAddrForServer);
- }
-
- public boolean isUseIPAddrForServer() {
- return isUseIPAddrForServer(false);
- }
-
- public boolean isUseIPAddrForServer(boolean defaultValue) {
- return get(CommonClientConfigKey.UseIPAddrForServer, defaultValue);
- }
-
- public boolean has(IClientConfigKey key) {
- return this.config.containsProperty(key);
- }
-
- public T get(IClientConfigKey key) {
- return this.config.get(key);
- }
-
- public T get(IClientConfigKey key, T defaultValue) {
- return this.config.get(key, defaultValue);
- }
-
-}
diff --git a/spring-cloud-netflix-ribbon/src/main/java/org/springframework/cloud/netflix/ribbon/RibbonStatsRecorder.java b/spring-cloud-netflix-ribbon/src/main/java/org/springframework/cloud/netflix/ribbon/RibbonStatsRecorder.java
deleted file mode 100644
index 73859f27d..000000000
--- a/spring-cloud-netflix-ribbon/src/main/java/org/springframework/cloud/netflix/ribbon/RibbonStatsRecorder.java
+++ /dev/null
@@ -1,62 +0,0 @@
-/*
- * Copyright 2016-2019 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * https://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.springframework.cloud.netflix.ribbon;
-
-import java.util.concurrent.TimeUnit;
-
-import com.netflix.loadbalancer.Server;
-import com.netflix.loadbalancer.ServerStats;
-import com.netflix.servo.monitor.Stopwatch;
-
-/**
- * @author Spencer Gibb
- */
-public class RibbonStatsRecorder {
-
- private RibbonLoadBalancerContext context;
-
- private ServerStats serverStats;
-
- private Stopwatch tracer;
-
- public RibbonStatsRecorder(RibbonLoadBalancerContext context, Server server) {
- this.context = context;
- if (server != null) {
- serverStats = context.getServerStats(server);
- context.noteOpenConnection(serverStats);
- tracer = context.getExecuteTracer().start();
- }
- }
-
- public void recordStats(Object entity) {
- this.recordStats(entity, null);
- }
-
- public void recordStats(Throwable t) {
- this.recordStats(null, t);
- }
-
- protected void recordStats(Object entity, Throwable exception) {
- if (this.tracer != null && this.serverStats != null) {
- this.tracer.stop();
- long duration = this.tracer.getDuration(TimeUnit.MILLISECONDS);
- this.context.noteRequestCompletion(serverStats, entity, exception, duration,
- null/* errorHandler */);
- }
- }
-
-}
diff --git a/spring-cloud-netflix-ribbon/src/main/java/org/springframework/cloud/netflix/ribbon/RibbonUtils.java b/spring-cloud-netflix-ribbon/src/main/java/org/springframework/cloud/netflix/ribbon/RibbonUtils.java
deleted file mode 100644
index c29fd07fa..000000000
--- a/spring-cloud-netflix-ribbon/src/main/java/org/springframework/cloud/netflix/ribbon/RibbonUtils.java
+++ /dev/null
@@ -1,188 +0,0 @@
-/*
- * Copyright 2016-2019 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * https://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.springframework.cloud.netflix.ribbon;
-
-import java.net.URI;
-import java.util.HashMap;
-import java.util.Map;
-
-import com.netflix.client.config.CommonClientConfigKey;
-import com.netflix.client.config.IClientConfig;
-import com.netflix.config.ConfigurationManager;
-import com.netflix.config.DynamicPropertyFactory;
-import com.netflix.config.DynamicStringProperty;
-import com.netflix.loadbalancer.Server;
-
-import org.springframework.cloud.client.ServiceInstance;
-import org.springframework.util.StringUtils;
-import org.springframework.web.util.UriComponentsBuilder;
-
-import static com.netflix.client.config.CommonClientConfigKey.DeploymentContextBasedVipAddresses;
-import static com.netflix.client.config.CommonClientConfigKey.EnableZoneAffinity;
-
-/**
- * @author Spencer Gibb
- * @author Jacques-Etienne Beaudet
- * @author Tim Ysewyn
- */
-public final class RibbonUtils {
-
- /**
- * Used to verify if property value is set.
- */
- public static final String VALUE_NOT_SET = "__not__set__";
-
- /**
- * Default Ribbon namespace.
- */
- public static final String DEFAULT_NAMESPACE = "ribbon";
-
- private static final Map unsecureSchemeMapping;
-
- static {
- unsecureSchemeMapping = new HashMap<>();
- unsecureSchemeMapping.put("http", "https");
- unsecureSchemeMapping.put("ws", "wss");
- }
-
- private RibbonUtils() {
- throw new AssertionError("Must not instantiate utility class.");
- }
-
- public static void initializeRibbonDefaults(String serviceId) {
- setRibbonProperty(serviceId, DeploymentContextBasedVipAddresses.key(), serviceId);
- setRibbonProperty(serviceId, EnableZoneAffinity.key(), "true");
- }
-
- public static void setRibbonProperty(String serviceId, String suffix, String value) {
- // how to set the namespace properly?
- String key = getRibbonKey(serviceId, suffix);
- DynamicStringProperty property = getProperty(key);
- if (property.get().equals(VALUE_NOT_SET)) {
- ConfigurationManager.getConfigInstance().setProperty(key, value);
- }
- }
-
- public static String getRibbonKey(String serviceId, String suffix) {
- return serviceId + "." + DEFAULT_NAMESPACE + "." + suffix;
- }
-
- public static DynamicStringProperty getProperty(String key) {
- return DynamicPropertyFactory.getInstance().getStringProperty(key, VALUE_NOT_SET);
- }
-
- /**
- * Determine if client is secure. If the supplied {@link IClientConfig} has the
- * {@link CommonClientConfigKey#IsSecure} set, return that value. Otherwise, query the
- * supplied {@link ServerIntrospector}.
- * @param config the supplied client configuration.
- * @param serverIntrospector used to verify if the server provides secure connections
- * @param server to verify
- * @return true if the client is secure
- */
- public static boolean isSecure(IClientConfig config,
- ServerIntrospector serverIntrospector, Server server) {
- if (config != null) {
- Boolean isSecure = config.get(CommonClientConfigKey.IsSecure);
- if (isSecure != null) {
- return isSecure;
- }
- }
-
- return serverIntrospector.isSecure(server);
- }
-
- /**
- * Replace the scheme to https if needed. If the uri doesn't start with https and
- * {@link #isSecure(IClientConfig, ServerIntrospector, Server)} is true, update the
- * scheme. This assumes the uri is already encoded to avoid double encoding.
- * @param uri to modify if required
- * @param config Ribbon {@link IClientConfig} configuration
- * @param serverIntrospector used to verify if the server provides secure connections
- * @param server to verify
- * @return {@link URI} updated to https if necessary
- * @deprecated use {@link #updateToSecureConnectionIfNeeded}
- */
- public static URI updateToHttpsIfNeeded(URI uri, IClientConfig config,
- ServerIntrospector serverIntrospector, Server server) {
- return updateToSecureConnectionIfNeeded(uri, config, serverIntrospector, server);
- }
-
- /**
- * Replace the scheme to the secure variant if needed. If the
- * {@link #unsecureSchemeMapping} map contains the uri scheme and
- * {@link #isSecure(IClientConfig, ServerIntrospector, Server)} is true, update the
- * scheme. This assumes the uri is already encoded to avoid double encoding.
- * @param uri to modify if required
- * @param ribbonServer to verify if it provides secure connections
- * @return {@link URI} updated if required
- */
- static URI updateToSecureConnectionIfNeeded(URI uri, ServiceInstance ribbonServer) {
- String scheme = uri.getScheme();
-
- if (StringUtils.isEmpty(scheme)) {
- scheme = "http";
- }
-
- if (!StringUtils.isEmpty(uri.toString())
- && unsecureSchemeMapping.containsKey(scheme) && ribbonServer.isSecure()) {
- return upgradeConnection(uri, unsecureSchemeMapping.get(scheme));
- }
- return uri;
- }
-
- /**
- * Replace the scheme to the secure variant if needed. If the
- * {@link #unsecureSchemeMapping} map contains the uri scheme and
- * {@link #isSecure(IClientConfig, ServerIntrospector, Server)} is true, update the
- * scheme. This assumes the uri is already encoded to avoid double encoding.
- * @param uri to modify if required
- * @param config the supplied client configuration
- * @param serverIntrospector used to verify if the server provides secure connections
- * @param server to verify
- * @return {@link URI} updated if required
- */
- public static URI updateToSecureConnectionIfNeeded(URI uri, IClientConfig config,
- ServerIntrospector serverIntrospector, Server server) {
- String scheme = uri.getScheme();
-
- if (StringUtils.isEmpty(scheme)) {
- scheme = "http";
- }
-
- if (!StringUtils.isEmpty(uri.toString())
- && unsecureSchemeMapping.containsKey(scheme)
- && isSecure(config, serverIntrospector, server)) {
- return upgradeConnection(uri, unsecureSchemeMapping.get(scheme));
- }
- return uri;
- }
-
- private static URI upgradeConnection(URI uri, String scheme) {
- UriComponentsBuilder uriComponentsBuilder = UriComponentsBuilder.fromUri(uri)
- .scheme(scheme);
- if (uri.getRawQuery() != null) {
- // When building the URI, UriComponentsBuilder verify the allowed characters
- // and does not
- // support the '+' so we replace it for its equivalent '%20'.
- // See issue https://jira.spring.io/browse/SPR-10172
- uriComponentsBuilder.replaceQuery(uri.getRawQuery().replace("+", "%20"));
- }
- return uriComponentsBuilder.build(true).toUri();
- }
-
-}
diff --git a/spring-cloud-netflix-ribbon/src/main/java/org/springframework/cloud/netflix/ribbon/ServerIntrospector.java b/spring-cloud-netflix-ribbon/src/main/java/org/springframework/cloud/netflix/ribbon/ServerIntrospector.java
deleted file mode 100644
index 463453a3e..000000000
--- a/spring-cloud-netflix-ribbon/src/main/java/org/springframework/cloud/netflix/ribbon/ServerIntrospector.java
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
- * Copyright 2013-2019 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * https://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.springframework.cloud.netflix.ribbon;
-
-import java.util.Map;
-
-import com.netflix.loadbalancer.Server;
-
-/**
- * @author Spencer Gibb
- */
-public interface ServerIntrospector {
-
- boolean isSecure(Server server);
-
- Map getMetadata(Server server);
-
-}
diff --git a/spring-cloud-netflix-ribbon/src/main/java/org/springframework/cloud/netflix/ribbon/ServerIntrospectorProperties.java b/spring-cloud-netflix-ribbon/src/main/java/org/springframework/cloud/netflix/ribbon/ServerIntrospectorProperties.java
deleted file mode 100644
index 111750e65..000000000
--- a/spring-cloud-netflix-ribbon/src/main/java/org/springframework/cloud/netflix/ribbon/ServerIntrospectorProperties.java
+++ /dev/null
@@ -1,65 +0,0 @@
-/*
- * Copyright 2013-2019 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * https://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.springframework.cloud.netflix.ribbon;
-
-import java.util.Arrays;
-import java.util.List;
-import java.util.Objects;
-
-import org.springframework.boot.context.properties.ConfigurationProperties;
-
-/**
- * @author Rico Pahlisch
- * @author Gregor Zurowski
- */
-@ConfigurationProperties("ribbon")
-public class ServerIntrospectorProperties {
-
- private List securePorts = Arrays.asList(443, 8443);
-
- public List getSecurePorts() {
- return securePorts;
- }
-
- public void setSecurePorts(List securePorts) {
- this.securePorts = securePorts;
- }
-
- @Override
- public boolean equals(Object o) {
- if (this == o) {
- return true;
- }
- if (o == null || getClass() != o.getClass()) {
- return false;
- }
- ServerIntrospectorProperties that = (ServerIntrospectorProperties) o;
- return Objects.equals(securePorts, that.securePorts);
- }
-
- @Override
- public int hashCode() {
- return Objects.hash(securePorts);
- }
-
- @Override
- public String toString() {
- return new StringBuilder("ServerIntrospectorProperties{").append("securePorts=")
- .append(securePorts).append("}").toString();
- }
-
-}
diff --git a/spring-cloud-netflix-ribbon/src/main/java/org/springframework/cloud/netflix/ribbon/SpringClientFactory.java b/spring-cloud-netflix-ribbon/src/main/java/org/springframework/cloud/netflix/ribbon/SpringClientFactory.java
deleted file mode 100644
index f0b6b7c0e..000000000
--- a/spring-cloud-netflix-ribbon/src/main/java/org/springframework/cloud/netflix/ribbon/SpringClientFactory.java
+++ /dev/null
@@ -1,134 +0,0 @@
-/*
- * Copyright 2013-2019 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * https://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.springframework.cloud.netflix.ribbon;
-
-import java.lang.reflect.Constructor;
-
-import com.netflix.client.IClient;
-import com.netflix.client.IClientConfigAware;
-import com.netflix.client.config.IClientConfig;
-import com.netflix.loadbalancer.ILoadBalancer;
-
-import org.springframework.beans.BeanUtils;
-import org.springframework.cloud.context.named.NamedContextFactory;
-import org.springframework.context.annotation.AnnotationConfigApplicationContext;
-
-/**
- * A factory that creates client, load balancer and client configuration instances. It
- * creates a Spring ApplicationContext per client name, and extracts the beans that it
- * needs from there.
- *
- * @author Spencer Gibb
- * @author Dave Syer
- */
-public class SpringClientFactory extends NamedContextFactory {
-
- static final String NAMESPACE = "ribbon";
-
- public SpringClientFactory() {
- super(RibbonClientConfiguration.class, NAMESPACE, "ribbon.client.name");
- }
-
- /**
- * Get the rest client associated with the name.
- * @param name name to search by
- * @param clientClass the class of the client bean
- * @param {@link IClient} subtype
- * @return {@link IClient} instance
- * @throws RuntimeException if any error occurs
- */
- public > C getClient(String name, Class clientClass) {
- return getInstance(name, clientClass);
- }
-
- /**
- * Get the load balancer associated with the name.
- * @param name name to search by
- * @return {@link ILoadBalancer} instance
- * @throws RuntimeException if any error occurs
- */
- public ILoadBalancer getLoadBalancer(String name) {
- return getInstance(name, ILoadBalancer.class);
- }
-
- /**
- * Get the client config associated with the name.
- * @param name name to search by
- * @return {@link IClientConfig} instance
- * @throws RuntimeException if any error occurs
- */
- public IClientConfig getClientConfig(String name) {
- return getInstance(name, IClientConfig.class);
- }
-
- /**
- * Get the load balancer context associated with the name.
- * @param serviceId id of the service to search by
- * @return {@link RibbonLoadBalancerContext} instance
- * @throws RuntimeException if any error occurs
- */
- public RibbonLoadBalancerContext getLoadBalancerContext(String serviceId) {
- return getInstance(serviceId, RibbonLoadBalancerContext.class);
- }
-
- static C instantiateWithConfig(Class clazz, IClientConfig config) {
- return instantiateWithConfig(null, clazz, config);
- }
-
- static C instantiateWithConfig(AnnotationConfigApplicationContext context,
- Class clazz, IClientConfig config) {
- C result = null;
-
- try {
- Constructor constructor = clazz.getConstructor(IClientConfig.class);
- result = constructor.newInstance(config);
- }
- catch (Throwable e) {
- // Ignored
- }
-
- if (result == null) {
- result = BeanUtils.instantiateClass(clazz);
-
- if (result instanceof IClientConfigAware) {
- ((IClientConfigAware) result).initWithNiwsConfig(config);
- }
-
- if (context != null) {
- context.getAutowireCapableBeanFactory().autowireBean(result);
- }
- }
-
- return result;
- }
-
- @Override
- public C getInstance(String name, Class type) {
- C instance = super.getInstance(name, type);
- if (instance != null) {
- return instance;
- }
- IClientConfig config = getInstance(name, IClientConfig.class);
- return instantiateWithConfig(getContext(name), type, config);
- }
-
- @Override
- protected AnnotationConfigApplicationContext getContext(String name) {
- return super.getContext(name);
- }
-
-}
diff --git a/spring-cloud-netflix-ribbon/src/main/java/org/springframework/cloud/netflix/ribbon/StaticServerList.java b/spring-cloud-netflix-ribbon/src/main/java/org/springframework/cloud/netflix/ribbon/StaticServerList.java
deleted file mode 100644
index 42f585f85..000000000
--- a/spring-cloud-netflix-ribbon/src/main/java/org/springframework/cloud/netflix/ribbon/StaticServerList.java
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * Copyright 2013-2019 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * https://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.springframework.cloud.netflix.ribbon;
-
-import java.util.Arrays;
-import java.util.List;
-
-import com.netflix.loadbalancer.Server;
-import com.netflix.loadbalancer.ServerList;
-
-/**
- * Represents list of servers used by Ribbon.
- *
- * @param {@link Server} subtype
- * @author Spencer Gibb
- */
-public class StaticServerList implements ServerList {
-
- private final List servers;
-
- public StaticServerList(T... servers) {
- this.servers = Arrays.asList(servers);
- }
-
- @Override
- public List getInitialListOfServers() {
- return servers;
- }
-
- @Override
- public List getUpdatedListOfServers() {
- return servers;
- }
-
-}
diff --git a/spring-cloud-netflix-ribbon/src/main/java/org/springframework/cloud/netflix/ribbon/ZonePreferenceServerListFilter.java b/spring-cloud-netflix-ribbon/src/main/java/org/springframework/cloud/netflix/ribbon/ZonePreferenceServerListFilter.java
deleted file mode 100644
index c57c06f13..000000000
--- a/spring-cloud-netflix-ribbon/src/main/java/org/springframework/cloud/netflix/ribbon/ZonePreferenceServerListFilter.java
+++ /dev/null
@@ -1,96 +0,0 @@
-/*
- * Copyright 2013-2019 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * https://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.springframework.cloud.netflix.ribbon;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Objects;
-
-import com.netflix.client.config.IClientConfig;
-import com.netflix.config.ConfigurationManager;
-import com.netflix.config.DeploymentContext.ContextKey;
-import com.netflix.loadbalancer.Server;
-import com.netflix.loadbalancer.ZoneAffinityServerListFilter;
-
-/**
- * A filter that actively prefers the local zone (as defined by the deployment context, or
- * the Eureka instance metadata).
- *
- * @author Dave Syer
- */
-public class ZonePreferenceServerListFilter extends ZoneAffinityServerListFilter {
-
- private String zone;
-
- @Override
- public void initWithNiwsConfig(IClientConfig niwsClientConfig) {
- super.initWithNiwsConfig(niwsClientConfig);
- if (ConfigurationManager.getDeploymentContext() != null) {
- this.zone = ConfigurationManager.getDeploymentContext()
- .getValue(ContextKey.zone);
- }
- }
-
- @Override
- public List getFilteredListOfServers(List servers) {
- List output = super.getFilteredListOfServers(servers);
- if (this.zone != null && output.size() == servers.size()) {
- List local = new ArrayList<>();
- for (Server server : output) {
- if (this.zone.equalsIgnoreCase(server.getZone())) {
- local.add(server);
- }
- }
- if (!local.isEmpty()) {
- return local;
- }
- }
- return output;
- }
-
- public String getZone() {
- return zone;
- }
-
- public void setZone(String zone) {
- this.zone = zone;
- }
-
- @Override
- public boolean equals(Object o) {
- if (this == o) {
- return true;
- }
- if (o == null || getClass() != o.getClass()) {
- return false;
- }
- ZonePreferenceServerListFilter that = (ZonePreferenceServerListFilter) o;
- return Objects.equals(zone, that.zone);
- }
-
- @Override
- public int hashCode() {
- return Objects.hash(zone);
- }
-
- @Override
- public String toString() {
- return new StringBuilder("ZonePreferenceServerListFilter{").append("zone='")
- .append(zone).append("'").append("}").toString();
- }
-
-}
diff --git a/spring-cloud-netflix-ribbon/src/main/java/org/springframework/cloud/netflix/ribbon/apache/HttpClientRibbonConfiguration.java b/spring-cloud-netflix-ribbon/src/main/java/org/springframework/cloud/netflix/ribbon/apache/HttpClientRibbonConfiguration.java
deleted file mode 100644
index cb1d8438f..000000000
--- a/spring-cloud-netflix-ribbon/src/main/java/org/springframework/cloud/netflix/ribbon/apache/HttpClientRibbonConfiguration.java
+++ /dev/null
@@ -1,154 +0,0 @@
-/*
- * Copyright 2013-2019 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * https://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.springframework.cloud.netflix.ribbon.apache;
-
-import java.util.Timer;
-import java.util.TimerTask;
-import java.util.concurrent.TimeUnit;
-
-import javax.annotation.PreDestroy;
-
-import com.netflix.client.AbstractLoadBalancerAwareClient;
-import com.netflix.client.RetryHandler;
-import com.netflix.client.config.IClientConfig;
-import com.netflix.loadbalancer.ILoadBalancer;
-import com.netflix.servo.monitor.Monitors;
-import org.apache.http.client.config.RequestConfig;
-import org.apache.http.config.RegistryBuilder;
-import org.apache.http.conn.HttpClientConnectionManager;
-import org.apache.http.impl.client.CloseableHttpClient;
-
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
-import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
-import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingClass;
-import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
-import org.springframework.cloud.client.loadbalancer.LoadBalancedRetryFactory;
-import org.springframework.cloud.commons.httpclient.ApacheHttpClientConnectionManagerFactory;
-import org.springframework.cloud.commons.httpclient.ApacheHttpClientFactory;
-import org.springframework.cloud.netflix.ribbon.RibbonClientName;
-import org.springframework.cloud.netflix.ribbon.RibbonLoadBalancerContext;
-import org.springframework.cloud.netflix.ribbon.RibbonProperties;
-import org.springframework.cloud.netflix.ribbon.ServerIntrospector;
-import org.springframework.context.annotation.Bean;
-import org.springframework.context.annotation.Configuration;
-
-/**
- * @author Spencer Gibb
- */
-@Configuration(proxyBeanMethods = false)
-@ConditionalOnClass(name = "org.apache.http.client.HttpClient")
-@ConditionalOnProperty(name = "ribbon.httpclient.enabled", matchIfMissing = true)
-public class HttpClientRibbonConfiguration {
-
- @RibbonClientName
- private String name = "client";
-
- @Bean
- @ConditionalOnMissingBean(AbstractLoadBalancerAwareClient.class)
- @ConditionalOnMissingClass("org.springframework.retry.support.RetryTemplate")
- public RibbonLoadBalancingHttpClient ribbonLoadBalancingHttpClient(
- IClientConfig config, ServerIntrospector serverIntrospector,
- ILoadBalancer loadBalancer, RetryHandler retryHandler,
- CloseableHttpClient httpClient) {
- RibbonLoadBalancingHttpClient client = new RibbonLoadBalancingHttpClient(
- httpClient, config, serverIntrospector);
- client.setLoadBalancer(loadBalancer);
- client.setRetryHandler(retryHandler);
- Monitors.registerObject("Client_" + this.name, client);
- return client;
- }
-
- @Bean
- @ConditionalOnMissingBean(AbstractLoadBalancerAwareClient.class)
- @ConditionalOnClass(name = "org.springframework.retry.support.RetryTemplate")
- public RetryableRibbonLoadBalancingHttpClient retryableRibbonLoadBalancingHttpClient(
- IClientConfig config, ServerIntrospector serverIntrospector,
- ILoadBalancer loadBalancer, RetryHandler retryHandler,
- LoadBalancedRetryFactory loadBalancedRetryFactory,
- CloseableHttpClient httpClient,
- RibbonLoadBalancerContext ribbonLoadBalancerContext) {
- RetryableRibbonLoadBalancingHttpClient client = new RetryableRibbonLoadBalancingHttpClient(
- httpClient, config, serverIntrospector, loadBalancedRetryFactory);
- client.setLoadBalancer(loadBalancer);
- client.setRetryHandler(retryHandler);
- client.setRibbonLoadBalancerContext(ribbonLoadBalancerContext);
- Monitors.registerObject("Client_" + this.name, client);
- return client;
- }
-
- @Configuration(proxyBeanMethods = false)
- protected static class ApacheHttpClientConfiguration {
-
- private final Timer connectionManagerTimer = new Timer(
- "RibbonApacheHttpClientConfiguration.connectionManagerTimer", true);
-
- private CloseableHttpClient httpClient;
-
- @Autowired(required = false)
- private RegistryBuilder registryBuilder;
-
- @Bean
- @ConditionalOnMissingBean(HttpClientConnectionManager.class)
- public HttpClientConnectionManager httpClientConnectionManager(
- IClientConfig config,
- ApacheHttpClientConnectionManagerFactory connectionManagerFactory) {
- RibbonProperties ribbon = RibbonProperties.from(config);
- int maxTotalConnections = ribbon.maxTotalConnections();
- int maxConnectionsPerHost = ribbon.maxConnectionsPerHost();
- int timerRepeat = ribbon.connectionCleanerRepeatInterval();
- long timeToLive = ribbon.poolKeepAliveTime();
- TimeUnit ttlUnit = ribbon.getPoolKeepAliveTimeUnits();
- final HttpClientConnectionManager connectionManager = connectionManagerFactory
- .newConnectionManager(false, maxTotalConnections,
- maxConnectionsPerHost, timeToLive, ttlUnit, registryBuilder);
- this.connectionManagerTimer.schedule(new TimerTask() {
- @Override
- public void run() {
- connectionManager.closeExpiredConnections();
- }
- }, 30000, timerRepeat);
- return connectionManager;
- }
-
- @Bean
- @ConditionalOnMissingBean(CloseableHttpClient.class)
- public CloseableHttpClient httpClient(ApacheHttpClientFactory httpClientFactory,
- HttpClientConnectionManager connectionManager, IClientConfig config) {
- RibbonProperties ribbon = RibbonProperties.from(config);
- Boolean followRedirects = ribbon.isFollowRedirects();
- Integer connectTimeout = ribbon.connectTimeout();
- RequestConfig defaultRequestConfig = RequestConfig.custom()
- .setConnectTimeout(connectTimeout)
- .setRedirectsEnabled(followRedirects).build();
- this.httpClient = httpClientFactory.createBuilder()
- .setDefaultRequestConfig(defaultRequestConfig)
- .setConnectionManager(connectionManager).build();
- return httpClient;
- }
-
- @PreDestroy
- public void destroy() throws Exception {
- connectionManagerTimer.cancel();
- if (httpClient != null) {
- httpClient.close();
- }
- }
-
- }
-
-}
diff --git a/spring-cloud-netflix-ribbon/src/main/java/org/springframework/cloud/netflix/ribbon/apache/HttpClientStatusCodeException.java b/spring-cloud-netflix-ribbon/src/main/java/org/springframework/cloud/netflix/ribbon/apache/HttpClientStatusCodeException.java
deleted file mode 100644
index 54cb28598..000000000
--- a/spring-cloud-netflix-ribbon/src/main/java/org/springframework/cloud/netflix/ribbon/apache/HttpClientStatusCodeException.java
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- * Copyright 2013-2019 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * https://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.springframework.cloud.netflix.ribbon.apache;
-
-import java.io.IOException;
-import java.net.URI;
-
-import org.apache.http.HttpEntity;
-import org.apache.http.HttpResponse;
-import org.apache.http.message.BasicHttpResponse;
-import org.apache.http.util.EntityUtils;
-
-import org.springframework.cloud.client.loadbalancer.RetryableStatusCodeException;
-
-/**
- * A {@link RetryableStatusCodeException} for {@link HttpResponse}s.
- *
- * @author Ryan Baxter
- */
-public class HttpClientStatusCodeException extends RetryableStatusCodeException {
-
- private final BasicHttpResponse response;
-
- public HttpClientStatusCodeException(String serviceId, HttpResponse response,
- HttpEntity entity, URI uri) throws IOException {
- super(serviceId, response.getStatusLine().getStatusCode(), response, uri);
- this.response = new BasicHttpResponse(response.getStatusLine());
- this.response.setLocale(response.getLocale());
- this.response.setStatusCode(response.getStatusLine().getStatusCode());
- this.response.setReasonPhrase(response.getStatusLine().getReasonPhrase());
- this.response.setHeaders(response.getAllHeaders());
- EntityUtils.updateEntity(this.response, entity);
- }
-
- @Override
- public HttpResponse getResponse() {
- return this.response;
- }
-
-}
diff --git a/spring-cloud-netflix-ribbon/src/main/java/org/springframework/cloud/netflix/ribbon/apache/HttpClientUtils.java b/spring-cloud-netflix-ribbon/src/main/java/org/springframework/cloud/netflix/ribbon/apache/HttpClientUtils.java
deleted file mode 100644
index 05e757cf1..000000000
--- a/spring-cloud-netflix-ribbon/src/main/java/org/springframework/cloud/netflix/ribbon/apache/HttpClientUtils.java
+++ /dev/null
@@ -1,58 +0,0 @@
-/*
- * Copyright 2013-2019 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * https://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.springframework.cloud.netflix.ribbon.apache;
-
-import java.io.ByteArrayInputStream;
-import java.io.IOException;
-
-import org.apache.http.HttpEntity;
-import org.apache.http.HttpResponse;
-import org.apache.http.client.methods.CloseableHttpResponse;
-import org.apache.http.entity.BasicHttpEntity;
-import org.apache.http.util.EntityUtils;
-
-/**
- * Provides basic utilities for {@link org.apache.http.client.HttpClient}.
- *
- * @author Ryan Baxter
- */
-public final class HttpClientUtils {
-
- private HttpClientUtils() {
- throw new AssertionError("Must not instantiate utility class.");
- }
-
- /**
- * Creates an new {@link HttpEntity} by copying the {@link HttpEntity} from the
- * {@link HttpResponse}. This method will close the response after copying the entity.
- * @param response The response to create the {@link HttpEntity} from
- * @return A new {@link HttpEntity}
- * @throws IOException thrown if there is a problem closing the response.
- */
- public static HttpEntity createEntity(HttpResponse response) throws IOException {
- ByteArrayInputStream is = new ByteArrayInputStream(
- EntityUtils.toByteArray(response.getEntity()));
- BasicHttpEntity entity = new BasicHttpEntity();
- entity.setContent(is);
- entity.setContentLength(response.getEntity().getContentLength());
- if (CloseableHttpResponse.class.isInstance(response)) {
- ((CloseableHttpResponse) response).close();
- }
- return entity;
- }
-
-}
diff --git a/spring-cloud-netflix-ribbon/src/main/java/org/springframework/cloud/netflix/ribbon/apache/RetryableRibbonLoadBalancingHttpClient.java b/spring-cloud-netflix-ribbon/src/main/java/org/springframework/cloud/netflix/ribbon/apache/RetryableRibbonLoadBalancingHttpClient.java
deleted file mode 100644
index ec1016137..000000000
--- a/spring-cloud-netflix-ribbon/src/main/java/org/springframework/cloud/netflix/ribbon/apache/RetryableRibbonLoadBalancingHttpClient.java
+++ /dev/null
@@ -1,203 +0,0 @@
-/*
- * Copyright 2013-2019 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * https://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.springframework.cloud.netflix.ribbon.apache;
-
-import java.net.URI;
-
-import com.netflix.client.RequestSpecificRetryHandler;
-import com.netflix.client.RetryHandler;
-import com.netflix.client.config.IClientConfig;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.http.HttpResponse;
-import org.apache.http.client.config.RequestConfig;
-import org.apache.http.client.methods.HttpUriRequest;
-import org.apache.http.impl.client.CloseableHttpClient;
-
-import org.springframework.cloud.client.ServiceInstance;
-import org.springframework.cloud.client.loadbalancer.InterceptorRetryPolicy;
-import org.springframework.cloud.client.loadbalancer.LoadBalancedRecoveryCallback;
-import org.springframework.cloud.client.loadbalancer.LoadBalancedRetryContext;
-import org.springframework.cloud.client.loadbalancer.LoadBalancedRetryFactory;
-import org.springframework.cloud.client.loadbalancer.LoadBalancedRetryPolicy;
-import org.springframework.cloud.client.loadbalancer.ServiceInstanceChooser;
-import org.springframework.cloud.netflix.ribbon.RibbonLoadBalancerClient.RibbonServer;
-import org.springframework.cloud.netflix.ribbon.RibbonLoadBalancerContext;
-import org.springframework.cloud.netflix.ribbon.RibbonProperties;
-import org.springframework.cloud.netflix.ribbon.RibbonStatsRecorder;
-import org.springframework.cloud.netflix.ribbon.ServerIntrospector;
-import org.springframework.cloud.netflix.ribbon.support.ContextAwareRequest;
-import org.springframework.http.HttpRequest;
-import org.springframework.retry.RecoveryCallback;
-import org.springframework.retry.RetryCallback;
-import org.springframework.retry.RetryListener;
-import org.springframework.retry.backoff.BackOffPolicy;
-import org.springframework.retry.backoff.NoBackOffPolicy;
-import org.springframework.retry.policy.NeverRetryPolicy;
-import org.springframework.retry.support.RetryTemplate;
-import org.springframework.web.util.UriComponentsBuilder;
-
-/**
- * An Apache HTTP client which leverages Spring Retry to retry failed requests.
- *
- * @author Ryan Baxter
- * @author Gang Li
- */
-public class RetryableRibbonLoadBalancingHttpClient
- extends RibbonLoadBalancingHttpClient {
-
- private static final Log LOGGER = LogFactory
- .getLog(RetryableRibbonLoadBalancingHttpClient.class);
-
- private LoadBalancedRetryFactory loadBalancedRetryFactory;
-
- private RibbonLoadBalancerContext ribbonLoadBalancerContext;
-
- public RetryableRibbonLoadBalancingHttpClient(CloseableHttpClient delegate,
- IClientConfig config, ServerIntrospector serverIntrospector,
- LoadBalancedRetryFactory loadBalancedRetryFactory) {
- super(delegate, config, serverIntrospector);
- this.loadBalancedRetryFactory = loadBalancedRetryFactory;
- }
-
- @Override
- public RibbonApacheHttpResponse execute(final RibbonApacheHttpRequest request,
- final IClientConfig configOverride) throws Exception {
- final RequestConfig.Builder builder = RequestConfig.custom();
- IClientConfig config = configOverride != null ? configOverride : this.config;
- RibbonProperties ribbon = RibbonProperties.from(config);
- builder.setConnectTimeout(ribbon.connectTimeout(this.connectTimeout));
- builder.setSocketTimeout(ribbon.readTimeout(this.readTimeout));
- builder.setRedirectsEnabled(ribbon.isFollowRedirects(this.followRedirects));
- builder.setContentCompressionEnabled(ribbon.isGZipPayload(this.gzipPayload));
-
- final RequestConfig requestConfig = builder.build();
- final LoadBalancedRetryPolicy retryPolicy = loadBalancedRetryFactory
- .createRetryPolicy(this.getClientName(), this);
-
- RetryCallback retryCallback = context -> {
- // on retries the policy will choose the server and set it in the context
- // extract the server and update the request being made
- RibbonApacheHttpRequest newRequest = request;
- RibbonStatsRecorder statsRecorder = null;
- if (context instanceof LoadBalancedRetryContext) {
- ServiceInstance service = ((LoadBalancedRetryContext) context)
- .getServiceInstance();
- validateServiceInstance(service);
- if (service != null) {
- // Reconstruct the request URI using the host and port set in the
- // retry context
- newRequest = newRequest.withNewUri(UriComponentsBuilder.newInstance()
- .host(service.getHost()).scheme(service.getUri().getScheme())
- .userInfo(newRequest.getURI().getUserInfo())
- .port(service.getPort())
- .path(newRequest.getURI().getRawPath())
- .query(newRequest.getURI().getQuery())
- .fragment(newRequest.getURI().getFragment()).build(true)
- .encode().toUri());
- if (ribbonLoadBalancerContext == null) {
- LOGGER.error(
- "RibbonLoadBalancerContext is null. Unable to update load balancer stats");
- }
- else if (service instanceof RibbonServer) {
- statsRecorder = new RibbonStatsRecorder(ribbonLoadBalancerContext,
- ((RibbonServer) service).getServer());
- }
- }
- }
- newRequest = getSecureRequest(newRequest, configOverride);
- HttpUriRequest httpUriRequest = newRequest.toRequest(requestConfig);
- final HttpResponse httpResponse = RetryableRibbonLoadBalancingHttpClient.this.delegate
- .execute(httpUriRequest);
- if (retryPolicy
- .retryableStatusCode(httpResponse.getStatusLine().getStatusCode())) {
- throw new HttpClientStatusCodeException(
- RetryableRibbonLoadBalancingHttpClient.this.clientName,
- httpResponse, HttpClientUtils.createEntity(httpResponse),
- httpUriRequest.getURI());
- }
- if (statsRecorder != null) {
- statsRecorder.recordStats(httpResponse);
- }
- return new RibbonApacheHttpResponse(httpResponse, httpUriRequest.getURI());
- };
- LoadBalancedRecoveryCallback recoveryCallback = new LoadBalancedRecoveryCallback() {
- @Override
- protected RibbonApacheHttpResponse createResponse(HttpResponse response,
- URI uri) {
- return new RibbonApacheHttpResponse(response, uri);
- }
- };
- return this.executeWithRetry(request, retryPolicy, retryCallback,
- recoveryCallback);
- }
-
- @Override
- public boolean isClientRetryable(ContextAwareRequest request) {
- return request != null && isRequestRetryable(request);
- }
-
- private boolean isRequestRetryable(ContextAwareRequest request) {
- if (request.getContext() == null || request.getContext().getRetryable() == null) {
- return true;
- }
- return request.getContext().getRetryable();
- }
-
- private RibbonApacheHttpResponse executeWithRetry(RibbonApacheHttpRequest request,
- LoadBalancedRetryPolicy retryPolicy,
- RetryCallback callback,
- RecoveryCallback recoveryCallback)
- throws Exception {
- RetryTemplate retryTemplate = new RetryTemplate();
- boolean retryable = isRequestRetryable(request);
- retryTemplate.setRetryPolicy(retryPolicy == null || !retryable
- ? new NeverRetryPolicy()
- : new RetryPolicy(request, retryPolicy, this, this.getClientName()));
- BackOffPolicy backOffPolicy = loadBalancedRetryFactory
- .createBackOffPolicy(this.getClientName());
- retryTemplate.setBackOffPolicy(
- backOffPolicy == null ? new NoBackOffPolicy() : backOffPolicy);
- RetryListener[] retryListeners = this.loadBalancedRetryFactory
- .createRetryListeners(this.getClientName());
- if (retryListeners != null && retryListeners.length != 0) {
- retryTemplate.setListeners(retryListeners);
- }
- return retryTemplate.execute(callback, recoveryCallback);
- }
-
- @Override
- public RequestSpecificRetryHandler getRequestSpecificRetryHandler(
- RibbonApacheHttpRequest request, IClientConfig requestConfig) {
- return new RequestSpecificRetryHandler(false, false, RetryHandler.DEFAULT, null);
- }
-
- public void setRibbonLoadBalancerContext(
- RibbonLoadBalancerContext ribbonLoadBalancerContext) {
- this.ribbonLoadBalancerContext = ribbonLoadBalancerContext;
- }
-
- static class RetryPolicy extends InterceptorRetryPolicy {
-
- RetryPolicy(HttpRequest request, LoadBalancedRetryPolicy policy,
- ServiceInstanceChooser serviceInstanceChooser, String serviceName) {
- super(request, policy, serviceInstanceChooser, serviceName);
- }
-
- }
-
-}
diff --git a/spring-cloud-netflix-ribbon/src/main/java/org/springframework/cloud/netflix/ribbon/apache/RibbonApacheHttpRequest.java b/spring-cloud-netflix-ribbon/src/main/java/org/springframework/cloud/netflix/ribbon/apache/RibbonApacheHttpRequest.java
deleted file mode 100644
index ac51d6252..000000000
--- a/spring-cloud-netflix-ribbon/src/main/java/org/springframework/cloud/netflix/ribbon/apache/RibbonApacheHttpRequest.java
+++ /dev/null
@@ -1,85 +0,0 @@
-/*
- * Copyright 2013-2019 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * https://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.springframework.cloud.netflix.ribbon.apache;
-
-import java.net.URI;
-import java.util.List;
-
-import org.apache.http.client.config.RequestConfig;
-import org.apache.http.client.methods.HttpUriRequest;
-import org.apache.http.client.methods.RequestBuilder;
-import org.apache.http.entity.BasicHttpEntity;
-
-import org.springframework.cloud.netflix.ribbon.support.ContextAwareRequest;
-import org.springframework.cloud.netflix.ribbon.support.RibbonCommandContext;
-
-import static org.springframework.cloud.netflix.ribbon.support.RibbonRequestCustomizer.Runner.customize;
-
-/**
- * @author Christian Lohmann
- */
-public class RibbonApacheHttpRequest extends ContextAwareRequest implements Cloneable {
-
- public RibbonApacheHttpRequest(RibbonCommandContext context) {
- super(context);
- }
-
- public HttpUriRequest toRequest(final RequestConfig requestConfig) {
- final RequestBuilder builder = RequestBuilder.create(this.context.getMethod());
- builder.setUri(this.uri);
- for (final String name : this.context.getHeaders().keySet()) {
- final List values = this.context.getHeaders().get(name);
- for (final String value : values) {
- builder.addHeader(name, value);
- }
- }
-
- for (final String name : this.context.getParams().keySet()) {
- final List values = this.context.getParams().get(name);
- for (final String value : values) {
- builder.addParameter(name, value);
- }
- }
-
- if (this.context.getRequestEntity() != null) {
- final BasicHttpEntity entity;
- entity = new BasicHttpEntity();
- entity.setContent(this.context.getRequestEntity());
- // if the entity contentLength isn't set, transfer-encoding will be set
- // to chunked in org.apache.http.protocol.RequestContent. See gh-1042
- Long contentLength = this.context.getContentLength();
- if ("GET".equals(this.context.getMethod())
- && (contentLength == null || contentLength < 0)) {
- entity.setContentLength(0);
- }
- else if (contentLength != null) {
- entity.setContentLength(contentLength);
- }
- builder.setEntity(entity);
- }
-
- customize(this.context.getRequestCustomizers(), builder);
-
- builder.setConfig(requestConfig);
- return builder.build();
- }
-
- public RibbonApacheHttpRequest withNewUri(URI uri) {
- return new RibbonApacheHttpRequest(newContext(uri));
- }
-
-}
diff --git a/spring-cloud-netflix-ribbon/src/main/java/org/springframework/cloud/netflix/ribbon/apache/RibbonApacheHttpResponse.java b/spring-cloud-netflix-ribbon/src/main/java/org/springframework/cloud/netflix/ribbon/apache/RibbonApacheHttpResponse.java
deleted file mode 100644
index ac7c10518..000000000
--- a/spring-cloud-netflix-ribbon/src/main/java/org/springframework/cloud/netflix/ribbon/apache/RibbonApacheHttpResponse.java
+++ /dev/null
@@ -1,173 +0,0 @@
-/*
- * Copyright 2013-2019 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * https://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.springframework.cloud.netflix.ribbon.apache;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.lang.reflect.Type;
-import java.net.URI;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import com.google.common.reflect.TypeToken;
-import com.netflix.client.ClientException;
-import com.netflix.client.http.CaseInsensitiveMultiMap;
-import com.netflix.client.http.HttpHeaders;
-import org.apache.http.Header;
-import org.apache.http.HttpResponse;
-
-import org.springframework.http.HttpStatus;
-import org.springframework.util.Assert;
-
-/**
- * @author Christian Lohmann
- */
-public class RibbonApacheHttpResponse implements com.netflix.client.http.HttpResponse {
-
- private HttpResponse httpResponse;
-
- private URI uri;
-
- public RibbonApacheHttpResponse(final HttpResponse httpResponse, final URI uri) {
- Assert.notNull(httpResponse, "httpResponse can not be null");
- this.httpResponse = httpResponse;
- this.uri = uri;
- }
-
- @Override
- public Object getPayload() throws ClientException {
- try {
- if (!hasPayload()) {
- return null;
- }
- return this.httpResponse.getEntity().getContent();
- }
- catch (final IOException e) {
- throw new ClientException(e.getMessage(), e);
- }
- }
-
- @Override
- public boolean hasPayload() {
- return this.httpResponse.getEntity() != null;
- }
-
- @Override
- public boolean isSuccess() {
- return HttpStatus.valueOf(this.httpResponse.getStatusLine().getStatusCode())
- .is2xxSuccessful();
- }
-
- @Override
- public URI getRequestedURI() {
- return this.uri;
- }
-
- public int getStatus() {
- return httpResponse.getStatusLine().getStatusCode();
- }
-
- public String getStatusLine() {
- return httpResponse.getStatusLine().toString();
- }
-
- @Override
- public Map> getHeaders() {
- final Map> headers = new HashMap<>();
- for (final Header header : this.httpResponse.getAllHeaders()) {
- if (headers.containsKey(header.getName())) {
- headers.get(header.getName()).add(header.getValue());
- }
- else {
- final List values = new ArrayList<>();
- values.add(header.getValue());
- headers.put(header.getName(), values);
- }
- }
-
- return headers;
- }
-
- @Override
- public HttpHeaders getHttpHeaders() {
- final CaseInsensitiveMultiMap headers = new CaseInsensitiveMultiMap();
- for (final Header header : httpResponse.getAllHeaders()) {
- headers.addHeader(header.getName(), header.getValue());
- }
-
- return headers;
- }
-
- @Override
- public void close() {
- if (this.httpResponse != null && this.httpResponse.getEntity() != null) {
- try {
- this.httpResponse.getEntity().getContent().close();
- }
- catch (final IOException e) {
- throw new RuntimeException(e.getMessage(), e);
- }
- }
-
- }
-
- @Override
- public InputStream getInputStream() {
- try {
- if (!hasPayload()) {
- return null;
- }
- return this.httpResponse.getEntity().getContent();
- }
- catch (final IOException e) {
- throw new RuntimeException(e.getMessage(), e);
- }
- }
-
- @Override
- public boolean hasEntity() {
- return hasPayload();
- }
-
- /**
- * Not used.
- */
- @Override
- public T getEntity(final Class type) throws Exception {
- return null;
- }
-
- /**
- * Not used.
- */
- @Override
- public T getEntity(final Type type) throws Exception {
- return null;
- }
-
- /**
- * Not used.
- */
- @Override
- public T getEntity(final TypeToken type) throws Exception {
- return null;
- }
-
-}
diff --git a/spring-cloud-netflix-ribbon/src/main/java/org/springframework/cloud/netflix/ribbon/apache/RibbonLoadBalancingHttpClient.java b/spring-cloud-netflix-ribbon/src/main/java/org/springframework/cloud/netflix/ribbon/apache/RibbonLoadBalancingHttpClient.java
deleted file mode 100644
index c13181165..000000000
--- a/spring-cloud-netflix-ribbon/src/main/java/org/springframework/cloud/netflix/ribbon/apache/RibbonLoadBalancingHttpClient.java
+++ /dev/null
@@ -1,111 +0,0 @@
-/*
- * Copyright 2013-2019 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * https://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.springframework.cloud.netflix.ribbon.apache;
-
-import java.net.URI;
-
-import com.netflix.client.RequestSpecificRetryHandler;
-import com.netflix.client.RetryHandler;
-import com.netflix.client.config.IClientConfig;
-import com.netflix.loadbalancer.Server;
-import org.apache.http.HttpResponse;
-import org.apache.http.client.config.RequestConfig;
-import org.apache.http.client.methods.HttpUriRequest;
-import org.apache.http.impl.client.CloseableHttpClient;
-import org.apache.http.impl.client.HttpClientBuilder;
-
-import org.springframework.cloud.netflix.ribbon.RibbonProperties;
-import org.springframework.cloud.netflix.ribbon.ServerIntrospector;
-import org.springframework.cloud.netflix.ribbon.support.AbstractLoadBalancingClient;
-import org.springframework.web.util.UriComponentsBuilder;
-
-import static org.springframework.cloud.netflix.ribbon.RibbonUtils.updateToSecureConnectionIfNeeded;
-
-/**
- * @author Christian Lohmann
- * @author Ryan Baxter
- * @author Tim Ysewyn
- */
-// TODO: rename (ie new class that extends this in Dalston) to
-// ApacheHttpLoadBalancingClient
-public class RibbonLoadBalancingHttpClient extends
- AbstractLoadBalancingClient {
-
- public RibbonLoadBalancingHttpClient(IClientConfig config,
- ServerIntrospector serverIntrospector) {
- super(config, serverIntrospector);
- }
-
- public RibbonLoadBalancingHttpClient(CloseableHttpClient delegate,
- IClientConfig config, ServerIntrospector serverIntrospector) {
- super(delegate, config, serverIntrospector);
- }
-
- protected CloseableHttpClient createDelegate(IClientConfig config) {
- RibbonProperties ribbon = RibbonProperties.from(config);
- return HttpClientBuilder.create()
- // already defaults to 0 in builder, so resetting to 0 won't hurt
- .setMaxConnTotal(ribbon.maxTotalConnections(0))
- // already defaults to 0 in builder, so resetting to 0 won't hurt
- .setMaxConnPerRoute(ribbon.maxConnectionsPerHost(0))
- .disableCookieManagement().useSystemProperties() // for proxy
- .build();
- }
-
- @Override
- public RibbonApacheHttpResponse execute(RibbonApacheHttpRequest request,
- final IClientConfig configOverride) throws Exception {
- IClientConfig config = configOverride != null ? configOverride : this.config;
- RibbonProperties ribbon = RibbonProperties.from(config);
- RequestConfig requestConfig = RequestConfig.custom()
- .setConnectTimeout(ribbon.connectTimeout(this.connectTimeout))
- .setSocketTimeout(ribbon.readTimeout(this.readTimeout))
- .setRedirectsEnabled(ribbon.isFollowRedirects(this.followRedirects))
- .setContentCompressionEnabled(ribbon.isGZipPayload(this.gzipPayload))
- .build();
-
- request = getSecureRequest(request, configOverride);
- final HttpUriRequest httpUriRequest = request.toRequest(requestConfig);
- final HttpResponse httpResponse = this.delegate.execute(httpUriRequest);
- return new RibbonApacheHttpResponse(httpResponse, httpUriRequest.getURI());
- }
-
- @Override
- public URI reconstructURIWithServer(Server server, URI original) {
- URI uri = updateToSecureConnectionIfNeeded(original, this.config,
- this.serverIntrospector, server);
- return super.reconstructURIWithServer(server, uri);
- }
-
- @Override
- public RequestSpecificRetryHandler getRequestSpecificRetryHandler(
- RibbonApacheHttpRequest request, IClientConfig requestConfig) {
- return new RequestSpecificRetryHandler(false, false, RetryHandler.DEFAULT,
- requestConfig);
- }
-
- protected RibbonApacheHttpRequest getSecureRequest(RibbonApacheHttpRequest request,
- IClientConfig configOverride) {
- if (isSecure(configOverride)) {
- final URI secureUri = UriComponentsBuilder.fromUri(request.getUri())
- .scheme("https").build(true).toUri();
- return request.withNewUri(secureUri);
- }
- return request;
- }
-
-}
diff --git a/spring-cloud-netflix-ribbon/src/main/java/org/springframework/cloud/netflix/ribbon/okhttp/OkHttpLoadBalancingClient.java b/spring-cloud-netflix-ribbon/src/main/java/org/springframework/cloud/netflix/ribbon/okhttp/OkHttpLoadBalancingClient.java
deleted file mode 100644
index 784b40e4d..000000000
--- a/spring-cloud-netflix-ribbon/src/main/java/org/springframework/cloud/netflix/ribbon/okhttp/OkHttpLoadBalancingClient.java
+++ /dev/null
@@ -1,96 +0,0 @@
-/*
- * Copyright 2013-2019 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * https://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.springframework.cloud.netflix.ribbon.okhttp;
-
-import java.net.URI;
-import java.util.concurrent.TimeUnit;
-
-import com.netflix.client.config.IClientConfig;
-import com.netflix.loadbalancer.Server;
-import okhttp3.OkHttpClient;
-import okhttp3.Request;
-import okhttp3.Response;
-
-import org.springframework.cloud.netflix.ribbon.RibbonProperties;
-import org.springframework.cloud.netflix.ribbon.ServerIntrospector;
-import org.springframework.cloud.netflix.ribbon.support.AbstractLoadBalancingClient;
-import org.springframework.web.util.UriComponentsBuilder;
-
-import static org.springframework.cloud.netflix.ribbon.RibbonUtils.updateToSecureConnectionIfNeeded;
-
-/**
- * @author Spencer Gibb
- * @author Ryan Baxter
- * @author Tim Ysewyn
- */
-public class OkHttpLoadBalancingClient extends
- AbstractLoadBalancingClient {
-
- public OkHttpLoadBalancingClient(IClientConfig config,
- ServerIntrospector serverIntrospector) {
- super(config, serverIntrospector);
- }
-
- public OkHttpLoadBalancingClient(OkHttpClient delegate, IClientConfig config,
- ServerIntrospector serverIntrospector) {
- super(delegate, config, serverIntrospector);
- }
-
- @Override
- protected OkHttpClient createDelegate(IClientConfig config) {
- return new OkHttpClient();
- }
-
- @Override
- public OkHttpRibbonResponse execute(OkHttpRibbonRequest ribbonRequest,
- final IClientConfig configOverride) throws Exception {
- boolean secure = isSecure(configOverride);
- if (secure) {
- final URI secureUri = UriComponentsBuilder.fromUri(ribbonRequest.getUri())
- .scheme("https").build().toUri();
- ribbonRequest = ribbonRequest.withNewUri(secureUri);
- }
-
- OkHttpClient httpClient = getOkHttpClient(configOverride, secure);
- final Request request = ribbonRequest.toRequest();
- Response response = httpClient.newCall(request).execute();
- return new OkHttpRibbonResponse(response, ribbonRequest.getUri());
- }
-
- OkHttpClient getOkHttpClient(IClientConfig configOverride, boolean secure) {
- IClientConfig config = configOverride != null ? configOverride : this.config;
- RibbonProperties ribbon = RibbonProperties.from(config);
- OkHttpClient.Builder builder = this.delegate.newBuilder()
- .connectTimeout(ribbon.connectTimeout(this.connectTimeout),
- TimeUnit.MILLISECONDS)
- .readTimeout(ribbon.readTimeout(this.readTimeout), TimeUnit.MILLISECONDS)
- .followRedirects(ribbon.isFollowRedirects(this.followRedirects));
- if (secure) {
- builder.followSslRedirects(ribbon.isFollowRedirects(this.followRedirects));
- }
-
- return builder.build();
- }
-
- @Override
- public URI reconstructURIWithServer(Server server, URI original) {
- URI uri = updateToSecureConnectionIfNeeded(original, this.config,
- this.serverIntrospector, server);
- return super.reconstructURIWithServer(server, uri);
- }
-
-}
diff --git a/spring-cloud-netflix-ribbon/src/main/java/org/springframework/cloud/netflix/ribbon/okhttp/OkHttpRibbonConfiguration.java b/spring-cloud-netflix-ribbon/src/main/java/org/springframework/cloud/netflix/ribbon/okhttp/OkHttpRibbonConfiguration.java
deleted file mode 100644
index c67857a65..000000000
--- a/spring-cloud-netflix-ribbon/src/main/java/org/springframework/cloud/netflix/ribbon/okhttp/OkHttpRibbonConfiguration.java
+++ /dev/null
@@ -1,126 +0,0 @@
-/*
- * Copyright 2013-2019 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * https://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.springframework.cloud.netflix.ribbon.okhttp;
-
-import java.util.concurrent.TimeUnit;
-
-import javax.annotation.PreDestroy;
-
-import com.netflix.client.AbstractLoadBalancerAwareClient;
-import com.netflix.client.RetryHandler;
-import com.netflix.client.config.IClientConfig;
-import com.netflix.loadbalancer.ILoadBalancer;
-import com.netflix.servo.monitor.Monitors;
-import okhttp3.ConnectionPool;
-import okhttp3.OkHttpClient;
-
-import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
-import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
-import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingClass;
-import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
-import org.springframework.cloud.client.loadbalancer.LoadBalancedRetryFactory;
-import org.springframework.cloud.commons.httpclient.OkHttpClientConnectionPoolFactory;
-import org.springframework.cloud.commons.httpclient.OkHttpClientFactory;
-import org.springframework.cloud.netflix.ribbon.RibbonClientName;
-import org.springframework.cloud.netflix.ribbon.RibbonLoadBalancerContext;
-import org.springframework.cloud.netflix.ribbon.RibbonProperties;
-import org.springframework.cloud.netflix.ribbon.ServerIntrospector;
-import org.springframework.context.annotation.Bean;
-import org.springframework.context.annotation.Configuration;
-
-/**
- * @author Spencer Gibb
- */
-@Configuration(proxyBeanMethods = false)
-@ConditionalOnProperty("ribbon.okhttp.enabled")
-@ConditionalOnClass(name = "okhttp3.OkHttpClient")
-public class OkHttpRibbonConfiguration {
-
- @RibbonClientName
- private String name = "client";
-
- @Bean
- @ConditionalOnMissingBean(AbstractLoadBalancerAwareClient.class)
- @ConditionalOnClass(name = "org.springframework.retry.support.RetryTemplate")
- public RetryableOkHttpLoadBalancingClient retryableOkHttpLoadBalancingClient(
- IClientConfig config, ServerIntrospector serverIntrospector,
- ILoadBalancer loadBalancer, RetryHandler retryHandler,
- LoadBalancedRetryFactory loadBalancedRetryFactory, OkHttpClient delegate,
- RibbonLoadBalancerContext ribbonLoadBalancerContext) {
- RetryableOkHttpLoadBalancingClient client = new RetryableOkHttpLoadBalancingClient(
- delegate, config, serverIntrospector, loadBalancedRetryFactory);
- client.setLoadBalancer(loadBalancer);
- client.setRetryHandler(retryHandler);
- client.setRibbonLoadBalancerContext(ribbonLoadBalancerContext);
- Monitors.registerObject("Client_" + this.name, client);
- return client;
- }
-
- @Bean
- @ConditionalOnMissingBean(AbstractLoadBalancerAwareClient.class)
- @ConditionalOnMissingClass("org.springframework.retry.support.RetryTemplate")
- public OkHttpLoadBalancingClient okHttpLoadBalancingClient(IClientConfig config,
- ServerIntrospector serverIntrospector, ILoadBalancer loadBalancer,
- RetryHandler retryHandler, OkHttpClient delegate) {
- OkHttpLoadBalancingClient client = new OkHttpLoadBalancingClient(delegate, config,
- serverIntrospector);
- client.setLoadBalancer(loadBalancer);
- client.setRetryHandler(retryHandler);
- Monitors.registerObject("Client_" + this.name, client);
- return client;
- }
-
- @Configuration(proxyBeanMethods = false)
- protected static class OkHttpClientConfiguration {
-
- private OkHttpClient httpClient;
-
- @Bean
- @ConditionalOnMissingBean(ConnectionPool.class)
- public ConnectionPool httpClientConnectionPool(IClientConfig config,
- OkHttpClientConnectionPoolFactory connectionPoolFactory) {
- RibbonProperties ribbon = RibbonProperties.from(config);
- int maxTotalConnections = ribbon.maxTotalConnections();
- long timeToLive = ribbon.poolKeepAliveTime();
- TimeUnit ttlUnit = ribbon.getPoolKeepAliveTimeUnits();
- return connectionPoolFactory.create(maxTotalConnections, timeToLive, ttlUnit);
- }
-
- @Bean
- @ConditionalOnMissingBean(OkHttpClient.class)
- public OkHttpClient client(OkHttpClientFactory httpClientFactory,
- ConnectionPool connectionPool, IClientConfig config) {
- RibbonProperties ribbon = RibbonProperties.from(config);
- this.httpClient = httpClientFactory.createBuilder(false)
- .connectTimeout(ribbon.connectTimeout(), TimeUnit.MILLISECONDS)
- .readTimeout(ribbon.readTimeout(), TimeUnit.MILLISECONDS)
- .followRedirects(ribbon.isFollowRedirects())
- .connectionPool(connectionPool).build();
- return this.httpClient;
- }
-
- @PreDestroy
- public void destroy() {
- if (httpClient != null) {
- httpClient.dispatcher().executorService().shutdown();
- httpClient.connectionPool().evictAll();
- }
- }
-
- }
-
-}
diff --git a/spring-cloud-netflix-ribbon/src/main/java/org/springframework/cloud/netflix/ribbon/okhttp/OkHttpRibbonRequest.java b/spring-cloud-netflix-ribbon/src/main/java/org/springframework/cloud/netflix/ribbon/okhttp/OkHttpRibbonRequest.java
deleted file mode 100644
index 5fcc545e8..000000000
--- a/spring-cloud-netflix-ribbon/src/main/java/org/springframework/cloud/netflix/ribbon/okhttp/OkHttpRibbonRequest.java
+++ /dev/null
@@ -1,138 +0,0 @@
-/*
- * Copyright 2013-2019 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * https://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.springframework.cloud.netflix.ribbon.okhttp;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.URI;
-import java.util.List;
-
-import okhttp3.Headers;
-import okhttp3.HttpUrl;
-import okhttp3.MediaType;
-import okhttp3.Request;
-import okhttp3.RequestBody;
-import okhttp3.internal.http.HttpMethod;
-import okio.BufferedSink;
-import okio.Okio;
-import okio.Source;
-
-import org.springframework.cloud.netflix.ribbon.support.ContextAwareRequest;
-import org.springframework.cloud.netflix.ribbon.support.RibbonCommandContext;
-
-import static org.springframework.cloud.netflix.ribbon.support.RibbonRequestCustomizer.Runner.customize;
-
-/**
- * @author Spencer Gibb
- */
-public class OkHttpRibbonRequest extends ContextAwareRequest implements Cloneable {
-
- public OkHttpRibbonRequest(RibbonCommandContext context) {
- super(context);
- }
-
- public Request toRequest() {
- Headers.Builder headers = new Headers.Builder();
- for (String name : this.context.getHeaders().keySet()) {
- List values = this.context.getHeaders().get(name);
- for (String value : values) {
- headers.add(name, value);
- }
- }
-
- HttpUrl.Builder url = HttpUrl.get(this.uri).newBuilder();
- for (String name : this.context.getParams().keySet()) {
- List values = this.context.getParams().get(name);
- for (String value : values) {
- url.addQueryParameter(name, value);
- }
- }
-
- RequestBody requestBody = null;
-
- if (this.context.getRequestEntity() != null
- && HttpMethod.permitsRequestBody(this.context.getMethod())) {
- MediaType mediaType = null;
- if (headers.get("Content-Type") != null) {
- mediaType = MediaType.parse(headers.get("Content-Type"));
- }
- requestBody = new InputStreamRequestBody(this.context.getRequestEntity(),
- mediaType, this.context.getContentLength());
- }
-
- Request.Builder builder = new Request.Builder().url(url.build())
- .headers(headers.build()).method(this.context.getMethod(), requestBody);
-
- customize(this.context.getRequestCustomizers(), builder);
-
- return builder.build();
- }
-
- public OkHttpRibbonRequest withNewUri(final URI uri) {
- return new OkHttpRibbonRequest(newContext(uri));
- }
-
- static class InputStreamRequestBody extends RequestBody {
-
- private InputStream inputStream;
-
- private MediaType mediaType;
-
- private Long contentLength;
-
- InputStreamRequestBody(InputStream inputStream, MediaType mediaType,
- Long contentLength) {
- this.inputStream = inputStream;
- this.mediaType = mediaType;
- this.contentLength = contentLength;
- }
-
- @Override
- public MediaType contentType() {
- return mediaType;
- }
-
- @Override
- public long contentLength() {
- if (contentLength != null) {
- return contentLength;
- }
- try {
- return inputStream.available();
- }
- catch (IOException e) {
- return 0;
- }
- }
-
- @Override
- public void writeTo(BufferedSink sink) throws IOException {
- Source source = null;
- try {
- source = Okio.source(inputStream);
- sink.writeAll(source);
- }
- finally {
- if (source != null) {
- source.close();
- }
- }
- }
-
- }
-
-}
diff --git a/spring-cloud-netflix-ribbon/src/main/java/org/springframework/cloud/netflix/ribbon/okhttp/OkHttpRibbonResponse.java b/spring-cloud-netflix-ribbon/src/main/java/org/springframework/cloud/netflix/ribbon/okhttp/OkHttpRibbonResponse.java
deleted file mode 100644
index 227fa37a7..000000000
--- a/spring-cloud-netflix-ribbon/src/main/java/org/springframework/cloud/netflix/ribbon/okhttp/OkHttpRibbonResponse.java
+++ /dev/null
@@ -1,155 +0,0 @@
-/*
- * Copyright 2013-2019 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * https://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.springframework.cloud.netflix.ribbon.okhttp;
-
-import java.io.InputStream;
-import java.lang.reflect.Type;
-import java.net.URI;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import com.google.common.reflect.TypeToken;
-import com.netflix.client.ClientException;
-import com.netflix.client.http.CaseInsensitiveMultiMap;
-import com.netflix.client.http.HttpHeaders;
-import okhttp3.Response;
-import okhttp3.ResponseBody;
-
-import org.springframework.util.Assert;
-
-/**
- * @author Spencer Gibb
- */
-public class OkHttpRibbonResponse implements com.netflix.client.http.HttpResponse {
-
- private final ResponseBody body;
-
- private URI uri;
-
- private Response response;
-
- public OkHttpRibbonResponse(Response response, URI uri) {
- Assert.notNull(response, "response can not be null");
- this.response = response;
- this.body = response.body();
- this.uri = uri;
- }
-
- @Override
- public int getStatus() {
- return this.response.code();
- }
-
- @Override
- public String getStatusLine() {
- return this.response.message();
- }
-
- @Override
- public Object getPayload() throws ClientException {
- if (!hasPayload()) {
- return null;
- }
- return this.body.byteStream();
- }
-
- @Override
- public boolean hasPayload() {
- return this.body != null;
- }
-
- @Override
- public boolean isSuccess() {
- return this.response.isSuccessful();
- }
-
- @Override
- public URI getRequestedURI() {
- return this.uri;
- }
-
- @Override
- public Map> getHeaders() {
- final Map