Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
poutsma committed Sep 22, 2021
1 parent af57fec commit 9020efb
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 69 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ protected void bindMultipart(Map<String, List<MultipartFile>> multipartFiles, Mu

@SuppressWarnings("serial")
protected <T> T construct(Constructor<T> ctor, BiFunction<String, Class<?>, Object> values,
@Nullable MethodParameter parameter) throws Exception {
@Nullable MethodParameter parameter) throws BindException {

// A single data class constructor -> resolve constructor arguments from request parameters.
String[] paramNames = BeanUtils.getParameterNames(ctor);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import org.springframework.lang.Nullable;
import org.springframework.util.CollectionUtils;
import org.springframework.util.MultiValueMap;
import org.springframework.validation.BindException;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.server.ServerWebExchange;

Expand Down Expand Up @@ -89,12 +90,12 @@ public Mono<Map<String, Object>> getValuesToBind(ServerWebExchange exchange) {
}

public <T> Mono<T> construct(ServerWebExchange exchange, Constructor<T> ctor, @Nullable MethodParameter parameter) {
return getValuesToBind(exchange).flatMap(bindValues -> {
return getValuesToBind(exchange).handle((bindValues, sink) -> {
try {
return Mono.just(super.construct(ctor, (name, type) -> bindValues.get(name), parameter));
sink.next(super.construct(ctor, (name, type) -> bindValues.get(name), parameter));
}
catch (Exception ex) {
return Mono.error(ex);
catch (BindException ex) {
sink.error(ex);
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

import java.lang.annotation.Annotation;
import java.lang.reflect.Constructor;
import java.util.List;
import java.util.Map;
import java.util.Optional;

Expand All @@ -34,7 +33,6 @@
import org.springframework.http.MediaType;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.StringUtils;
import org.springframework.validation.BindException;
import org.springframework.validation.BindingResult;
import org.springframework.validation.Errors;
Expand All @@ -49,9 +47,6 @@
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
import org.springframework.web.method.support.HandlerMethodReturnValueHandler;
import org.springframework.web.method.support.ModelAndViewContainer;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartRequest;
import org.springframework.web.multipart.support.StandardServletPartUtils;

/**
* Resolve {@code @ModelAttribute} annotated method arguments and handle
Expand Down Expand Up @@ -258,30 +253,6 @@ protected void bindRequestParameters(WebDataBinder binder, NativeWebRequest requ
((WebRequestDataBinder) binder).bind(request);
}

@Nullable
@Deprecated
public Object resolveConstructorArgument(String paramName, Class<?> paramType, NativeWebRequest request)
throws Exception {

MultipartRequest multipartRequest = request.getNativeRequest(MultipartRequest.class);
if (multipartRequest != null) {
List<MultipartFile> files = multipartRequest.getFiles(paramName);
if (!files.isEmpty()) {
return (files.size() == 1 ? files.get(0) : files);
}
}
else if (StringUtils.startsWithIgnoreCase(
request.getHeader(HttpHeaders.CONTENT_TYPE), MediaType.MULTIPART_FORM_DATA_VALUE)) {
HttpServletRequest servletRequest = request.getNativeRequest(HttpServletRequest.class);
if (servletRequest != null && HttpMethod.POST.matches(servletRequest.getMethod())) {
List<Part> parts = StandardServletPartUtils.getParts(servletRequest, paramName);
if (!parts.isEmpty()) {
return (parts.size() == 1 ? parts.get(0) : parts);
}
}
}
return null;
}

/**
* Validate the model attribute if applicable.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,20 +222,6 @@ private Mono<?> createAttribute(String attributeName, Class<?> clazz, BindingCon
return dataBinder.construct(exchange, ctor, null);
}

/**
* Protected method to obtain the values for data binding. By default this
* method delegates to {@link WebExchangeDataBinder#getValuesToBind}.
* @param binder the data binder in use
* @param exchange the current exchange
* @return a map of bind values
* @since 5.3
* @deprecated As of TODO, no longer used.
*/
@Deprecated
public Mono<Map<String, Object>> getValuesToBind(WebExchangeDataBinder binder, ServerWebExchange exchange) {
return binder.getValuesToBind(exchange);
}

private boolean hasErrorsArgument(MethodParameter parameter) {
int i = parameter.getParameterIndex();
Class<?>[] paramTypes = parameter.getExecutable().getParameterTypes();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,25 +168,5 @@ protected void bindRequestParameters(WebDataBinder binder, NativeWebRequest requ
ServletRequestDataBinder servletBinder = (ServletRequestDataBinder) binder;
servletBinder.bind(servletRequest);
}

@Override
@Nullable
@Deprecated
public Object resolveConstructorArgument(String paramName, Class<?> paramType, NativeWebRequest request)
throws Exception {

Object value = super.resolveConstructorArgument(paramName, paramType, request);
if (value != null) {
return value;
}
ServletRequest servletRequest = request.getNativeRequest(ServletRequest.class);
if (servletRequest != null) {
String attr = HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE;
@SuppressWarnings("unchecked")
Map<String, String> uriVars = (Map<String, String>) servletRequest.getAttribute(attr);
return uriVars.get(paramName);
}
return null;
}


}

0 comments on commit 9020efb

Please sign in to comment.