Polishing

This commit is contained in:
Juergen Hoeller
2019-04-26 20:36:21 +02:00
parent 54c1f408ba
commit 0f0da73043
25 changed files with 180 additions and 194 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2019 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.
@@ -76,14 +76,14 @@ class ReactiveTypeHandler {
private static Log logger = LogFactory.getLog(ReactiveTypeHandler.class);
private final ReactiveAdapterRegistry reactiveRegistry;
private final ReactiveAdapterRegistry adapterRegistry;
private final TaskExecutor taskExecutor;
private Boolean taskExecutorWarning;
private final ContentNegotiationManager contentNegotiationManager;
private boolean taskExecutorWarning;
public ReactiveTypeHandler() {
this(ReactiveAdapterRegistry.getSharedInstance(), new SyncTaskExecutor(), new ContentNegotiationManager());
@@ -93,10 +93,12 @@ class ReactiveTypeHandler {
Assert.notNull(registry, "ReactiveAdapterRegistry is required");
Assert.notNull(executor, "TaskExecutor is required");
Assert.notNull(manager, "ContentNegotiationManager is required");
this.reactiveRegistry = registry;
this.adapterRegistry = registry;
this.taskExecutor = executor;
this.taskExecutorWarning = executor instanceof SimpleAsyncTaskExecutor || executor instanceof SyncTaskExecutor;
this.contentNegotiationManager = manager;
this.taskExecutorWarning =
(executor instanceof SimpleAsyncTaskExecutor || executor instanceof SyncTaskExecutor);
}
@@ -104,7 +106,7 @@ class ReactiveTypeHandler {
* Whether the type can be adapted to a Reactive Streams {@link Publisher}.
*/
public boolean isReactiveType(Class<?> type) {
return (this.reactiveRegistry.hasAdapters() && this.reactiveRegistry.getAdapter(type) != null);
return (this.adapterRegistry.hasAdapters() && this.adapterRegistry.getAdapter(type) != null);
}
@@ -119,7 +121,7 @@ class ReactiveTypeHandler {
ModelAndViewContainer mav, NativeWebRequest request) throws Exception {
Assert.notNull(returnValue, "Expected return value");
ReactiveAdapter adapter = this.reactiveRegistry.getAdapter(returnValue.getClass());
ReactiveAdapter adapter = this.adapterRegistry.getAdapter(returnValue.getClass());
Assert.state(adapter != null, () -> "Unexpected return value: " + returnValue);
ResolvableType elementType = ResolvableType.forMethodParameter(returnType).getGeneric();
@@ -317,7 +319,7 @@ class ReactiveTypeHandler {
return;
}
}
if (isTerminated) {
this.done = true;
Throwable ex = this.error;

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2019 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.
@@ -83,17 +83,17 @@ public class ResponseBodyEmitterReturnValueHandler implements HandlerMethodRetur
/**
* Complete constructor with pluggable "reactive" type support.
* @param messageConverters converters to write emitted objects with
* @param reactiveRegistry for reactive return value type support
* @param registry for reactive return value type support
* @param executor for blocking I/O writes of items emitted from reactive types
* @param manager for detecting streaming media types
* @since 5.0
*/
public ResponseBodyEmitterReturnValueHandler(List<HttpMessageConverter<?>> messageConverters,
ReactiveAdapterRegistry reactiveRegistry, TaskExecutor executor, ContentNegotiationManager manager) {
ReactiveAdapterRegistry registry, TaskExecutor executor, ContentNegotiationManager manager) {
Assert.notEmpty(messageConverters, "HttpMessageConverter List must not be empty");
this.messageConverters = messageConverters;
this.reactiveHandler = new ReactiveTypeHandler(reactiveRegistry, executor, manager);
this.reactiveHandler = new ReactiveTypeHandler(registry, executor, manager);
}

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.
@@ -19,7 +19,6 @@ package org.springframework.web.servlet.support;
import java.util.Locale;
import java.util.Map;
import java.util.TimeZone;
import javax.servlet.ServletContext;
import javax.servlet.ServletRequest;
import javax.servlet.http.HttpServletRequest;

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2017 the original author or authors.
* Copyright 2002-2019 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.
@@ -346,7 +346,7 @@ public class RedirectView extends AbstractUrlBasedView implements SmartView {
targetUrl = replaceUriTemplateVariables(targetUrl.toString(), model, variables, enc);
}
if (isPropagateQueryProperties()) {
appendCurrentQueryParams(targetUrl, request);
appendCurrentQueryParams(targetUrl, request);
}
if (this.exposeModelAttributes) {
appendQueryProperties(targetUrl, model, enc);
@@ -368,7 +368,7 @@ public class RedirectView extends AbstractUrlBasedView implements SmartView {
* attributes or URI variables from the current request. Model attributes
* referenced in the URL are removed from the model.
* @param targetUrl the redirect URL
* @param model Map that contains model attributes
* @param model a Map that contains model attributes
* @param currentUriVariables current request URI variables to use
* @param encodingScheme the encoding scheme to use
* @throws UnsupportedEncodingException if string encoding failed
@@ -435,7 +435,7 @@ public class RedirectView extends AbstractUrlBasedView implements SmartView {
* Append query properties to the redirect URL.
* Stringifies, URL-encodes and formats model attributes as query properties.
* @param targetUrl the StringBuilder to append the properties to
* @param model Map that contains model attributes
* @param model a Map that contains model attributes
* @param encodingScheme the encoding scheme to use
* @throws UnsupportedEncodingException if string encoding failed
* @see #queryProperties
@@ -554,8 +554,9 @@ public class RedirectView extends AbstractUrlBasedView implements SmartView {
/**
* Determine whether the given model element value is eligible for exposure.
* <p>The default implementation considers primitives, Strings, Numbers, Dates,
* URIs, URLs and Locale objects as eligible. This can be overridden in subclasses.
* <p>The default implementation considers primitives, strings, numbers, dates,
* URIs, URLs etc as eligible, according to {@link BeanUtils#isSimpleValueType}.
* This can be overridden in subclasses.
* @param value the model element value
* @return whether the element value is eligible
* @see BeanUtils#isSimpleValueType
@@ -572,7 +573,6 @@ public class RedirectView extends AbstractUrlBasedView implements SmartView {
* @return the encoded output String
* @throws UnsupportedEncodingException if thrown by the JDK URLEncoder
* @see java.net.URLEncoder#encode(String, String)
* @see java.net.URLEncoder#encode(String)
*/
protected String urlEncode(String input, String encodingScheme) throws UnsupportedEncodingException {
return URLEncoder.encode(input, encodingScheme);
@@ -602,7 +602,7 @@ public class RedirectView extends AbstractUrlBasedView implements SmartView {
}
/**
* Send a redirect back to the HTTP client
* Send a redirect back to the HTTP client.
* @param request current HTTP request (allows for reacting to request method)
* @param response current HTTP response (for sending response headers)
* @param targetUrl the target URL to redirect to

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2002-2019 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,10 +47,6 @@ public class SimpleWebApplicationContext extends StaticWebApplicationContext {
@Override
public void refresh() throws BeansException {
MutablePropertyValues pvs = new MutablePropertyValues();
pvs.add("commandClass", "org.springframework.tests.sample.beans.TestBean");
pvs.add("formView", "form");
registerSingleton("/locale.do", LocaleChecker.class);
addMessage("test", Locale.ENGLISH, "test message");
@@ -63,7 +59,7 @@ public class SimpleWebApplicationContext extends StaticWebApplicationContext {
registerSingleton("handlerMapping", BeanNameUrlHandlerMapping.class);
registerSingleton("viewResolver", InternalResourceViewResolver.class);
pvs = new MutablePropertyValues();
MutablePropertyValues pvs = new MutablePropertyValues();
pvs.add("location", "org/springframework/web/context/WEB-INF/sessionContext.xml");
registerSingleton("viewResolver2", XmlViewResolver.class, pvs);
@@ -76,6 +72,7 @@ public class SimpleWebApplicationContext extends StaticWebApplicationContext {
@Override
public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
if (!(RequestContextUtils.findWebApplicationContext(request) instanceof SimpleWebApplicationContext)) {
throw new ServletException("Incorrect WebApplicationContext");
}