I was trying out Spring Cloud Gateway (Finchley.M5). Then I built up this simple project based on Springboot 2 (2.0.0.M7):
@RestController
)When asking the service directly, the response arrives as expected:
But when I try to ask for the service through the Gateway, the service receives the request (I printed a message to the console) but the response never get back to the client:
The repo with the project is over here: https://github.com/julianobrasil/spring-gateway-test
[EDIT 1]: So you don't have to clone the above repo to see what is going on with the code, here it is:
@SpringBootApplication
@EnableDiscoveryClient
public class GatewayApplication {
public static void main(String[] args) {
SpringApplication.run(GatewayApplication.class, args);
}
@Bean
public RouteLocator routes(RouteLocatorBuilder builder) {
return builder.routes()
.route(r -> r.path("/service/**")
.rewritePath("/service/(?<path>.*)", "/${path}")
.uri("lb://mySimpleService"))
.build();
}
}
@RestController
public class MyController {
@GetMapping("/test")
Mono<String> getHello() {
System.out.println("I received a connection request");
return Mono.just("Hello, world!");
}
}
[EDIT 2]: Someone on the Spring Cloud team has cloned my repo and tested it. And reported it worked just fine. Apparently, the test was made in a Linux system (I'm running it on a windows 10 machine).
I found out the real problem was a typical windows world problem: antivirus. Kaspersky was bloking the http response. To whom it may concern: