Skip to content

Commit af44b3e

Browse files
committed
Fix delegation in ServerRequest decorators
Closes gh-31955
1 parent 2724c6d commit af44b3e

File tree

2 files changed

+126
-1
lines changed

2 files changed

+126
-1
lines changed

Diff for: spring-webflux/src/main/java/org/springframework/web/reactive/function/server/RequestPredicates.java

+79-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import java.net.InetSocketAddress;
2020
import java.net.URI;
2121
import java.security.Principal;
22+
import java.time.Instant;
2223
import java.util.Arrays;
2324
import java.util.Collections;
2425
import java.util.LinkedHashMap;
@@ -1086,6 +1087,22 @@ public UriBuilder uriBuilder() {
10861087
return this.delegate.uriBuilder();
10871088
}
10881089

1090+
@Override
1091+
public String path() {
1092+
return this.delegate.path();
1093+
}
1094+
1095+
@Override
1096+
@Deprecated
1097+
public PathContainer pathContainer() {
1098+
return this.delegate.pathContainer();
1099+
}
1100+
1101+
@Override
1102+
public RequestPath requestPath() {
1103+
return this.delegate.requestPath();
1104+
}
1105+
10891106
@Override
10901107
public Headers headers() {
10911108
return this.delegate.headers();
@@ -1141,21 +1158,41 @@ public <T> Flux<T> bodyToFlux(ParameterizedTypeReference<T> typeReference) {
11411158
return this.delegate.bodyToFlux(typeReference);
11421159
}
11431160

1161+
@Override
1162+
public <T> Mono<T> bind(Class<T> bindType) {
1163+
return this.delegate.bind(bindType);
1164+
}
1165+
11441166
@Override
11451167
public <T> Mono<T> bind(Class<T> bindType, Consumer<WebDataBinder> dataBinderCustomizer) {
11461168
return this.delegate.bind(bindType, dataBinderCustomizer);
11471169
}
11481170

1171+
@Override
1172+
public Optional<Object> attribute(String name) {
1173+
return this.delegate.attribute(name);
1174+
}
1175+
11491176
@Override
11501177
public Map<String, Object> attributes() {
11511178
return this.delegate.attributes();
11521179
}
11531180

1181+
@Override
1182+
public Optional<String> queryParam(String name) {
1183+
return this.delegate.queryParam(name);
1184+
}
1185+
11541186
@Override
11551187
public MultiValueMap<String, String> queryParams() {
11561188
return this.delegate.queryParams();
11571189
}
11581190

1191+
@Override
1192+
public String pathVariable(String name) {
1193+
return this.delegate.pathVariable(name);
1194+
}
1195+
11591196
@Override
11601197
public Map<String, String> pathVariables() {
11611198
return this.delegate.pathVariables();
@@ -1186,9 +1223,24 @@ public ServerWebExchange exchange() {
11861223
return this.delegate.exchange();
11871224
}
11881225

1226+
@Override
1227+
public Mono<ServerResponse> checkNotModified(Instant lastModified) {
1228+
return this.delegate.checkNotModified(lastModified);
1229+
}
1230+
1231+
@Override
1232+
public Mono<ServerResponse> checkNotModified(String etag) {
1233+
return this.delegate.checkNotModified(etag);
1234+
}
1235+
1236+
@Override
1237+
public Mono<ServerResponse> checkNotModified(Instant lastModified, String etag) {
1238+
return this.delegate.checkNotModified(lastModified, etag);
1239+
}
1240+
11891241
@Override
11901242
public String toString() {
1191-
return this.delegate.toString();
1243+
return String.format("HTTP %s %s", method(), path());
11921244
}
11931245
}
11941246

@@ -1204,12 +1256,27 @@ public ExtendedAttributesServerRequestWrapper(ServerRequest delegate, Map<String
12041256
this.attributes = mergeMaps(delegate.attributes(), newAttributes);
12051257
}
12061258

1259+
@Override
1260+
public Optional<Object> attribute(String name) {
1261+
return Optional.ofNullable(this.attributes.get(name));
1262+
}
12071263

12081264
@Override
12091265
public Map<String, Object> attributes() {
12101266
return this.attributes;
12111267
}
12121268

1269+
@Override
1270+
public String pathVariable(String name) {
1271+
Map<String, String> pathVariables = pathVariables();
1272+
if (pathVariables.containsKey(name)) {
1273+
return pathVariables().get(name);
1274+
}
1275+
else {
1276+
throw new IllegalArgumentException("No path variable with name \"" + name + "\" available");
1277+
}
1278+
}
1279+
12131280
@Override
12141281
@SuppressWarnings("unchecked")
12151282
public Map<String, String> pathVariables() {
@@ -1259,5 +1326,16 @@ private static RequestPath requestPath(RequestPath original, PathPattern.PathRem
12591326
public RequestPath requestPath() {
12601327
return this.requestPath;
12611328
}
1329+
1330+
@Override
1331+
public String path() {
1332+
return this.requestPath.pathWithinApplication().value();
1333+
}
1334+
1335+
@Override
1336+
@Deprecated
1337+
public PathContainer pathContainer() {
1338+
return this.requestPath;
1339+
}
12621340
}
12631341
}

Diff for: spring-webmvc/src/main/java/org/springframework/web/servlet/function/RequestPredicates.java

+47
Original file line numberDiff line numberDiff line change
@@ -1090,6 +1090,12 @@ public String path() {
10901090
return this.delegate.path();
10911091
}
10921092

1093+
@Override
1094+
@Deprecated
1095+
public PathContainer pathContainer() {
1096+
return this.delegate.pathContainer();
1097+
}
1098+
10931099
@Override
10941100
public RequestPath requestPath() {
10951101
return this.delegate.requestPath();
@@ -1135,11 +1141,21 @@ public <T> T bind(Class<T> bindType, Consumer<WebDataBinder> dataBinderCustomize
11351141
return this.delegate.bind(bindType, dataBinderCustomizer);
11361142
}
11371143

1144+
@Override
1145+
public Optional<Object> attribute(String name) {
1146+
return this.delegate.attribute(name);
1147+
}
1148+
11381149
@Override
11391150
public Map<String, Object> attributes() {
11401151
return this.delegate.attributes();
11411152
}
11421153

1154+
@Override
1155+
public Optional<String> param(String name) {
1156+
return this.delegate.param(name);
1157+
}
1158+
11431159
@Override
11441160
public MultiValueMap<String, String> params() {
11451161
return this.delegate.params();
@@ -1150,6 +1166,11 @@ public MultiValueMap<String, Part> multipartData() throws IOException, ServletEx
11501166
return this.delegate.multipartData();
11511167
}
11521168

1169+
@Override
1170+
public String pathVariable(String name) {
1171+
return this.delegate.pathVariable(name);
1172+
}
1173+
11531174
@Override
11541175
public Map<String, String> pathVariables() {
11551176
return this.delegate.pathVariables();
@@ -1203,12 +1224,27 @@ public ExtendedAttributesServerRequestWrapper(ServerRequest delegate, Map<String
12031224
this.attributes = mergeMaps(delegate.attributes(), newAttributes);
12041225
}
12051226

1227+
@Override
1228+
public Optional<Object> attribute(String name) {
1229+
return Optional.ofNullable(this.attributes.get(name));
1230+
}
12061231

12071232
@Override
12081233
public Map<String, Object> attributes() {
12091234
return this.attributes;
12101235
}
12111236

1237+
@Override
1238+
public String pathVariable(String name) {
1239+
Map<String, String> pathVariables = pathVariables();
1240+
if (pathVariables.containsKey(name)) {
1241+
return pathVariables().get(name);
1242+
}
1243+
else {
1244+
throw new IllegalArgumentException("No path variable with name \"" + name + "\" available");
1245+
}
1246+
}
1247+
12121248
@Override
12131249
@SuppressWarnings("unchecked")
12141250
public Map<String, String> pathVariables() {
@@ -1258,5 +1294,16 @@ private static RequestPath requestPath(RequestPath original, PathPattern.PathRem
12581294
public RequestPath requestPath() {
12591295
return this.requestPath;
12601296
}
1297+
1298+
@Override
1299+
public String path() {
1300+
return this.requestPath.pathWithinApplication().value();
1301+
}
1302+
1303+
@Override
1304+
@Deprecated
1305+
public PathContainer pathContainer() {
1306+
return this.requestPath;
1307+
}
12611308
}
12621309
}

0 commit comments

Comments
 (0)