Polishing

This commit is contained in:
Juergen Hoeller
2018-01-22 21:34:44 +01:00
parent b47491695e
commit 61579ffe7b
12 changed files with 43 additions and 54 deletions

View File

@@ -190,7 +190,6 @@ public abstract class AbstractGenericWebContextLoader extends AbstractContextLoa
}
else {
ServletContext servletContext = null;
// Find the root WebApplicationContext
while (parent != null) {
if (parent instanceof WebApplicationContext && !(parent.getParent() instanceof WebApplicationContext)) {
@@ -199,7 +198,7 @@ public abstract class AbstractGenericWebContextLoader extends AbstractContextLoa
}
parent = parent.getParent();
}
Assert.state(servletContext != null, "Failed to find Root WebApplicationContext in the context hierarchy");
Assert.state(servletContext != null, "Failed to find root WebApplicationContext in the context hierarchy");
context.setServletContext(servletContext);
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2017 the original author or authors.
* Copyright 2002-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -52,7 +52,7 @@ public interface SyncHandlerMethodArgumentResolver extends HandlerMethodArgument
* @return the resolved value, if any
*/
@Nullable
Object resolveArgumentValue(MethodParameter parameter, BindingContext bindingContext,
ServerWebExchange exchange);
Object resolveArgumentValue(
MethodParameter parameter, BindingContext bindingContext, ServerWebExchange exchange);
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2017 the original author or authors.
* Copyright 2002-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -38,15 +38,14 @@ import org.springframework.web.server.ServerWebExchange;
public abstract class AbstractNamedValueSyncArgumentResolver extends AbstractNamedValueArgumentResolver
implements SyncHandlerMethodArgumentResolver {
/**
* @param factory a bean factory to use for resolving ${...}
* placeholder and #{...} SpEL expressions in default values;
* or {@code null} if default values are not expected to have expressions
* @param registry for checking reactive type wrappers
*/
protected AbstractNamedValueSyncArgumentResolver(@Nullable ConfigurableBeanFactory factory,
ReactiveAdapterRegistry registry) {
protected AbstractNamedValueSyncArgumentResolver(
@Nullable ConfigurableBeanFactory factory, ReactiveAdapterRegistry registry) {
super(factory, registry);
}
@@ -65,8 +64,8 @@ public abstract class AbstractNamedValueSyncArgumentResolver extends AbstractNam
}
@Override
public Object resolveArgumentValue(MethodParameter parameter, BindingContext context,
ServerWebExchange exchange) {
public Object resolveArgumentValue(
MethodParameter parameter, BindingContext context, ServerWebExchange exchange) {
// This won't block since resolveName below doesn't
return resolveArgument(parameter, context, exchange).block();

View File

@@ -40,7 +40,7 @@ import org.springframework.web.server.ServerWebExchange;
/**
* Resolves arguments of type {@link Map} annotated with {@link MatrixVariable @MatrixVariable}
* where the annotation does not specify a name. In other words the purpose of this resolver
* is to provide access to multiple matrix variables, either all or associted with a specific
* is to provide access to multiple matrix variables, either all or associated with a specific
* path variable.
*
* <p>When a name is specified, an argument of type Map is considered to be a single attribute
@@ -53,7 +53,6 @@ import org.springframework.web.server.ServerWebExchange;
public class MatrixVariableMapMethodArgumentResolver extends HandlerMethodArgumentResolverSupport
implements SyncHandlerMethodArgumentResolver {
public MatrixVariableMapMethodArgumentResolver(ReactiveAdapterRegistry registry) {
super(registry);
}
@@ -62,7 +61,7 @@ public class MatrixVariableMapMethodArgumentResolver extends HandlerMethodArgume
@Override
public boolean supportsParameter(MethodParameter parameter) {
return checkAnnotatedParamNoReactiveWrapper(parameter, MatrixVariable.class,
(annot, type) -> (Map.class.isAssignableFrom(type) && !StringUtils.hasText(annot.name())));
(ann, type) -> (Map.class.isAssignableFrom(type) && !StringUtils.hasText(ann.name())));
}
@Nullable
@@ -113,4 +112,4 @@ public class MatrixVariableMapMethodArgumentResolver extends HandlerMethodArgume
return false;
}
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2017 the original author or authors.
* Copyright 2002-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.web.reactive.result.method.annotation;
import java.util.ArrayList;
@@ -48,9 +49,8 @@ import org.springframework.web.server.ServerWebInputException;
*/
public class MatrixVariableMethodArgumentResolver extends AbstractNamedValueSyncArgumentResolver {
protected MatrixVariableMethodArgumentResolver(@Nullable ConfigurableBeanFactory factory,
ReactiveAdapterRegistry registry) {
public MatrixVariableMethodArgumentResolver(
@Nullable ConfigurableBeanFactory factory, ReactiveAdapterRegistry registry) {
super(factory, registry);
}
@@ -59,7 +59,7 @@ public class MatrixVariableMethodArgumentResolver extends AbstractNamedValueSync
@Override
public boolean supportsParameter(MethodParameter parameter) {
return checkAnnotatedParamNoReactiveWrapper(parameter, MatrixVariable.class,
(annot, type) -> !Map.class.isAssignableFrom(type) || StringUtils.hasText(annot.name()));
(ann, type) -> !Map.class.isAssignableFrom(type) || StringUtils.hasText(ann.name()));
}
@@ -73,10 +73,8 @@ public class MatrixVariableMethodArgumentResolver extends AbstractNamedValueSync
@Nullable
@Override
protected Object resolveNamedValue(String name, MethodParameter param, ServerWebExchange exchange) {
Map<String, MultiValueMap<String, String>> pathParameters =
exchange.getAttribute(HandlerMapping.MATRIX_VARIABLES_ATTRIBUTE);
if (CollectionUtils.isEmpty(pathParameters)) {
return null;
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2017 the original author or authors.
* Copyright 2002-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -21,7 +21,6 @@ import java.util.Map;
import org.springframework.core.MethodParameter;
import org.springframework.core.ReactiveAdapterRegistry;
import org.springframework.ui.Model;
import org.springframework.util.Assert;
import org.springframework.web.reactive.BindingContext;
import org.springframework.web.reactive.result.method.HandlerMethodArgumentResolverSupport;
import org.springframework.web.reactive.result.method.SyncHandlerMethodArgumentResolver;
@@ -49,8 +48,8 @@ public class ModelArgumentResolver extends HandlerMethodArgumentResolverSupport
}
@Override
public Object resolveArgumentValue(MethodParameter parameter, BindingContext context,
ServerWebExchange exchange) {
public Object resolveArgumentValue(
MethodParameter parameter, BindingContext context, ServerWebExchange exchange) {
Class<?> type = parameter.getParameterType();
if (Model.class.isAssignableFrom(type)) {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2017 the original author or authors.
* Copyright 2002-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -53,13 +53,13 @@ public class PathVariableMapMethodArgumentResolver extends HandlerMethodArgument
}
private boolean allVariables(PathVariable pathVariable, Class<?> type) {
return Map.class.isAssignableFrom(type) && !StringUtils.hasText(pathVariable.value());
return (Map.class.isAssignableFrom(type) && !StringUtils.hasText(pathVariable.value()));
}
@Override
public Object resolveArgumentValue(MethodParameter methodParameter, BindingContext context,
ServerWebExchange exchange) {
public Object resolveArgumentValue(
MethodParameter methodParameter, BindingContext context, ServerWebExchange exchange) {
String name = HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE;
return exchange.getAttributeOrDefault(name, Collections.emptyMap());

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2017 the original author or authors.
* Copyright 2002-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -60,14 +60,12 @@ public class RequestHeaderMapMethodArgumentResolver extends HandlerMethodArgumen
@Override
public Object resolveArgumentValue(MethodParameter methodParameter,
BindingContext context, ServerWebExchange exchange) {
Class<?> paramType = methodParameter.getParameterType();
boolean isMultiValueMap = MultiValueMap.class.isAssignableFrom(paramType);
public Object resolveArgumentValue(
MethodParameter methodParameter, BindingContext context, ServerWebExchange exchange) {
boolean isMultiValueMap = MultiValueMap.class.isAssignableFrom(methodParameter.getParameterType());
HttpHeaders headers = exchange.getRequest().getHeaders();
return isMultiValueMap ? headers : headers.toSingleValueMap();
return (isMultiValueMap ? headers : headers.toSingleValueMap());
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2017 the original author or authors.
* Copyright 2002-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -47,7 +47,6 @@ import org.springframework.web.server.ServerWebExchange;
public class RequestParamMapMethodArgumentResolver extends HandlerMethodArgumentResolverSupport
implements SyncHandlerMethodArgumentResolver {
public RequestParamMapMethodArgumentResolver(ReactiveAdapterRegistry adapterRegistry) {
super(adapterRegistry);
}
@@ -59,17 +58,17 @@ public class RequestParamMapMethodArgumentResolver extends HandlerMethodArgument
}
private boolean allParams(RequestParam requestParam, Class<?> type) {
return Map.class.isAssignableFrom(type) && !StringUtils.hasText(requestParam.name());
return (Map.class.isAssignableFrom(type) && !StringUtils.hasText(requestParam.name()));
}
@Override
public Object resolveArgumentValue(MethodParameter methodParameter, BindingContext context,
ServerWebExchange exchange) {
public Object resolveArgumentValue(
MethodParameter methodParameter, BindingContext context, ServerWebExchange exchange) {
boolean isMultiValueMap = MultiValueMap.class.isAssignableFrom(methodParameter.getParameterType());
MultiValueMap<String, String> queryParams = exchange.getRequest().getQueryParams();
return isMultiValueMap ? queryParams : queryParams.toSingleValueMap();
return (isMultiValueMap ? queryParams : queryParams.toSingleValueMap());
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2017 the original author or authors.
* Copyright 2002-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -25,7 +25,6 @@ import org.springframework.context.i18n.TimeZoneAwareLocaleContext;
import org.springframework.core.MethodParameter;
import org.springframework.core.ReactiveAdapterRegistry;
import org.springframework.http.HttpMethod;
import org.springframework.http.HttpRequest;
import org.springframework.http.server.reactive.ServerHttpRequest;
import org.springframework.http.server.reactive.ServerHttpResponse;
import org.springframework.lang.Nullable;
@@ -80,8 +79,8 @@ public class ServerWebExchangeArgumentResolver extends HandlerMethodArgumentReso
}
@Override
public Object resolveArgumentValue(MethodParameter methodParameter, BindingContext context,
ServerWebExchange exchange) {
public Object resolveArgumentValue(
MethodParameter methodParameter, BindingContext context, ServerWebExchange exchange) {
Class<?> paramType = methodParameter.getParameterType();
if (ServerWebExchange.class.isAssignableFrom(paramType)) {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2017 the original author or authors.
* Copyright 2002-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.web.reactive.result.method.annotation;
import org.springframework.core.MethodParameter;
@@ -32,7 +33,6 @@ import org.springframework.web.server.ServerWebExchange;
*/
public class SessionStatusMethodArgumentResolver implements SyncHandlerMethodArgumentResolver {
@Override
public boolean supportsParameter(MethodParameter parameter) {
return SessionStatus.class == parameter.getParameterType();
@@ -40,8 +40,8 @@ public class SessionStatusMethodArgumentResolver implements SyncHandlerMethodArg
@Nullable
@Override
public Object resolveArgumentValue(MethodParameter parameter, BindingContext bindingContext,
ServerWebExchange exchange) {
public Object resolveArgumentValue(
MethodParameter parameter, BindingContext bindingContext, ServerWebExchange exchange) {
Assert.isInstanceOf(InitBinderBindingContext.class, bindingContext);
return ((InitBinderBindingContext) bindingContext).getSessionStatus();

View File

@@ -40,7 +40,7 @@ import org.springframework.web.servlet.HandlerMapping;
/**
* Resolves arguments of type {@link Map} annotated with {@link MatrixVariable @MatrixVariable}
* where the annotation does not specify a name. In other words the purpose of this resolver
* is to provide access to multiple matrix variables, either all or associted with a specific
* is to provide access to multiple matrix variables, either all or associated with a specific
* path variable.
*
* <p>When a name is specified, an argument of type Map is considered to be a single attribute
@@ -51,7 +51,6 @@ import org.springframework.web.servlet.HandlerMapping;
*/
public class MatrixVariableMapMethodArgumentResolver implements HandlerMethodArgumentResolver {
@Override
public boolean supportsParameter(MethodParameter parameter) {
MatrixVariable matrixVariable = parameter.getParameterAnnotation(MatrixVariable.class);
@@ -113,4 +112,4 @@ public class MatrixVariableMapMethodArgumentResolver implements HandlerMethodArg
return false;
}
}
}