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.

Spring WebFlux doesn't handle redirect: directives when media type is requested [SPR-15291]

See original GitHub issue

Greg Turnquist opened SPR-15291 and commented

The following code…

@Controller
public class WelcomeController {

    @GetMapping("/")
    @ResponseBody
    public String welcome() {
        return "Hello World";
    }

    @GetMapping("/redir")
    public Mono<String> redir() {
        return Mono.just("redirect:/");
    }
}

generates the following stacktrace…

java.lang.IllegalStateException: Could not resolve view with name 'redirect:/'.
    at org.springframework.web.reactive.result.view.ViewResolutionResultHandler.lambda$resolveViews$5(ViewResolutionResultHandler.java:274)

Affects: 5.0 M5

Issue Links:

  • #19103 Reactive HTTP response based RedirectView

Referenced from: commits https://github.com/spring-projects/spring-framework/commit/226c9f9a73d9468b5c0b1c7dfc35700619e06386, https://github.com/spring-projects/spring-framework/commit/718162b8c428220f4cb9c86092c9c651dec6e71c

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:8

github_iconTop GitHub Comments

2reactions
spring-projects-issuescommented, Jan 11, 2019

Brian Clozel commented

Since you may have multiple file types associated with this endpoint, maybe dealing with the response “manually” is the best choice:

@GetMapping("/image.jpg")
public Mono<Void> redir(ServerWebExchange exchange) {
	ServerHttpResponse response = exchange.getResponse();
	response.setStatusCode(HttpStatus.SEE_OTHER);
	response.getHeaders().add(HttpHeaders.LOCATION, "/");
	return response.setComplete();
}
0reactions
spring-projects-issuescommented, Jan 11, 2019

Rossen Stoyanchev commented

This looks like a bug. Arguably content negotiation should not impact redirects and I recall this being an issue once for Spring MVC (see #13254) and WebFlux should be consistent.

On the Spring MVC side SmartView extends View. I think in WebFlux we can add isRedirect to View as a default method and then it should be easy for ViewResolutionResultHandler to check if a candidate view is a redirect.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Redirection inside reactive Spring Webflux REST controller
Redirecting with Controller MVC good-old approach: import org.springframework.http.
Read more >
A Guide To Spring Redirects - Baeldung
A guide to redirect and forward in Spring MVC, with a focus on the code and implementation of each strategy.
Read more >
Sign users in to your web app using the redirect model | Okta ...
Create the app integration by running: okta apps create web. Copied! · Enter Quickstart when prompted for the app name. · Specify the...
Read more >
SVR1: Implementing automatic redirects on the server side ...
When the browser receives this response, the location bar changes and the browser makes a request with the new URL. Examples. Example 1:...
Read more >
Redirecting HTTP Requests With Zuul in Spring Boot - DZone
Zuul is part of the Spring Cloud Netflix package and allows redirect REST requests to perform various types of filters.
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