Describe the bug
- spring-cloud-openfeign >=
2.2.3.RELEASE (Hoxton.SR5) - springframework
5.2.12.RELEASE - springboot
2.3.7.RELEASE - io.github.openfeign
10.10.1 - jdk
1.8.0_212
Describe: spring-cloud-openfeign version >= 2.2.3.RELEASE @RequestHeader will repace ',' to ', ' (One more white space), but it's ok in 2.2.2.RELEASE.
Sample
"Wed, 23 Dec 2020 02:34:12 GMT"
was replaced by
"Wed, 23 Dec 2020 02:34:12 GMT"
One more white space!
This causes some APIs authentication to fail!
My POC:
package com.devyy.poc.openfeignmock.controller;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@Slf4j
@RestController
@RequestMapping("/poc")
public class PocController {
@PostMapping
public String poc(@RequestHeader("requestDate") String requestDate) {
log.info("PocController requestDate={}", requestDate);
return requestDate;
}
}
package com.devyy.poc.openfeignmock.feign;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
@FeignClient(name = "feignClient", url = "http://127.0.0.1:8888/")
public interface IFeignClient {
@RequestMapping(value = "/poc", method = RequestMethod.POST)
String testWhiteSpace(@RequestHeader("requestDate") String requestDate);
}
package com.devyy.poc.openfeignmock;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.openfeign.EnableFeignClients;
@EnableFeignClients("com.devyy.poc.openfeignmock.feign")
@SpringBootApplication
public class OpenfeignMockApplication {
public static void main(String[] args) {
SpringApplication.run(OpenfeignMockApplication.class, args);
}
}
pom.xml:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.3.7.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.devyy.poc</groupId>
<artifactId>openfeign-mock</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>openfeign-mock</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>1.8</java.version>
<spring-cloud.version>Hoxton.SR5</spring-cloud.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<excludes>
<exclude>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>
</project>
application.properties:
server.port=8888
My unit test:
package com.devyy.poc.openfeignmock;
import com.devyy.poc.openfeignmock.feign.IFeignClient;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
@Slf4j
@SpringBootTest
class OpenfeignMockApplicationTests {
@Autowired
private IFeignClient feignClient;
@Test
void contextLoads() {
String req = "Wed, 23 Dec 2020 02:34:12 GMT";
String res = feignClient.testWhiteSpace(req);
log.info("testWhiteSpace req={}", req);
log.info("testWhiteSpace res={}", res);
}
}
My logs:
OpenfeignMockApplicationTests logs:
2020-12-23 11:53:16.294 INFO 32812 --- [ main] c.d.p.o.OpenfeignMockApplicationTests : testWhiteSpace req=Wed, 23 Dec 2020 02:34:12 GMT
2020-12-23 11:53:16.297 INFO 32812 --- [ main] c.d.p.o.OpenfeignMockApplicationTests : testWhiteSpace res=Wed, 23 Dec 2020 02:34:12 GMT
PocController logs:
2020-12-23 11:53:16.134 INFO 39676 --- [nio-8888-exec-1] c.d.p.o.controller.PocController : PocController requestDate=Wed, 23 Dec 2020 02:34:12 GMT
Comment From: gdut-yy
I found that the problem was caused by feign.template.HeaderTemplate#expand(Map<String, ?> variables):
@Override
public String expand(Map<String, ?> variables) {
String result = super.expand(variables);
/* remove any trailing commas */
while (result.endsWith(",")) {
result = result.replaceAll(",$", "");
}
/* space all the commas now */
result = result.replaceAll(",", ", ");
return result;
}
I look at the difference between v2.2.2.RELEASE and v2.2.3.RELEASE
git diff v2.2.2.RELEASE v2.2.3.RELEASE
io.github.openfeign was upgraded from 10.7.4 to 10.10.1 in v2.2.3.RELEASE
diff --git a/spring-cloud-openfeign-dependencies/pom.xml b/spring-cloud-openfeign-dependencies/pom.xml
index 47f016ce..412e3091 100644
--- a/spring-cloud-openfeign-dependencies/pom.xml
+++ b/spring-cloud-openfeign-dependencies/pom.xml
@@ -6,16 +6,16 @@
<parent>
<artifactId>spring-cloud-dependencies-parent</artifactId>
<groupId>org.springframework.cloud</groupId>
- <version>2.2.3.RELEASE</version>
+ <version>2.3.0.RELEASE</version>
<relativePath/>
</parent>
<artifactId>spring-cloud-openfeign-dependencies</artifactId>
- <version>2.2.2.RELEASE</version>
+ <version>2.2.3.RELEASE</version>
<packaging>pom</packaging>
<name>spring-cloud-openfeign-dependencies</name>
<description>Spring Cloud OpenFeign Dependencies</description>
<properties>
- <feign.version>10.7.4</feign.version>
+ <feign.version>10.10.1</feign.version>
<feign-form.version>3.8.0</feign-form.version>
</properties>
<dependencyManagement>
is a bug.
Comment From: spencergibb
Please open an issue in the openfeign repository