This commit is contained in:
Phillip Webb 2017-05-15 17:16:03 -07:00
parent 226db4697f
commit 302f038e84
27 changed files with 91 additions and 80 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright 2012-2016 the original author or authors.
* Copyright 2012-2017 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.

View File

@ -1,5 +1,5 @@
/*
* Copyright 2012-2016 the original author or authors.
* Copyright 2012-2017 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.

View File

@ -798,8 +798,7 @@ public class KafkaProperties {
/**
* Control flag for login configuration.
*/
private KafkaJaasLoginModuleInitializer.ControlFlag controlFlag =
KafkaJaasLoginModuleInitializer.ControlFlag.REQUIRED;
private KafkaJaasLoginModuleInitializer.ControlFlag controlFlag = KafkaJaasLoginModuleInitializer.ControlFlag.REQUIRED;
/**
* Additional JAAS options.
@ -826,7 +825,8 @@ public class KafkaProperties {
return this.controlFlag;
}
public void setControlFlag(KafkaJaasLoginModuleInitializer.ControlFlag controlFlag) {
public void setControlFlag(
KafkaJaasLoginModuleInitializer.ControlFlag controlFlag) {
this.controlFlag = controlFlag;
}

View File

@ -254,7 +254,7 @@ public class ThymeleafAutoConfiguration {
ThymeleafReactiveViewResolver resolver = new ThymeleafReactiveViewResolver();
resolver.setTemplateEngine(templateEngine);
resolver.setDefaultCharset(this.properties.getEncoding());
final List<MediaType> mediaTypes = this.properties.getReactive().getMediaTypes();
List<MediaType> mediaTypes = this.properties.getReactive().getMediaTypes();
if (mediaTypes != null) {
resolver.setSupportedMediaTypes(mediaTypes);
}

View File

@ -69,7 +69,8 @@ public class HttpHandlerAutoConfiguration {
@Bean
public HttpHandler httpHandler() {
return WebHttpHandlerBuilder.applicationContext(this.applicationContext).build();
return WebHttpHandlerBuilder.applicationContext(this.applicationContext)
.build();
}
}
@ -87,9 +88,9 @@ public class HttpHandlerAutoConfiguration {
private final List<ViewResolver> viewResolvers;
public FunctionalConfig(ObjectProvider<List<WebFilter>> webFilters,
ObjectProvider<WebSessionManager> webSessionManager,
ObjectProvider<HandlerStrategies.Builder> handlerStrategiesBuilder,
ObjectProvider<List<ViewResolver>> viewResolvers) {
ObjectProvider<WebSessionManager> webSessionManager,
ObjectProvider<HandlerStrategies.Builder> handlerStrategiesBuilder,
ObjectProvider<List<ViewResolver>> viewResolvers) {
this.webFilters = webFilters.getIfAvailable();
if (this.webFilters != null) {
AnnotationAwareOrderComparator.sort(this.webFilters);
@ -103,7 +104,7 @@ public class HttpHandlerAutoConfiguration {
public HttpHandler httpHandler(List<RouterFunction<?>> routerFunctions) {
routerFunctions.sort(new AnnotationAwareOrderComparator());
RouterFunction<?> routerFunction = routerFunctions.stream()
.reduce(RouterFunction::andOther).get();
.reduce(RouterFunction::andOther).get();
if (this.handlerStrategiesBuilder == null) {
this.handlerStrategiesBuilder = HandlerStrategies.builder();
}
@ -111,9 +112,9 @@ public class HttpHandlerAutoConfiguration {
this.viewResolvers.forEach(this.handlerStrategiesBuilder::viewResolver);
}
WebHandler webHandler = RouterFunctions.toHttpHandler(routerFunction,
this.handlerStrategiesBuilder.build());
this.handlerStrategiesBuilder.build());
WebHttpHandlerBuilder builder = WebHttpHandlerBuilder.webHandler(webHandler)
.sessionManager(this.webSessionManager);
.sessionManager(this.webSessionManager);
builder.filters(this.webFilters);
return builder.build();
}

View File

@ -31,13 +31,14 @@ import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
* Auto configuration for WebSocket reactive server in Tomcat, Jetty or Undertow.
* Requires the appropriate WebSocket modules to be on the classpath.
* Auto configuration for WebSocket reactive server in Tomcat, Jetty or Undertow. Requires
* the appropriate WebSocket modules to be on the classpath.
* <p>
* If Tomcat's WebSocket support is detected on the classpath we add a customizer that
* installs the Tomcat WebSocket initializer.
*
* @author Brian Clozel
* @since 2.0.0
*/
@Configuration
@ConditionalOnClass({ Servlet.class, ServerContainer.class })

