Skip to content

Commit e176c4e

Browse files
committed
Polishing
1 parent 690e219 commit e176c4e

File tree

6 files changed

+16
-15
lines changed

6 files changed

+16
-15
lines changed

spring-messaging/src/main/java/org/springframework/messaging/handler/annotation/support/AbstractNamedValueMethodArgumentResolver.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,6 @@ protected AbstractNamedValueMethodArgumentResolver(ConversionService conversionS
9090

9191
@Override
9292
public Object resolveArgument(MethodParameter parameter, Message<?> message) throws Exception {
93-
9493
NamedValueInfo namedValueInfo = getNamedValueInfo(parameter);
9594
MethodParameter nestedParameter = parameter.nestedIfOptional();
9695

spring-test/src/main/java/org/springframework/mock/web/MockMultipartHttpServletRequest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2019 the original author or authors.
2+
* Copyright 2002-2020 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.
@@ -158,7 +158,7 @@ public HttpHeaders getMultipartHeaders(String paramOrFileName) {
158158
String contentType = getMultipartContentType(paramOrFileName);
159159
if (contentType != null) {
160160
HttpHeaders headers = new HttpHeaders();
161-
headers.add("Content-Type", contentType);
161+
headers.add(HttpHeaders.CONTENT_TYPE, contentType);
162162
return headers;
163163
}
164164
else {

spring-web/src/main/java/org/springframework/web/multipart/support/RequestPartServletServerHttpRequest.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,8 @@ public HttpHeaders getHeaders() {
8484
@Override
8585
public InputStream getBody() throws IOException {
8686
// Prefer Servlet Part resolution to cover file as well as parameter streams
87-
if (this.multipartRequest instanceof StandardMultipartHttpServletRequest) {
87+
boolean servletParts = (this.multipartRequest instanceof StandardMultipartHttpServletRequest);
88+
if (servletParts) {
8889
Part part = retrieveServletPart();
8990
if (part != null) {
9091
return part.getInputStream();
@@ -102,9 +103,11 @@ public InputStream getBody() throws IOException {
102103
}
103104

104105
// Fallback: Servlet Part resolution even if not indicated
105-
Part part = retrieveServletPart();
106-
if (part != null) {
107-
return part.getInputStream();
106+
if (!servletParts) {
107+
Part part = retrieveServletPart();
108+
if (part != null) {
109+
return part.getInputStream();
110+
}
108111
}
109112

110113
throw new IllegalStateException("No body available for request part '" + this.requestPartName + "'");

spring-web/src/test/java/org/springframework/web/multipart/support/RequestPartServletServerHttpRequestTests.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,12 +139,11 @@ public HttpHeaders getMultipartHeaders(String paramOrFileName) {
139139
assertThat(result).isEqualTo(bytes);
140140
}
141141

142-
@Test
142+
@Test // gh-25829
143143
public void getBodyViaRequestPart() throws Exception {
144144
byte[] bytes = "content".getBytes("UTF-8");
145145
MockPart mockPart = new MockPart("part", bytes);
146146
mockPart.getHeaders().setContentType(MediaType.APPLICATION_JSON);
147-
mockRequest.addPart(mockPart);
148147
this.mockRequest.addPart(mockPart);
149148
ServerHttpRequest request = new RequestPartServletServerHttpRequest(this.mockRequest, "part");
150149

spring-web/src/testFixtures/java/org/springframework/web/testfixture/servlet/MockMultipartHttpServletRequest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2019 the original author or authors.
2+
* Copyright 2002-2020 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.
@@ -158,7 +158,7 @@ public HttpHeaders getMultipartHeaders(String paramOrFileName) {
158158
String contentType = getMultipartContentType(paramOrFileName);
159159
if (contentType != null) {
160160
HttpHeaders headers = new HttpHeaders();
161-
headers.add("Content-Type", contentType);
161+
headers.add(HttpHeaders.CONTENT_TYPE, contentType);
162162
return headers;
163163
}
164164
else {

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ public Mono<Object> resolveArgument(
9292
NamedValueInfo namedValueInfo = getNamedValueInfo(parameter);
9393
MethodParameter nestedParameter = parameter.nestedIfOptional();
9494

95-
Object resolvedName = resolveStringValue(namedValueInfo.name);
95+
Object resolvedName = resolveEmbeddedValuesAndExpressions(namedValueInfo.name);
9696
if (resolvedName == null) {
9797
return Mono.error(new IllegalArgumentException(
9898
"Specified name must not resolve to null: [" + namedValueInfo.name + "]"));
@@ -103,7 +103,7 @@ public Mono<Object> resolveArgument(
103103
return resolveName(resolvedName.toString(), nestedParameter, exchange)
104104
.flatMap(arg -> {
105105
if ("".equals(arg) && namedValueInfo.defaultValue != null) {
106-
arg = resolveStringValue(namedValueInfo.defaultValue);
106+
arg = resolveEmbeddedValuesAndExpressions(namedValueInfo.defaultValue);
107107
}
108108
arg = applyConversion(arg, namedValueInfo, parameter, bindingContext, exchange);
109109
handleResolvedValue(arg, namedValueInfo.name, parameter, model, exchange);
@@ -158,7 +158,7 @@ private NamedValueInfo updateNamedValueInfo(MethodParameter parameter, NamedValu
158158
* potentially containing placeholders and expressions.
159159
*/
160160
@Nullable
161-
private Object resolveStringValue(String value) {
161+
private Object resolveEmbeddedValuesAndExpressions(String value) {
162162
if (this.configurableBeanFactory == null || this.expressionContext == null) {
163163
return value;
164164
}
@@ -209,7 +209,7 @@ private Mono<Object> getDefaultValue(NamedValueInfo namedValueInfo, MethodParame
209209
return Mono.fromSupplier(() -> {
210210
Object value = null;
211211
if (namedValueInfo.defaultValue != null) {
212-
value = resolveStringValue(namedValueInfo.defaultValue);
212+
value = resolveEmbeddedValuesAndExpressions(namedValueInfo.defaultValue);
213213
}
214214
else if (namedValueInfo.required && !parameter.isOptional()) {
215215
handleMissingValue(namedValueInfo.name, parameter, exchange);

0 commit comments

Comments
 (0)