question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

WebFlux application server add server.forward- Headers - Strategy = Framework RouterFunction endpoint 404

See original GitHub issue

There are two services:

account-service, gateway-server

After the account-service has set the ‘server.forward- Headers - Strategy = Framework’ property.routerFunction endpoint start 404

The following interfaces are accessed through the Spring Cloud Gateway

http://localhost:8080/account/hi is 404. The generated by RouterFunction endpoint

http://localhost:8080/account/hello return 200 normal, through RequestMapping annotations

Reproducible Example:

forward-proxy-demo.zip

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:7 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
poutsmacommented, Jul 7, 2020

This is something that needs to be straightened out in WebFlux.fn. I will pick it up for 5.3, since it will be a breaking change for some people.

1reaction
bclozelcommented, Jul 7, 2020

Now that #25279 is solved, I’ve checked again with the sample application.

There is a major mapping difference between Spring WebFlux annotations and RouterFunctions mapping:

  • Annotations remove the context path when mapping, by using the org.springframework.http.server.RequestPath#pathWithinApplication
  • RouterFunction variants always use the full path since org.springframework.web.reactive.function.server.ServerRequest#pathContainer is returning a PathContainer, and not RequestPath (which extends PathContainer). The context path is not removed before mapping.

Debugging through sample applications show that the DefaultServerRequest implementation is using the underlying RequestPath, it’s just not exposing it as is.

@poutsma @rstoyanchev this difference is the only remaining point here; I can see why RouterFunctions could be considered more explicit, and maybe nesting routes should be used instead here in applications. We’re not calling out that difference anywhere in our documentation as far as I understand, maybe because contextPath shouldn’t even be a concept in the functional variant?

I managed to reproduce this with a new test in RequestPredicatesTests:

@Test
public void pathWithContext() {
	URI uri = URI.create("https://localhost/context/path");
	RequestPredicate predicate = RequestPredicates.path("/p*");
	MockServerHttpRequest mockRequest = MockServerHttpRequest.get(uri.toString()).contextPath("/context").build();
	ServerRequest request = new DefaultServerRequest(MockServerWebExchange.from(mockRequest), emptyList());
	assertThat(predicate.test(request)).isTrue();

	mockRequest = MockServerHttpRequest.head("https://example.com").build();
	request = new DefaultServerRequest(MockServerWebExchange.from(mockRequest), Collections.emptyList());
	assertThat(predicate.test(request)).isFalse();
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Return 404 with Spring WebFlux - Baeldung
Learn how to return 404 status code in Spring WebFlux. ... With Spring Boot 2 and the new non-blocking server Netty, we don't...
Read more >
Web on Reactive Stack - Spring
At the programming-model level, Java 8 enabled Spring WebFlux to offer functional web endpoints alongside annotated controllers.
Read more >
Spring Webflux returns 404 ( Not Foud ) - Stack Overflow
The solution: go to application.properties,; remove server.servlet.context-path; and add spring.webflux.base-path.
Read more >
Sending HTTP requests with Spring WebClient - Reflectoring
Let's start simple, with a plain GET request to read some content from a server or API. To get started, you'll first need...
Read more >
springdoc-openapi v2.0.0
For the integration between spring-boot and swagger-ui, add the library ... by setting server.forward-headers-strategy is set to FRAMEWORK.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found