View File

@ -18,7 +18,6 @@ package org.springframework.boot.autoconfigure.websocket.servlet;
import org.apache.tomcat.websocket.server.WsContextListener;
import org.springframework.boot.web.embedded.tomcat.TomcatContextCustomizer;
import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory;
import org.springframework.boot.web.server.WebServerFactoryCustomizer;
import org.springframework.core.Ordered;
@ -36,8 +35,8 @@ public class TomcatWebSocketServletWebServerCustomizer
@Override
public void customize(TomcatServletWebServerFactory factory) {
factory.addContextCustomizers((TomcatContextCustomizer) context ->
context.addApplicationListener(WsContextListener.class.getName()));
factory.addContextCustomizers((context) -> context
.addApplicationListener(WsContextListener.class.getName()));
}
@Override

View File

@ -46,24 +46,23 @@ public class DataSourceBuilderTests {
@Test
public void defaultToHikari() {
this.dataSource = DataSourceBuilder.create()
.url("jdbc:h2:test").build();
this.dataSource = DataSourceBuilder.create().url("jdbc:h2:test").build();
assertThat(this.dataSource).isInstanceOf(HikariDataSource.class);
}
@Test
public void defaultToTomcatIfHikariIsNotAvailable() {
this.dataSource = DataSourceBuilder.create(
new HidePackagesClassLoader("com.zaxxer.hikari"))
this.dataSource = DataSourceBuilder
.create(new HidePackagesClassLoader("com.zaxxer.hikari"))
.url("jdbc:h2:test").build();
assertThat(this.dataSource).isInstanceOf(
org.apache.tomcat.jdbc.pool.DataSource.class);
assertThat(this.dataSource)
.isInstanceOf(org.apache.tomcat.jdbc.pool.DataSource.class);
}
@Test
public void defaultToCommonsDbcp2AsLastResort() {
this.dataSource = DataSourceBuilder.create(
new HidePackagesClassLoader("com.zaxxer.hikari",
this.dataSource = DataSourceBuilder
.create(new HidePackagesClassLoader("com.zaxxer.hikari",
"org.apache.tomcat.jdbc.pool"))
.url("jdbc:h2:test").build();
assertThat(this.dataSource).isInstanceOf(BasicDataSource.class);

View File

@ -176,8 +176,7 @@ public class KafkaAutoConfigurationTests {
"spring.kafka.listener.ack-time=456",
"spring.kafka.listener.concurrency=3",
"spring.kafka.listener.poll-timeout=2000",
"spring.kafka.jaas.enabled=true",
"spring.kafka.jaas.login-module=foo",
"spring.kafka.jaas.enabled=true", "spring.kafka.jaas.login-module=foo",
"spring.kafka.jaas.control-flag=REQUISITE",
"spring.kafka.jaas.options.useKeyTab=true");
DefaultKafkaProducerFactory<?, ?> producerFactory = this.context
@ -201,8 +200,8 @@ public class KafkaAutoConfigurationTests {
.isEqualTo(2000L);
assertThat(this.context.getBeansOfType(KafkaJaasLoginModuleInitializer.class))
.hasSize(1);
KafkaJaasLoginModuleInitializer jaas = this.context.getBean(
KafkaJaasLoginModuleInitializer.class);
KafkaJaasLoginModuleInitializer jaas = this.context
.getBean(KafkaJaasLoginModuleInitializer.class);
dfa = new DirectFieldAccessor(jaas);
assertThat(dfa.getPropertyValue("loginModule")).isEqualTo("foo");
assertThat(dfa.getPropertyValue("controlFlag"))

View File

@ -1,5 +1,5 @@
/*
* Copyright 2012-2013 the original author or authors.
* Copyright 2012-2017 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.

View File

@ -1,5 +1,5 @@
/*
* Copyright 2012-2013 the original author or authors.
* Copyright 2012-2017 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.

View File

@ -1,5 +1,5 @@
/*
* Copyright 2012-2013 the original author or authors.
* Copyright 2012-2017 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.

View File

@ -1,5 +1,5 @@
/*
* Copyright 2012-2015 the original author or authors.
* Copyright 2012-2017 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.

View File

@ -1,5 +1,5 @@
/*
* Copyright 2012-2015 the original author or authors.
* Copyright 2012-2017 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.

View File

@ -1,5 +1,5 @@
/*
* Copyright 2012-2015 the original author or authors.
* Copyright 2012-2017 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.

View File

@ -1,5 +1,5 @@
/*
* Copyright 2012-2014 the original author or authors.
* Copyright 2012-2017 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.

View File

@ -1,5 +1,5 @@
/*
* Copyright 2012-2014 the original author or authors.
* Copyright 2012-2017 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.

View File

@ -349,8 +349,8 @@ public class ConfigurationMetadataAnnotationProcessor extends AbstractProcessor
}
private Element getTopLevelType(Element element) {
if ((element.getEnclosingElement() == null) ||
!(element.getEnclosingElement() instanceof TypeElement)) {
if ((element.getEnclosingElement() == null)
|| !(element.getEnclosingElement() instanceof TypeElement)) {
return element;
}
return getTopLevelType(element.getEnclosingElement());

View File

@ -179,8 +179,8 @@ class TypeElementMembers {
return candidate;
}
TypeMirror alternative = this.typeUtils.getWrapperOrPrimitiveFor(type);
if (alternative != null &&
this.env.getTypeUtils().isSameType(returnType, alternative)) {
if (alternative != null
&& this.env.getTypeUtils().isSameType(returnType, alternative)) {
return candidate;
}
}

View File

@ -159,14 +159,16 @@ public final class ItemMetadata implements Comparable<ItemMetadata> {
return false;
}
ItemMetadata other = (ItemMetadata) o;
return nullSafeEquals(this.itemType, other.itemType)
&& nullSafeEquals(this.name, other.name)
&& nullSafeEquals(this.type, other.type)
&& nullSafeEquals(this.description, other.description)
&& nullSafeEquals(this.sourceType, other.sourceType)
&& nullSafeEquals(this.sourceMethod, other.sourceMethod)
&& nullSafeEquals(this.defaultValue, other.defaultValue)
&& nullSafeEquals(this.deprecation, other.deprecation);
boolean result = true;
result = result && nullSafeEquals(this.itemType, other.itemType);
result = result && nullSafeEquals(this.name, other.name);
result = result && nullSafeEquals(this.type, other.type);
result = result && nullSafeEquals(this.description, other.description);
result = result && nullSafeEquals(this.sourceType, other.sourceType);
result = result && nullSafeEquals(this.sourceMethod, other.sourceMethod);
result = result && nullSafeEquals(this.defaultValue, other.defaultValue);
result = result && nullSafeEquals(this.deprecation, other.deprecation);
return result;
}
@Override

View File

@ -352,12 +352,12 @@ public class ConfigurationMetadataAnnotationProcessorTests {
@Test
public void innerClassPropertiesHierachical() throws Exception {
ConfigurationMetadata metadata = compile(InnerClassHierachicalProperties.class);
assertThat(metadata)
.has(Metadata.withGroup("config.foo").ofType(InnerClassHierachicalProperties.Foo.class));
assertThat(metadata).has(
Metadata.withGroup("config.foo.bar").ofType(InnerClassHierachicalProperties.Bar.class));
assertThat(metadata).has(
Metadata.withGroup("config.foo.bar.baz").ofType(InnerClassHierachicalProperties.Foo.Baz.class));
assertThat(metadata).has(Metadata.withGroup("config.foo")
.ofType(InnerClassHierachicalProperties.Foo.class));
assertThat(metadata).has(Metadata.withGroup("config.foo.bar")
.ofType(InnerClassHierachicalProperties.Bar.class));
assertThat(metadata).has(Metadata.withGroup("config.foo.bar.baz")
.ofType(InnerClassHierachicalProperties.Foo.Baz.class));
assertThat(metadata).has(Metadata.withProperty("config.foo.bar.baz.blah"));
assertThat(metadata).has(Metadata.withProperty("config.foo.bar.bling"));
}
@ -505,8 +505,8 @@ public class ConfigurationMetadataAnnotationProcessorTests {
@Test
public void lombokInnerClassWithGetterProperties() throws IOException {
ConfigurationMetadata metadata =
compile(LombokInnerClassWithGetterProperties.class);
ConfigurationMetadata metadata = compile(
LombokInnerClassWithGetterProperties.class);
assertThat(metadata).has(Metadata.withGroup("config")
.fromSource(LombokInnerClassWithGetterProperties.class));
assertThat(metadata).has(Metadata.withGroup("config.first")

View File

@ -19,8 +19,8 @@ package org.springframework.boot.configurationsample.specific;
import org.springframework.boot.configurationsample.ConfigurationProperties;
/**
* Demonstrate inner classes end up in metadata regardless of
* position in hierarchy and without the use of
* Demonstrate inner classes end up in metadata regardless of position in hierarchy and
* without the use of
* {@link org.springframework.boot.configurationsample.NestedConfigurationProperty}.
*
* @author Madhura Bhave
@ -61,7 +61,9 @@ public class InnerClassHierachicalProperties {
public void setBlah(String blah) {
this.blah = blah;
}
}
}
public static class Bar {
@ -85,6 +87,7 @@ public class InnerClassHierachicalProperties {
public void setBaz(Foo.Baz baz) {
this.baz = baz;
}
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright 2012-2016 the original author or authors.
* Copyright 2012-2017 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.

View File

@ -103,4 +103,5 @@ public class UndertowReactiveWebServerFactory extends AbstractReactiveWebServerF
public void setDirectBuffers(Boolean directBuffers) {
this.directBuffers = directBuffers;
}
}

View File

@ -23,6 +23,7 @@ import java.io.InputStream;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.core.io.AbstractResource;
import org.springframework.core.io.Resource;
import org.springframework.util.StringUtils;
/**
* Subclass of {@link AnnotationConfigApplicationContext}, suitable for reactive web
@ -37,8 +38,6 @@ public class GenericReactiveWebApplicationContext extends
private String namespace;
private final NonExistentResource nonExistentResource = new NonExistentResource();
public GenericReactiveWebApplicationContext() {
super();
}
@ -59,24 +58,25 @@ public class GenericReactiveWebApplicationContext extends
@Override
protected Resource getResourceByPath(String path) {
// No ServletContext is available
if (path.startsWith("/")) {
return this.nonExistentResource;
}
else {
return super.getResourceByPath(path);
}
// We must be careful not to expose classpath resources
return new FilteredReactiveWebContextResource(path);
}
/**
* Resource implementation that replaces the
* {@link org.springframework.web.context.support.ServletContextResource}
* in a reactive web application.
*
* <p>{@link #exists()} always returns null in order to avoid exposing
* the whole classpath in a non-servlet environment.
* {@link org.springframework.web.context.support.ServletContextResource} in a
* reactive web application.
* <p>
* {@link #exists()} always returns null in order to avoid exposing the whole
* classpath in a non-servlet environment.
*/
class NonExistentResource extends AbstractResource {
class FilteredReactiveWebContextResource extends AbstractResource {
private final String path;
FilteredReactiveWebContextResource(String path) {
this.path = path;
}
@Override
public boolean exists() {
@ -85,17 +85,20 @@ public class GenericReactiveWebApplicationContext extends
@Override
public Resource createRelative(String relativePath) throws IOException {
return this;
String pathToUse = StringUtils.applyRelativePath(this.path, relativePath);
return new FilteredReactiveWebContextResource(pathToUse);
}
@Override
public String getDescription() {
return "NonExistentResource";
return "ReactiveWebContext resource [" + this.path + "]";
}
@Override
public InputStream getInputStream() throws IOException {
throw new FileNotFoundException(this.getDescription() + " cannot be opened because it does not exist");
throw new FileNotFoundException(this.getDescription()
+ " cannot be opened because it does not exist");
}
}
}

View File

@ -57,4 +57,5 @@ public class TomcatReactiveWebServerFactoryTests
ordered.verify(listener).customize(any(Context.class));
}
}
}

View File

@ -34,7 +34,9 @@ public class GenericReactiveWebApplicationContextTests {
GenericReactiveWebApplicationContext context = new GenericReactiveWebApplicationContext();
Resource rootResource = context.getResourceByPath("/");
assertThat(rootResource.exists()).isFalse();
assertThat(rootResource.createRelative("application.properties").exists()).isFalse();
assertThat(rootResource.createRelative("application.properties").exists())
.isFalse();
context.close();
}
}