'Getting the 307 Redirection Response instead of the target-location page content from an enpoint in Spring Boot

So I have a simple endpoint in my Spring Boot App, which just redirects to another website:

@Controller public class FeedbackController {

@GetMapping(path = "/test")
public Mono<ResponseEntity<Void>> method() {
    String redirectUrl = "https://www.google.com";
    return Mono
            .just(ResponseEntity.status(HttpStatus.TEMPORARY_REDIRECT).location(URI.create(redirectUrl)).build());
}

Making a GET request to this endpoint (e.g. in browser or with postman) gives me the page content of google as a response. However for testing purposes I want to make sure that the response is a TEMPORARY_REDIRECT with www.google.com as the Location Header. How can I make a request to this endpoint so that the response is the 307 TEMPORARY_REDIRECT instead of the 200 with page content from the target website?



Solution 1:[1]

First

to test if its working, you could use simple tools like curl :

We add the -L flag to tell curl that we want to know if we are getting redirected

curl -L http://www.....

Go further

Then, you could simply use tools like MockMvc to automate this test See this SO post

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 jacouille