Skip to content

Commit ccf6887

Browse files
committed
Merge branch '6.0.x'
2 parents f7367ce + f7d1957 commit ccf6887

File tree

8 files changed

+56
-15
lines changed

8 files changed

+56
-15
lines changed

spring-messaging/src/test/java/org/springframework/messaging/simp/stomp/ReactorNetty2StompBrokerRelayIntegrationTests.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
package org.springframework.messaging.simp.stomp;
1818

19+
import org.junit.jupiter.api.Disabled;
20+
1921
import org.springframework.messaging.tcp.TcpOperations;
2022
import org.springframework.messaging.tcp.reactor.ReactorNetty2TcpClient;
2123

@@ -25,6 +27,7 @@
2527
*
2628
* @author Rossen Stoyanchev
2729
*/
30+
@Disabled("gh-29287 :: Disabled because they fail too frequently")
2831
public class ReactorNetty2StompBrokerRelayIntegrationTests extends AbstractStompBrokerRelayIntegrationTests {
2932

3033
@Override

spring-test/src/test/java/org/springframework/test/web/reactive/server/DefaultControllerSpecTests.java

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2022 the original author or authors.
2+
* Copyright 2002-2023 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -48,15 +48,12 @@ public void controller() {
4848
.exchange()
4949
.expectStatus().isOk()
5050
.expectBody(String.class).isEqualTo("Success");
51-
}
5251

53-
@Test
54-
public void controllerEmptyPath() {
5552
new DefaultControllerSpec(new MyController()).build()
5653
.get().uri("")
5754
.exchange()
5855
.expectStatus().isOk()
59-
.expectBody(String.class).isEqualTo("Success empty path");
56+
.expectBody(String.class).isEqualTo("Success");
6057
}
6158

6259
@Test
@@ -121,19 +118,15 @@ public void uriTemplate() {
121118
}
122119

123120

121+
@SuppressWarnings("unused")
124122
@RestController
125123
private static class MyController {
126124

127-
@GetMapping("/")
125+
@GetMapping
128126
public String handleRootPath() {
129127
return "Success";
130128
}
131129

132-
@GetMapping
133-
public String handleEmptyPath() {
134-
return "Success empty path";
135-
}
136-
137130
@GetMapping("/exception")
138131
public void handleWithError() {
139132
throw new IllegalStateException();

spring-webflux/src/main/java/org/springframework/web/reactive/result/condition/PatternsRequestCondition.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,12 @@ protected String getToStringInfix() {
8989
return " || ";
9090
}
9191

92-
private boolean isEmptyPathMapping() {
93-
return this.patterns == EMPTY_PATH_PATTERN;
92+
/**
93+
* Whether the condition is the "" (empty path) mapping.
94+
* @since 6.0.10
95+
*/
96+
public boolean isEmptyPathMapping() {
97+
return (this.patterns == EMPTY_PATH_PATTERN);
9498
}
9599

96100
/**

spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/RequestMappingHandlerMapping.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2022 the original author or authors.
2+
* Copyright 2002-2023 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -153,6 +153,9 @@ protected RequestMappingInfo getMappingForMethod(Method method, Class<?> handler
153153
if (typeInfo != null) {
154154
info = typeInfo.combine(info);
155155
}
156+
if (info.getPatternsCondition().isEmptyPathMapping()) {
157+
info = info.mutate().paths("", "/").options(this.config).build();
158+
}
156159
for (Map.Entry<String, Predicate<Class<?>>> entry : this.pathPrefixes.entrySet()) {
157160
if (entry.getValue().test(handlerType)) {
158161
String prefix = entry.getKey();

spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/RequestMappingIntegrationTests.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,17 @@ protected ApplicationContext initApplicationContext() {
6161
}
6262

6363

64+
@ParameterizedHttpServerTest // gh-30293
65+
void emptyMapping(HttpServer httpServer) throws Exception {
66+
startServer(httpServer);
67+
68+
String url = "http://localhost:" + this.port;
69+
assertThat(getRestTemplate().getForObject(url, String.class)).isEqualTo("root");
70+
71+
url += "/";
72+
assertThat(getRestTemplate().getForObject(url, String.class)).isEqualTo("root");
73+
}
74+
6475
@ParameterizedHttpServerTest
6576
void httpHead(HttpServer httpServer) throws Exception {
6677
startServer(httpServer);
@@ -106,6 +117,11 @@ static class WebConfig {
106117
@SuppressWarnings("unused")
107118
private static class TestRestController {
108119

120+
@GetMapping
121+
public String get() {
122+
return "root";
123+
}
124+
109125
@GetMapping("/text")
110126
public String textGet() {
111127
return "Foo";

spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/RequestMappingInfo.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,16 @@ public Set<String> getPatternValues() {
255255
pprc.getPatternValues() : ((PatternsRequestCondition) condition).getPatterns());
256256
}
257257

258+
/**
259+
* Whether the request mapping has an empty URL path mapping.
260+
* @since 6.0.10
261+
*/
262+
public boolean isEmptyMapping() {
263+
RequestCondition<?> condition = getActivePatternsCondition();
264+
return (condition instanceof PathPatternsRequestCondition pprc ?
265+
pprc.isEmptyPathMapping() : ((PatternsRequestCondition) condition).isEmptyPathMapping());
266+
}
267+
258268
/**
259269
* Return the HTTP request methods of this {@link RequestMappingInfo};
260270
* or instance with 0 request methods (never {@code null}).

spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/RequestMappingHandlerMapping.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2022 the original author or authors.
2+
* Copyright 2002-2023 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -305,6 +305,9 @@ protected RequestMappingInfo getMappingForMethod(Method method, Class<?> handler
305305
if (typeInfo != null) {
306306
info = typeInfo.combine(info);
307307
}
308+
if (info.isEmptyMapping()) {
309+
info = info.mutate().paths("", "/").options(this.config).build();
310+
}
308311
String prefix = getPathPrefix(handlerType);
309312
if (prefix != null) {
310313
info = RequestMappingInfo.paths(prefix).options(this.config).build().combine(info);

spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/ServletAnnotationControllerHandlerMethodTests.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,16 @@ void emptyValueMapping(boolean usePathPatterns) throws Exception {
193193
request.setServletPath("");
194194
MockHttpServletResponse response = new MockHttpServletResponse();
195195
getServlet().service(request, response);
196+
197+
assertThat(response.getContentAsString()).isEqualTo("test");
198+
199+
// gh-30293
200+
request = new MockHttpServletRequest("GET", "/");
201+
response = new MockHttpServletResponse();
202+
getServlet().service(request, response);
203+
196204
assertThat(response.getContentAsString()).isEqualTo("test");
205+
197206
}
198207

199208
@PathPatternsParameterizedTest

0 commit comments

Comments
 (0)