|
16 | 16 |
|
17 | 17 | package org.springframework.web.reactive.result.method.annotation; |
18 | 18 |
|
| 19 | +import java.io.IOException; |
| 20 | +import java.net.HttpURLConnection; |
| 21 | +import java.net.Proxy; |
19 | 22 | import java.net.URI; |
| 23 | +import java.net.URL; |
20 | 24 | import java.util.Optional; |
21 | 25 |
|
22 | 26 | import org.junit.Test; |
| 27 | +import reactor.core.publisher.Mono; |
23 | 28 |
|
24 | 29 | import org.springframework.context.ApplicationContext; |
25 | 30 | import org.springframework.context.annotation.AnnotationConfigApplicationContext; |
|
30 | 35 | import org.springframework.http.MediaType; |
31 | 36 | import org.springframework.http.RequestEntity; |
32 | 37 | import org.springframework.http.ResponseEntity; |
| 38 | +import org.springframework.http.client.SimpleClientHttpRequestFactory; |
33 | 39 | import org.springframework.stereotype.Controller; |
34 | 40 | import org.springframework.ui.Model; |
35 | 41 | import org.springframework.web.bind.annotation.GetMapping; |
36 | 42 | import org.springframework.web.bind.annotation.RequestParam; |
| 43 | +import org.springframework.web.client.RestTemplate; |
37 | 44 | import org.springframework.web.reactive.config.ViewResolverRegistry; |
38 | 45 | import org.springframework.web.reactive.config.WebFluxConfigurationSupport; |
39 | 46 | import org.springframework.web.reactive.result.view.freemarker.FreeMarkerConfigurer; |
40 | 47 | import org.springframework.web.server.ServerWebExchange; |
41 | 48 |
|
42 | | -import static org.junit.Assert.*; |
| 49 | +import static org.junit.Assert.assertEquals; |
| 50 | +import static org.junit.Assert.assertNull; |
43 | 51 |
|
44 | 52 | /** |
45 | 53 | * {@code @RequestMapping} integration tests with view resolution scenarios. |
@@ -73,6 +81,25 @@ public void etagCheckWithNotModifiedResponse() throws Exception { |
73 | 81 | assertNull(response.getBody()); |
74 | 82 | } |
75 | 83 |
|
| 84 | + @Test // SPR-15291 |
| 85 | + public void redirect() throws Exception { |
| 86 | + SimpleClientHttpRequestFactory factory = new SimpleClientHttpRequestFactory() { |
| 87 | + |
| 88 | + @Override |
| 89 | + protected void prepareConnection(HttpURLConnection conn, String method) throws IOException { |
| 90 | + super.prepareConnection(conn, method); |
| 91 | + conn.setInstanceFollowRedirects(false); |
| 92 | + } |
| 93 | + }; |
| 94 | + |
| 95 | + URI uri = new URI("http://localhost:" + this.port + "/redirect"); |
| 96 | + RequestEntity<Void> request = RequestEntity.get(uri).accept(MediaType.ALL).build(); |
| 97 | + ResponseEntity<Void> response = new RestTemplate(factory).exchange(request, Void.class); |
| 98 | + |
| 99 | + assertEquals(HttpStatus.SEE_OTHER, response.getStatusCode()); |
| 100 | + assertEquals("/", response.getHeaders().getLocation().toString()); |
| 101 | + } |
| 102 | + |
76 | 103 |
|
77 | 104 | @Configuration |
78 | 105 | @ComponentScan(resourcePattern = "**/RequestMappingViewResolutionIntegrationTests$*.class") |
@@ -108,6 +135,11 @@ public String getHtmlPage(@RequestParam Optional<String> name, Model model, |
108 | 135 | model.addAttribute("hello", "Hello: " + name.orElse("<no name>") + "!"); |
109 | 136 | return "test"; |
110 | 137 | } |
| 138 | + |
| 139 | + @GetMapping("/redirect") |
| 140 | + public Mono<String> redirect() { |
| 141 | + return Mono.just("redirect:/"); |
| 142 | + } |
111 | 143 | } |
112 | 144 |
|
113 | 145 | } |
0 commit comments