Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/2.2.x'
Browse files Browse the repository at this point in the history
# Conflicts:
#	spring-cloud-openfeign-core/src/main/java/org/springframework/cloud/openfeign/FeignClientFactoryBean.java
#	spring-cloud-openfeign-core/src/main/java/org/springframework/cloud/openfeign/FeignClientProperties.java
#	spring-cloud-openfeign-core/src/main/java/org/springframework/cloud/openfeign/ribbon/FeignLoadBalancer.java
#	spring-cloud-openfeign-core/src/main/java/org/springframework/cloud/openfeign/ribbon/LoadBalancerFeignClient.java
#	spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/FeignClientOverrideDefaultsTests.java
#	spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/FeignClientUsingPropertiesTests.java
#	spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/ribbon/FeignLoadBalancerTests.java
#	spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/ribbon/RetryableFeignLoadBalancerTests.java
  • Loading branch information
OlgaMaciaszek committed Mar 3, 2021
2 parents 4b962e6 + 6b436c4 commit 33f3841
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ public class FeignClientFactoryBean

private int connectTimeoutMillis = new Request.Options().connectTimeoutMillis();

private boolean followRedirects = new Request.Options().isFollowRedirects();

@Override
public void afterPropertiesSet() {
Assert.hasText(contextId, "Context id must be set");
Expand Down Expand Up @@ -182,6 +184,7 @@ protected void configureUsingConfiguration(FeignContext context, Feign.Builder b
builder.options(options);
readTimeoutMillis = options.readTimeoutMillis();
connectTimeoutMillis = options.connectTimeoutMillis();
followRedirects = options.isFollowRedirects();
}
Map<String, RequestInterceptor> requestInterceptors = getInheritedAwareInstances(context,
RequestInterceptor.class);
Expand Down Expand Up @@ -222,9 +225,10 @@ protected void configureUsingProperties(FeignClientProperties.FeignClientConfigu

connectTimeoutMillis = config.getConnectTimeout() != null ? config.getConnectTimeout() : connectTimeoutMillis;
readTimeoutMillis = config.getReadTimeout() != null ? config.getReadTimeout() : readTimeoutMillis;
followRedirects = config.isFollowRedirects() != null ? config.isFollowRedirects() : followRedirects;

builder.options(new Request.Options(connectTimeoutMillis, TimeUnit.MILLISECONDS, readTimeoutMillis,
TimeUnit.MILLISECONDS, true));
TimeUnit.MILLISECONDS, followRedirects));

if (config.getRetryer() != null) {
Retryer retryer = getOrInstantiate(config.getRetryer());
Expand Down Expand Up @@ -495,13 +499,16 @@ public boolean equals(Object o) {
&& Objects.equals(beanFactory, that.beanFactory) && decode404 == that.decode404
&& inheritParentContext == that.inheritParentContext && Objects.equals(fallback, that.fallback)
&& Objects.equals(fallbackFactory, that.fallbackFactory) && Objects.equals(name, that.name)
&& Objects.equals(path, that.path) && Objects.equals(type, that.type) && Objects.equals(url, that.url);
&& Objects.equals(path, that.path) && Objects.equals(type, that.type) && Objects.equals(url, that.url)
&& Objects.equals(connectTimeoutMillis, that.connectTimeoutMillis)
&& Objects.equals(readTimeoutMillis, that.readTimeoutMillis)
&& Objects.equals(followRedirects, that.followRedirects);
}

@Override
public int hashCode() {
return Objects.hash(applicationContext, beanFactory, decode404, inheritParentContext, fallback, fallbackFactory,
name, path, type, url);
name, path, type, url, readTimeoutMillis, connectTimeoutMillis, followRedirects);
}

