Polish
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2017 the original author or authors.
|
||||
* Copyright 2012-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.
|
||||
@@ -112,7 +112,7 @@ public final class PropertyMapper {
|
||||
if (this.parent != null) {
|
||||
return this.parent.from(supplier);
|
||||
}
|
||||
return new Source<T>(new CachingSupplier<>(supplier), (Predicate<T>) ALWAYS);
|
||||
return new Source<>(new CachingSupplier<>(supplier), (Predicate<T>) ALWAYS);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -207,7 +207,7 @@ public final class PropertyMapper {
|
||||
}
|
||||
return null;
|
||||
};
|
||||
return new Source<R>(supplier, predicate);
|
||||
return new Source<>(supplier, predicate);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2017 the original author or authors.
|
||||
* Copyright 2012-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.
|
||||
@@ -351,8 +351,8 @@ public class Binder {
|
||||
* @return a {@link Binder} instance
|
||||
*/
|
||||
public static Binder get(Environment environment) {
|
||||
return new Binder(ConfigurationPropertySources
|
||||
.get(environment), new PropertySourcesPlaceholdersResolver(environment));
|
||||
return new Binder(ConfigurationPropertySources.get(environment),
|
||||
new PropertySourcesPlaceholdersResolver(environment));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2017 the original author or authors.
|
||||
* Copyright 2012-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.
|
||||
@@ -51,7 +51,8 @@ class DurationConverter implements GenericConverter {
|
||||
|
||||
private static final Pattern ISO8601 = Pattern.compile("^[\\+\\-]?P.*$");
|
||||
|
||||
private static final Pattern SIMPLE = Pattern.compile("^([\\+\\-]?\\d+)([a-zA-Z]{0,2})$");
|
||||
private static final Pattern SIMPLE = Pattern
|
||||
.compile("^([\\+\\-]?\\d+)([a-zA-Z]{0,2})$");
|
||||
|
||||
private static final Map<String, ChronoUnit> UNITS;
|
||||
|
||||
@@ -90,7 +91,8 @@ class DurationConverter implements GenericConverter {
|
||||
return Duration.parse(source);
|
||||
}
|
||||
Matcher matcher = SIMPLE.matcher(source);
|
||||
Assert.state(matcher.matches(), () -> "'" + source + "' is not a valid duration");
|
||||
Assert.state(matcher.matches(),
|
||||
() -> "'" + source + "' is not a valid duration");
|
||||
long amount = Long.parseLong(matcher.group(1));
|
||||
ChronoUnit unit = getUnit(matcher.group(2), defaultUnit);
|
||||
return Duration.of(amount, unit);
|
||||
|
||||
@@ -26,8 +26,8 @@ import org.springframework.util.Assert;
|
||||
import org.springframework.web.server.ServerWebExchange;
|
||||
|
||||
/**
|
||||
* {@link ApplicationContext} backed {@link ServerWebExchangeMatcher}. Can work directly with the
|
||||
* {@link ApplicationContext}, obtain an existing bean or
|
||||
* {@link ApplicationContext} backed {@link ServerWebExchangeMatcher}. Can work directly
|
||||
* with the {@link ApplicationContext}, obtain an existing bean or
|
||||
* {@link AutowireCapableBeanFactory#createBean(Class, int, boolean) create a new bean}
|
||||
* that is autowired in the usual way.
|
||||
*
|
||||
@@ -38,7 +38,8 @@ import org.springframework.web.server.ServerWebExchange;
|
||||
* @author Madhura Bhave
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public abstract class ApplicationContextServerWebExchangeMatcher<C> implements ServerWebExchangeMatcher {
|
||||
public abstract class ApplicationContextServerWebExchangeMatcher<C>
|
||||
implements ServerWebExchangeMatcher {
|
||||
|
||||
private final Class<? extends C> contextClass;
|
||||
|
||||
@@ -101,4 +102,3 @@ public abstract class ApplicationContextServerWebExchangeMatcher<C> implements S
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -178,8 +178,8 @@ public class JettyReactiveWebServerFactory extends AbstractReactiveWebServerFact
|
||||
JettyHandlerWrappers.createGzipHandlerWrapper(getCompression()));
|
||||
}
|
||||
if (StringUtils.hasText(getServerHeader())) {
|
||||
handler = applyWrapper(handler,
|
||||
JettyHandlerWrappers.createServerHeaderHandlerWrapper(getServerHeader()));
|
||||
handler = applyWrapper(handler, JettyHandlerWrappers
|
||||
.createServerHeaderHandlerWrapper(getServerHeader()));
|
||||
}
|
||||
return handler;
|
||||
}
|
||||
|
||||
@@ -182,8 +182,8 @@ public class JettyServletWebServerFactory extends AbstractServletWebServerFactor
|
||||
JettyHandlerWrappers.createGzipHandlerWrapper(getCompression()));
|
||||
}
|
||||
if (StringUtils.hasText(getServerHeader())) {
|
||||
handler = applyWrapper(handler,
|
||||
JettyHandlerWrappers.createServerHeaderHandlerWrapper(getServerHeader()));
|
||||
handler = applyWrapper(handler, JettyHandlerWrappers
|
||||
.createServerHeaderHandlerWrapper(getServerHeader()));
|
||||
}
|
||||
return handler;
|
||||
}
|
||||
@@ -530,7 +530,6 @@ public class JettyServletWebServerFactory extends AbstractServletWebServerFactor
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static final class LoaderHidingResource extends Resource {
|
||||
|
||||
private final Resource delegate;
|
||||
|
||||
@@ -80,7 +80,6 @@ public class TomcatReactiveWebServerFactory extends AbstractReactiveWebServerFac
|
||||
|
||||
private int backgroundProcessorDelay;
|
||||
|
||||
|
||||
/**
|
||||
* Create a new {@link TomcatServletWebServerFactory} instance.
|
||||
*/
|
||||
@@ -304,8 +303,8 @@ public class TomcatReactiveWebServerFactory extends AbstractReactiveWebServerFac
|
||||
}
|
||||
|
||||
/**
|
||||
* Set {@link LifecycleListener}s that should be applied to the Tomcat {@link Context}.
|
||||
* Calling this method will replace any existing listeners.
|
||||
* Set {@link LifecycleListener}s that should be applied to the Tomcat
|
||||
* {@link Context}. Calling this method will replace any existing listeners.
|
||||
* @param contextLifecycleListeners the listeners to set
|
||||
*/
|
||||
public void setContextLifecycleListeners(
|
||||
|
||||
@@ -42,8 +42,8 @@ import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
* {@link WebServer} that can be used to control a Tomcat web server. Usually this class
|
||||
* should be created using the {@link TomcatReactiveWebServerFactory}
|
||||
* of {@link TomcatServletWebServerFactory}, but not directly.
|
||||
* should be created using the {@link TomcatReactiveWebServerFactory} of
|
||||
* {@link TomcatServletWebServerFactory}, but not directly.
|
||||
*
|
||||
* @author Brian Clozel
|
||||
* @author Kristine Jetzke
|
||||
|
||||
@@ -52,7 +52,8 @@ final class UndertowCompressionConfigurer {
|
||||
* @param httpHandler the HTTP handler to wrap
|
||||
* @return the wrapped HTTP handler if compression is enabled, or the handler itself
|
||||
*/
|
||||
public static HttpHandler configureCompression(Compression compression, HttpHandler httpHandler) {
|
||||
public static HttpHandler configureCompression(Compression compression,
|
||||
HttpHandler httpHandler) {
|
||||
if (compression == null || !compression.getEnabled()) {
|
||||
return httpHandler;
|
||||
}
|
||||
|
||||
@@ -77,7 +77,6 @@ public class UndertowReactiveWebServerFactory extends AbstractReactiveWebServerF
|
||||
|
||||
private boolean useForwardHeaders;
|
||||
|
||||
|
||||
/**
|
||||
* Create a new {@link UndertowReactiveWebServerFactory} instance.
|
||||
*/
|
||||
@@ -94,7 +93,8 @@ public class UndertowReactiveWebServerFactory extends AbstractReactiveWebServerF
|
||||
}
|
||||
|
||||
@Override
|
||||
public WebServer getWebServer(org.springframework.http.server.reactive.HttpHandler httpHandler) {
|
||||
public WebServer getWebServer(
|
||||
org.springframework.http.server.reactive.HttpHandler httpHandler) {
|
||||
Undertow.Builder builder = createBuilder(getPort());
|
||||
HttpHandler handler = createUndertowHandler(httpHandler);
|
||||
builder.setHandler(handler);
|
||||
@@ -127,19 +127,22 @@ public class UndertowReactiveWebServerFactory extends AbstractReactiveWebServerF
|
||||
return builder;
|
||||
}
|
||||
|
||||
private HttpHandler createUndertowHandler(org.springframework.http.server.reactive.HttpHandler httpHandler) {
|
||||
private HttpHandler createUndertowHandler(
|
||||
org.springframework.http.server.reactive.HttpHandler httpHandler) {
|
||||
HttpHandler handler = new UndertowHttpHandlerAdapter(httpHandler);
|
||||
if (this.useForwardHeaders) {
|
||||
handler = Handlers.proxyPeerAddress(handler);
|
||||
}
|
||||
handler = UndertowCompressionConfigurer.configureCompression(getCompression(), handler);
|
||||
handler = UndertowCompressionConfigurer.configureCompression(getCompression(),
|
||||
handler);
|
||||
if (isAccessLogEnabled()) {
|
||||
handler = createAccessLogHandler(handler);
|
||||
}
|
||||
return handler;
|
||||
}
|
||||
|
||||
private AccessLogHandler createAccessLogHandler(io.undertow.server.HttpHandler handler) {
|
||||
private AccessLogHandler createAccessLogHandler(
|
||||
io.undertow.server.HttpHandler handler) {
|
||||
try {
|
||||
createAccessLogDirectoryIfNecessary();
|
||||
String prefix = (this.accessLogPrefix != null ? this.accessLogPrefix
|
||||
@@ -175,8 +178,7 @@ public class UndertowReactiveWebServerFactory extends AbstractReactiveWebServerF
|
||||
new SslBuilderCustomizer(getPort(), getAddress(), getSsl(), getSslStoreProvider())
|
||||
.customize(builder);
|
||||
if (getHttp2() != null) {
|
||||
builder.setServerOption(UndertowOptions.ENABLE_HTTP2,
|
||||
getHttp2().isEnabled());
|
||||
builder.setServerOption(UndertowOptions.ENABLE_HTTP2, getHttp2().isEnabled());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -304,6 +306,7 @@ public class UndertowReactiveWebServerFactory extends AbstractReactiveWebServerF
|
||||
* Undertow {@link io.undertow.Undertow.Builder Builder}.
|
||||
* @param customizers the customizers to add
|
||||
*/
|
||||
@Override
|
||||
public void addBuilderCustomizers(UndertowBuilderCustomizer... customizers) {
|
||||
Assert.notNull(customizers, "Customizers must not be null");
|
||||
this.builderCustomizers.addAll(Arrays.asList(customizers));
|
||||
|
||||
@@ -452,6 +452,7 @@ public class UndertowServletWebServerFactory extends AbstractServletWebServerFac
|
||||
this.ioThreads = ioThreads;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setWorkerThreads(Integer workerThreads) {
|
||||
this.workerThreads = workerThreads;
|
||||
}
|
||||
|
||||
@@ -35,8 +35,9 @@ import org.springframework.util.ReflectionUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
* {@link WebServer} that can be used to control an Undertow web server. Usually this class
|
||||
* should be created using the {@link UndertowReactiveWebServerFactory} and not directly.
|
||||
* {@link WebServer} that can be used to control an Undertow web server. Usually this
|
||||
* class should be created using the {@link UndertowReactiveWebServerFactory} and not
|
||||
* directly.
|
||||
*
|
||||
* @author Ivan Sopov
|
||||
* @author Andy Wilkinson
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2017 the original author or authors.
|
||||
* Copyright 2012-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.
|
||||
@@ -125,8 +125,8 @@ public class AnnotationConfigReactiveWebServerApplicationContext
|
||||
|
||||
/**
|
||||
* Provide a custom {@link BeanNameGenerator} for use with
|
||||
* {@link AnnotatedBeanDefinitionReader} and/or {@link ClassPathBeanDefinitionScanner},
|
||||
* if any.
|
||||
* {@link AnnotatedBeanDefinitionReader} and/or
|
||||
* {@link ClassPathBeanDefinitionScanner}, if any.
|
||||
* <p>
|
||||
* Default is
|
||||
* {@link org.springframework.context.annotation.AnnotationBeanNameGenerator}.
|
||||
|
||||
@@ -58,8 +58,8 @@ public abstract class DynamicRegistrationBean<D extends Registration.Dynamic>
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets if asynchronous operations are supported for this registration. If not specified
|
||||
* defaults to {@code true}.
|
||||
* Sets if asynchronous operations are supported for this registration. If not
|
||||
* specified defaults to {@code true}.
|
||||
* @param asyncSupported if async is supported
|
||||
*/
|
||||
public void setAsyncSupported(boolean asyncSupported) {
|
||||
|
||||
@@ -246,8 +246,8 @@ public class ServletContextInitializerBeans
|
||||
}
|
||||
|
||||
/**
|
||||
* Adapter to convert a given Bean type into a {@link RegistrationBean} (and
|
||||
* hence a {@link ServletContextInitializer}).
|
||||
* Adapter to convert a given Bean type into a {@link RegistrationBean} (and hence a
|
||||
* {@link ServletContextInitializer}).
|
||||
*/
|
||||
private interface RegistrationBeanAdapter<T> {
|
||||
|
||||
|
||||
@@ -123,8 +123,8 @@ public class AnnotationConfigServletWebServerApplicationContext
|
||||
|
||||
/**
|
||||
* Provide a custom {@link BeanNameGenerator} for use with
|
||||
* {@link AnnotatedBeanDefinitionReader} and/or {@link ClassPathBeanDefinitionScanner},
|
||||
* if any.
|
||||
* {@link AnnotatedBeanDefinitionReader} and/or
|
||||
* {@link ClassPathBeanDefinitionScanner}, if any.
|
||||
* <p>
|
||||
* Default is
|
||||
* {@link org.springframework.context.annotation.AnnotationBeanNameGenerator}.
|
||||
@@ -169,6 +169,7 @@ public class AnnotationConfigServletWebServerApplicationContext
|
||||
* @see #scan(String...)
|
||||
* @see #refresh()
|
||||
*/
|
||||
@Override
|
||||
public final void register(Class<?>... annotatedClasses) {
|
||||
Assert.notEmpty(annotatedClasses,
|
||||
"At least one annotated class must be specified");
|
||||
@@ -182,6 +183,7 @@ public class AnnotationConfigServletWebServerApplicationContext
|
||||
* @see #register(Class...)
|
||||
* @see #refresh()
|
||||
*/
|
||||
@Override
|
||||
public final void scan(String... basePackages) {
|
||||
Assert.notEmpty(basePackages, "At least one base package must be specified");
|
||||
this.basePackages = basePackages;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2017 the original author or authors.
|
||||
* Copyright 2012-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.
|
||||
@@ -56,7 +56,8 @@ class SessionStoreDirectory {
|
||||
}
|
||||
|
||||
private void assertDirectory(boolean mkdirs, File dir) {
|
||||
Assert.state(!mkdirs || dir.exists(), () -> "Session dir " + dir + " does not exist");
|
||||
Assert.state(!mkdirs || dir.exists(),
|
||||
() -> "Session dir " + dir + " does not exist");
|
||||
Assert.state(!dir.isFile(), () -> "Session dir " + dir + " points to a file");
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2017 the original author or authors.
|
||||
* Copyright 2012-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.
|
||||
@@ -100,8 +100,7 @@ public class ExitCodeGeneratorsTests {
|
||||
return generator;
|
||||
}
|
||||
|
||||
private ExitCodeExceptionMapper mockMapper(Class<?> exceptionType,
|
||||
int exitCode) {
|
||||
private ExitCodeExceptionMapper mockMapper(Class<?> exceptionType, int exitCode) {
|
||||
return (exception) -> {
|
||||
if (exceptionType.isInstance(exception)) {
|
||||
return exitCode;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2017 the original author or authors.
|
||||
* Copyright 2012-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.
|
||||
@@ -137,7 +137,8 @@ public class DurationConverterTests {
|
||||
private Duration convert(String source, ChronoUnit defaultUnit) {
|
||||
TypeDescriptor targetType = mock(TypeDescriptor.class);
|
||||
DefaultDurationUnit annotation = AnnotationUtils.synthesizeAnnotation(
|
||||
Collections.singletonMap("value", defaultUnit), DefaultDurationUnit.class, null);
|
||||
Collections.singletonMap("value", defaultUnit), DefaultDurationUnit.class,
|
||||
null);
|
||||
given(targetType.getAnnotation(DefaultDurationUnit.class)).willReturn(annotation);
|
||||
return (Duration) this.converter.convert(source, TypeDescriptor.forObject(source),
|
||||
targetType);
|
||||
|
||||
@@ -69,8 +69,8 @@ public class LiquibaseServiceLocatorApplicationListenerTests {
|
||||
SpringApplication application = new SpringApplication(Conf.class);
|
||||
application.setWebApplicationType(WebApplicationType.NONE);
|
||||
DefaultResourceLoader resourceLoader = new DefaultResourceLoader();
|
||||
resourceLoader.setClassLoader(new ClassHidingClassLoader(
|
||||
CustomResolverServiceLocator.class));
|
||||
resourceLoader.setClassLoader(
|
||||
new ClassHidingClassLoader(CustomResolverServiceLocator.class));
|
||||
application.setResourceLoader(resourceLoader);
|
||||
this.context = application.run();
|
||||
Object resolver = getServiceLocator();
|
||||
@@ -94,7 +94,8 @@ public class LiquibaseServiceLocatorApplicationListenerTests {
|
||||
private final List<Class<?>> hiddenClasses;
|
||||
|
||||
private ClassHidingClassLoader(Class<?>... hiddenClasses) {
|
||||
super(new URL[0], LiquibaseServiceLocatorApplicationListenerTests.class.getClassLoader());
|
||||
super(new URL[0], LiquibaseServiceLocatorApplicationListenerTests.class
|
||||
.getClassLoader());
|
||||
this.hiddenClasses = Arrays.asList(hiddenClasses);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2017 the original author or authors.
|
||||
* Copyright 2012-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.
|
||||
@@ -55,34 +55,40 @@ public class ApplicationContextServerWebExchangeMatcherTests {
|
||||
@Test
|
||||
public void matchesWhenContextClassIsApplicationContextShouldProvideContext() {
|
||||
ServerWebExchange exchange = createHttpWebHandlerAdapter();
|
||||
StaticApplicationContext context = (StaticApplicationContext) exchange.getApplicationContext();
|
||||
assertThat(new TestApplicationContextServerWebExchangeMatcher<>(ApplicationContext.class)
|
||||
.callMatchesAndReturnProvidedContext(exchange)).isEqualTo(context);
|
||||
StaticApplicationContext context = (StaticApplicationContext) exchange
|
||||
.getApplicationContext();
|
||||
assertThat(new TestApplicationContextServerWebExchangeMatcher<>(
|
||||
ApplicationContext.class).callMatchesAndReturnProvidedContext(exchange))
|
||||
.isEqualTo(context);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void matchesWhenContextClassIsExistingBeanShouldProvideBean() {
|
||||
ServerWebExchange exchange = createHttpWebHandlerAdapter();
|
||||
StaticApplicationContext context = (StaticApplicationContext) exchange.getApplicationContext();
|
||||
StaticApplicationContext context = (StaticApplicationContext) exchange
|
||||
.getApplicationContext();
|
||||
context.registerSingleton("existingBean", ExistingBean.class);
|
||||
assertThat(new TestApplicationContextServerWebExchangeMatcher<>(ExistingBean.class)
|
||||
.callMatchesAndReturnProvidedContext(exchange))
|
||||
.isEqualTo(context.getBean(ExistingBean.class));
|
||||
assertThat(
|
||||
new TestApplicationContextServerWebExchangeMatcher<>(ExistingBean.class)
|
||||
.callMatchesAndReturnProvidedContext(exchange))
|
||||
.isEqualTo(context.getBean(ExistingBean.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void matchesWhenContextClassIsNewBeanShouldProvideBean() {
|
||||
ServerWebExchange exchange = createHttpWebHandlerAdapter();
|
||||
StaticApplicationContext context = (StaticApplicationContext) exchange.getApplicationContext();
|
||||
StaticApplicationContext context = (StaticApplicationContext) exchange
|
||||
.getApplicationContext();
|
||||
context.registerSingleton("existingBean", ExistingBean.class);
|
||||
assertThat(new TestApplicationContextServerWebExchangeMatcher<>(NewBean.class)
|
||||
.callMatchesAndReturnProvidedContext(exchange).getBean())
|
||||
.isEqualTo(context.getBean(ExistingBean.class));
|
||||
.isEqualTo(context.getBean(ExistingBean.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void matchesWhenContextIsNull() {
|
||||
MockServerWebExchange exchange = MockServerWebExchange.from(MockServerHttpRequest.get("/path").build());
|
||||
MockServerWebExchange exchange = MockServerWebExchange
|
||||
.from(MockServerHttpRequest.get("/path").build());
|
||||
this.thrown.expect(IllegalStateException.class);
|
||||
this.thrown.expectMessage("No WebApplicationContext found.");
|
||||
new TestApplicationContextServerWebExchangeMatcher<>(ExistingBean.class)
|
||||
@@ -91,9 +97,11 @@ public class ApplicationContextServerWebExchangeMatcherTests {
|
||||
|
||||
private ServerWebExchange createHttpWebHandlerAdapter() {
|
||||
StaticApplicationContext context = new StaticApplicationContext();
|
||||
TestHttpWebHandlerAdapter adapter = new TestHttpWebHandlerAdapter(mock(WebHandler.class));
|
||||
TestHttpWebHandlerAdapter adapter = new TestHttpWebHandlerAdapter(
|
||||
mock(WebHandler.class));
|
||||
adapter.setApplicationContext(context);
|
||||
return adapter.createExchange(MockServerHttpRequest.get("/path").build(), new MockServerHttpResponse());
|
||||
return adapter.createExchange(MockServerHttpRequest.get("/path").build(),
|
||||
new MockServerHttpResponse());
|
||||
}
|
||||
|
||||
static class TestHttpWebHandlerAdapter extends HttpWebHandlerAdapter {
|
||||
@@ -103,7 +111,8 @@ public class ApplicationContextServerWebExchangeMatcherTests {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ServerWebExchange createExchange(ServerHttpRequest request, ServerHttpResponse response) {
|
||||
protected ServerWebExchange createExchange(ServerHttpRequest request,
|
||||
ServerHttpResponse response) {
|
||||
return super.createExchange(request, response);
|
||||
}
|
||||
|
||||
@@ -154,4 +163,3 @@ public class ApplicationContextServerWebExchangeMatcherTests {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -149,7 +149,8 @@ public abstract class AbstractReactiveWebServerFactoryTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sslWantsClientAuthenticationSucceedsWithClientCertificate() throws Exception {
|
||||
public void sslWantsClientAuthenticationSucceedsWithClientCertificate()
|
||||
throws Exception {
|
||||
Ssl ssl = new Ssl();
|
||||
ssl.setClientAuth(Ssl.ClientAuth.WANT);
|
||||
ssl.setKeyStore("classpath:test.jks");
|
||||
@@ -159,9 +160,9 @@ public abstract class AbstractReactiveWebServerFactoryTests {
|
||||
testClientAuthSuccess(ssl, buildTrustAllSslWithClientKeyConnector());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void sslWantsClientAuthenticationSucceedsWithoutClientCertificate() throws Exception {
|
||||
public void sslWantsClientAuthenticationSucceedsWithoutClientCertificate()
|
||||
throws Exception {
|
||||
Ssl ssl = new Ssl();
|
||||
ssl.setClientAuth(Ssl.ClientAuth.WANT);
|
||||
ssl.setKeyStore("classpath:test.jks");
|
||||
@@ -171,12 +172,13 @@ public abstract class AbstractReactiveWebServerFactoryTests {
|
||||
testClientAuthSuccess(ssl, buildTrustAllSslConnector());
|
||||
}
|
||||
|
||||
protected ReactorClientHttpConnector buildTrustAllSslWithClientKeyConnector() throws Exception {
|
||||
protected ReactorClientHttpConnector buildTrustAllSslWithClientKeyConnector()
|
||||
throws Exception {
|
||||
KeyStore clientKeyStore = KeyStore.getInstance(KeyStore.getDefaultType());
|
||||
clientKeyStore.load(new FileInputStream(new File("src/test/resources/test.jks")),
|
||||
"secret".toCharArray());
|
||||
KeyManagerFactory clientKeyManagerFactory =
|
||||
KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
|
||||
KeyManagerFactory clientKeyManagerFactory = KeyManagerFactory
|
||||
.getInstance(KeyManagerFactory.getDefaultAlgorithm());
|
||||
clientKeyManagerFactory.init(clientKeyStore, "password".toCharArray());
|
||||
return new ReactorClientHttpConnector(
|
||||
(options) -> options.sslSupport(sslContextBuilder -> {
|
||||
@@ -186,7 +188,8 @@ public abstract class AbstractReactiveWebServerFactoryTests {
|
||||
}));
|
||||
}
|
||||
|
||||
protected void testClientAuthSuccess(Ssl sslConfiguration, ReactorClientHttpConnector clientConnector) {
|
||||
protected void testClientAuthSuccess(Ssl sslConfiguration,
|
||||
ReactorClientHttpConnector clientConnector) {
|
||||
AbstractReactiveWebServerFactory factory = getFactory();
|
||||
factory.setSsl(sslConfiguration);
|
||||
|
||||
@@ -203,7 +206,8 @@ public abstract class AbstractReactiveWebServerFactoryTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sslNeedsClientAuthenticationSucceedsWithClientCertificate() throws Exception {
|
||||
public void sslNeedsClientAuthenticationSucceedsWithClientCertificate()
|
||||
throws Exception {
|
||||
Ssl ssl = new Ssl();
|
||||
ssl.setClientAuth(Ssl.ClientAuth.NEED);
|
||||
ssl.setKeyStore("classpath:test.jks");
|
||||
@@ -214,9 +218,11 @@ public abstract class AbstractReactiveWebServerFactoryTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sslNeedsClientAuthenticationFailsWithoutClientCertificate() throws Exception {
|
||||
public void sslNeedsClientAuthenticationFailsWithoutClientCertificate()
|
||||
throws Exception {
|
||||
// Ignored for Undertow, see https://github.com/reactor/reactor-netty/issues/257
|
||||
Assumptions.assumeThat(getFactory()).isNotInstanceOf(UndertowReactiveWebServerFactory.class);
|
||||
Assumptions.assumeThat(getFactory())
|
||||
.isNotInstanceOf(UndertowReactiveWebServerFactory.class);
|
||||
Ssl ssl = new Ssl();
|
||||
ssl.setClientAuth(Ssl.ClientAuth.NEED);
|
||||
ssl.setKeyStore("classpath:test.jks");
|
||||
@@ -226,7 +232,8 @@ public abstract class AbstractReactiveWebServerFactoryTests {
|
||||
testClientAuthFailure(ssl, buildTrustAllSslConnector());
|
||||
}
|
||||
|
||||
protected void testClientAuthFailure(Ssl sslConfiguration, ReactorClientHttpConnector clientConnector) {
|
||||
protected void testClientAuthFailure(Ssl sslConfiguration,
|
||||
ReactorClientHttpConnector clientConnector) {
|
||||
AbstractReactiveWebServerFactory factory = getFactory();
|
||||
factory.setSsl(sslConfiguration);
|
||||
|
||||
@@ -240,17 +247,17 @@ public abstract class AbstractReactiveWebServerFactoryTests {
|
||||
.body(BodyInserters.fromObject("Hello World")).exchange()
|
||||
.flatMap((response) -> response.bodyToMono(String.class));
|
||||
|
||||
StepVerifier.create(result)
|
||||
.expectError(SSLException.class)
|
||||
StepVerifier.create(result).expectError(SSLException.class)
|
||||
.verify(Duration.ofSeconds(10));
|
||||
}
|
||||
|
||||
protected WebClient.Builder getWebClient() {
|
||||
return getWebClient(options -> {
|
||||
return getWebClient((options) -> {
|
||||
});
|
||||
}
|
||||
|
||||
protected WebClient.Builder getWebClient(Consumer<? super HttpClientOptions.Builder> clientOptions) {
|
||||
protected WebClient.Builder getWebClient(
|
||||
Consumer<? super HttpClientOptions.Builder> clientOptions) {
|
||||
return WebClient.builder()
|
||||
.clientConnector(new ReactorClientHttpConnector(clientOptions))
|
||||
.baseUrl("http://localhost:" + this.webServer.getPort());
|
||||
@@ -259,51 +266,54 @@ public abstract class AbstractReactiveWebServerFactoryTests {
|
||||
@Test
|
||||
public void compressionOfResponseToGetRequest() throws Exception {
|
||||
WebClient client = prepareCompressionTest();
|
||||
ResponseEntity<Void> response = client.get()
|
||||
.exchange().flatMap(res -> res.toEntity(Void.class)).block();
|
||||
ResponseEntity<Void> response = client.get().exchange()
|
||||
.flatMap((res) -> res.toEntity(Void.class)).block();
|
||||
assertResponseIsCompressed(response);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void compressionOfResponseToPostRequest() throws Exception {
|
||||
WebClient client = prepareCompressionTest();
|
||||
ResponseEntity<Void> response = client.post()
|
||||
.exchange().flatMap(res -> res.toEntity(Void.class)).block();
|
||||
ResponseEntity<Void> response = client.post().exchange()
|
||||
.flatMap((res) -> res.toEntity(Void.class)).block();
|
||||
assertResponseIsCompressed(response);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void noCompressionForSmallResponse() throws Exception {
|
||||
Assumptions.assumeThat(getFactory()).isInstanceOf(NettyReactiveWebServerFactory.class);
|
||||
Assumptions.assumeThat(getFactory())
|
||||
.isInstanceOf(NettyReactiveWebServerFactory.class);
|
||||
Compression compression = new Compression();
|
||||
compression.setEnabled(true);
|
||||
compression.setMinResponseSize(3001);
|
||||
WebClient client = prepareCompressionTest(compression);
|
||||
ResponseEntity<Void> response = client.get()
|
||||
.exchange().flatMap(res -> res.toEntity(Void.class)).block();
|
||||
ResponseEntity<Void> response = client.get().exchange()
|
||||
.flatMap((res) -> res.toEntity(Void.class)).block();
|
||||
assertResponseIsNotCompressed(response);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void noCompressionForMimeType() throws Exception {
|
||||
Assumptions.assumeThat(getFactory()).isNotInstanceOf(NettyReactiveWebServerFactory.class);
|
||||
Assumptions.assumeThat(getFactory())
|
||||
.isNotInstanceOf(NettyReactiveWebServerFactory.class);
|
||||
Compression compression = new Compression();
|
||||
compression.setMimeTypes(new String[] {"application/json"});
|
||||
compression.setMimeTypes(new String[] { "application/json" });
|
||||
WebClient client = prepareCompressionTest(compression);
|
||||
ResponseEntity<Void> response = client.get()
|
||||
.exchange().flatMap(res -> res.toEntity(Void.class)).block();
|
||||
ResponseEntity<Void> response = client.get().exchange()
|
||||
.flatMap((res) -> res.toEntity(Void.class)).block();
|
||||
assertResponseIsNotCompressed(response);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void noCompressionForUserAgent() throws Exception {
|
||||
Assumptions.assumeThat(getFactory()).isNotInstanceOf(NettyReactiveWebServerFactory.class);
|
||||
Assumptions.assumeThat(getFactory())
|
||||
.isNotInstanceOf(NettyReactiveWebServerFactory.class);
|
||||
Compression compression = new Compression();
|
||||
compression.setEnabled(true);
|
||||
compression.setExcludedUserAgents(new String[] { "testUserAgent" });
|
||||
WebClient client = prepareCompressionTest(compression);
|
||||
ResponseEntity<Void> response = client.get().header("User-Agent", "testUserAgent")
|
||||
.exchange().flatMap(res -> res.toEntity(Void.class)).block();
|
||||
.exchange().flatMap((res) -> res.toEntity(Void.class)).block();
|
||||
assertResponseIsNotCompressed(response);
|
||||
}
|
||||
|
||||
@@ -313,15 +323,17 @@ public abstract class AbstractReactiveWebServerFactoryTests {
|
||||
return prepareCompressionTest(compression);
|
||||
|
||||
}
|
||||
|
||||
protected WebClient prepareCompressionTest(Compression compression) {
|
||||
AbstractReactiveWebServerFactory factory = getFactory();
|
||||
factory.setCompression(compression);
|
||||
this.webServer = factory.getWebServer(new CharsHandler(3000, MediaType.TEXT_PLAIN));
|
||||
this.webServer = factory
|
||||
.getWebServer(new CharsHandler(3000, MediaType.TEXT_PLAIN));
|
||||
this.webServer.start();
|
||||
return getWebClient(options -> options.compression(true).afterChannelInit(channel -> {
|
||||
channel.pipeline().addBefore(NettyPipeline.HttpDecompressor,
|
||||
"CompressionTest", new CompressionDetectionHandler());
|
||||
})).build();
|
||||
return getWebClient((options) -> options.compression(true)
|
||||
.afterChannelInit((channel) -> channel.pipeline().addBefore(
|
||||
NettyPipeline.HttpDecompressor, "CompressionTest",
|
||||
new CompressionDetectionHandler()))).build();
|
||||
}
|
||||
|
||||
protected void assertResponseIsCompressed(ResponseEntity<Void> response) {
|
||||
@@ -345,7 +357,8 @@ public abstract class AbstractReactiveWebServerFactoryTests {
|
||||
|
||||
}
|
||||
|
||||
protected static class CompressionDetectionHandler extends ChannelInboundHandlerAdapter {
|
||||
protected static class CompressionDetectionHandler
|
||||
extends ChannelInboundHandlerAdapter {
|
||||
|
||||
@Override
|
||||
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
|
||||
|
||||
@@ -1018,7 +1018,7 @@ public abstract class AbstractServletWebServerFactoryTests {
|
||||
factory.getSession().getCookie().setHttpOnly(true);
|
||||
factory.getSession().getCookie().setSecure(true);
|
||||
factory.getSession().getCookie().setMaxAge(Duration.ofMinutes(1));
|
||||
AtomicReference<ServletContext> contextReference = new AtomicReference<ServletContext>();
|
||||
AtomicReference<ServletContext> contextReference = new AtomicReference<>();
|
||||
factory.getWebServer(contextReference::set).start();
|
||||
ServletContext servletContext = contextReference.get();
|
||||
assertThat(servletContext.getEffectiveSessionTrackingModes())
|
||||
|
||||
Reference in New Issue
Block a user