@Override
Expand All @@ -512,6 +519,8 @@ public String toString() {
.append(inheritParentContext).append(", ").append("applicationContext=").append(applicationContext)
.append(", ").append("beanFactory=").append(beanFactory).append(", ").append("fallback=")
.append(fallback).append(", ").append("fallbackFactory=").append(fallbackFactory).append("}")
.append("connectTimeoutMillis=").append(connectTimeoutMillis).append("}").append("readTimeoutMillis=")
.append(readTimeoutMillis).append("}").append("followRedirects=").append(followRedirects).append("}")
.toString();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2013-2020 the original author or authors.
* Copyright 2013-2021 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.
Expand Down Expand Up @@ -39,6 +39,7 @@
* @author Ilia Ilinykh
* @author Ram Anaswara
* @author Jonatan Ivanov
* @author Olga Maciaszek-Sharma
*/
@ConfigurationProperties("feign.client")
public class FeignClientProperties {
Expand Down Expand Up @@ -140,6 +141,8 @@ public static class FeignClientConfiguration {

private MetricsProperties metrics;

private Boolean followRedirects;

public Logger.Level getLoggerLevel() {
return loggerLevel;
}
Expand Down Expand Up @@ -260,6 +263,14 @@ public void setMetrics(MetricsProperties metrics) {
this.metrics = metrics;
}

public Boolean isFollowRedirects() {
return followRedirects;
}

public void setFollowRedirects(Boolean followRedirects) {
this.followRedirects = followRedirects;
}

@Override
public boolean equals(Object o) {
if (this == o) {
Expand All @@ -278,14 +289,15 @@ public boolean equals(Object o) {
&& Objects.equals(exceptionPropagationPolicy, that.exceptionPropagationPolicy)
&& Objects.equals(defaultRequestHeaders, that.defaultRequestHeaders)
&& Objects.equals(defaultQueryParameters, that.defaultQueryParameters)
&& Objects.equals(capabilities, that.capabilities) && Objects.equals(metrics, that.metrics);
&& Objects.equals(capabilities, that.capabilities) && Objects.equals(metrics, that.metrics)
&& Objects.equals(followRedirects, that.followRedirects);
}

@Override
public int hashCode() {
return Objects.hash(loggerLevel, connectTimeout, readTimeout, retryer, errorDecoder, requestInterceptors,
decode404, encoder, decoder, contract, exceptionPropagationPolicy, defaultQueryParameters,
defaultRequestHeaders, capabilities, metrics);
defaultRequestHeaders, capabilities, metrics, followRedirects);
}

}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2013-2020 the original author or authors.
* Copyright 2013-2021 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.
Expand All @@ -17,6 +17,7 @@
package org.springframework.cloud.openfeign;

import java.util.Map;
import java.util.concurrent.TimeUnit;

import feign.Capability;
import feign.Contract;
Expand Down Expand Up @@ -45,14 +46,14 @@
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.GetMapping;

import static org.assertj.core.api.Assertions.assertThat;

/**
* @author Spencer Gibb
* @author Jonatan Ivanov
* @author Olga Maciaszek-Sharma
*/
@SpringBootTest(classes = FeignClientOverrideDefaultsTests.TestConfiguration.class)
@DirtiesContext
Expand Down Expand Up @@ -121,6 +122,7 @@ void overrideRequestOptions() {
Request.Options options = context.getInstance("bar", Request.Options.class);
assertThat(options.connectTimeoutMillis()).isEqualTo(1);
assertThat(options.readTimeoutMillis()).isEqualTo(1);
assertThat(options.isFollowRedirects()).isFalse();
}

@Test
Expand Down Expand Up @@ -169,7 +171,7 @@ interface FooClient {
@FeignClient(name = "bar", url = "https://bar", configuration = BarConfiguration.class)
interface BarClient {

@RequestMapping(value = "/", method = RequestMethod.GET)
@GetMapping("/")
String get();

}
Expand Down Expand Up @@ -240,7 +242,7 @@ ErrorDecoder feignErrorDecoder() {

@Bean
Request.Options feignRequestOptions() {
return new Request.Options(1, 1);
return new Request.Options(1, TimeUnit.MILLISECONDS, 1, TimeUnit.MILLISECONDS, false);
}

@Bean
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2013-2020 the original author or authors.
* Copyright 2013-2021 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.
Expand Down Expand Up @@ -249,6 +249,20 @@ public void clientShouldContainCapabilities() {
.hasAtLeastOneElementOfType(MicrometerCapability.class);
}

@Test
public void shouldSetFollowRedirects() {
FeignClientFactoryBean testFactoryBean = new FeignClientFactoryBean();
testFactoryBean.setContextId("test");
testFactoryBean.setType(FeignClientFactoryBean.class);
testFactoryBean.setApplicationContext(applicationContext);

TimeoutClient client = testFactoryBean.feign(context).target(TimeoutClient.class, "http://localhost:" + port);

Request.Options options = getRequestOptions((Proxy) client);

assertThat(options.isFollowRedirects()).isFalse();
}

private Request.Options getRequestOptions(Proxy client) {
Object invocationHandlerLambda = ReflectionTestUtils.getField(client, "h");
Object invocationHandler = ReflectionTestUtils.getField(invocationHandlerLambda, "arg$2");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,4 @@ feign.client.config.unwrap.readTimeout=1000
feign.client.config.unwrap.exceptionPropagationPolicy=unwrap
feign.client.config.readTimeout.readTimeout=1000
feign.client.config.connectTimeout.connectTimeout=1000
feign.client.config.default.followRedirects=false

0 comments on commit 33f3841

Please sign in to comment.