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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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. * Control flag for login configuration.
*/ */
private KafkaJaasLoginModuleInitializer.ControlFlag controlFlag = private KafkaJaasLoginModuleInitializer.ControlFlag controlFlag = KafkaJaasLoginModuleInitializer.ControlFlag.REQUIRED;
KafkaJaasLoginModuleInitializer.ControlFlag.REQUIRED;
/** /**
* Additional JAAS options. * Additional JAAS options.
@ -826,7 +825,8 @@ public class KafkaProperties {
return this.controlFlag; return this.controlFlag;
} }
public void setControlFlag(KafkaJaasLoginModuleInitializer.ControlFlag controlFlag) { public void setControlFlag(
KafkaJaasLoginModuleInitializer.ControlFlag controlFlag) {
this.controlFlag = controlFlag; this.controlFlag = controlFlag;
} }

View File

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

View File

@ -69,7 +69,8 @@ public class HttpHandlerAutoConfiguration {
@Bean @Bean
public HttpHandler httpHandler() { public HttpHandler httpHandler() {
return WebHttpHandlerBuilder.applicationContext(this.applicationContext).build(); return WebHttpHandlerBuilder.applicationContext(this.applicationContext)
.build();
} }
} }

View File

@ -31,13 +31,14 @@ import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
/** /**
* Auto configuration for WebSocket reactive server in Tomcat, Jetty or Undertow. * Auto configuration for WebSocket reactive server in Tomcat, Jetty or Undertow. Requires
* Requires the appropriate WebSocket modules to be on the classpath. * the appropriate WebSocket modules to be on the classpath.
* <p> * <p>
* If Tomcat's WebSocket support is detected on the classpath we add a customizer that * If Tomcat's WebSocket support is detected on the classpath we add a customizer that
* installs the Tomcat WebSocket initializer. * installs the Tomcat WebSocket initializer.
* *
* @author Brian Clozel * @author Brian Clozel
* @since 2.0.0
*/ */
@Configuration @Configuration
@ConditionalOnClass({ Servlet.class, ServerContainer.class }) @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.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.embedded.tomcat.TomcatServletWebServerFactory;
import org.springframework.boot.web.server.WebServerFactoryCustomizer; import org.springframework.boot.web.server.WebServerFactoryCustomizer;
import org.springframework.core.Ordered; import org.springframework.core.Ordered;
@ -36,8 +35,8 @@ public class TomcatWebSocketServletWebServerCustomizer
@Override @Override
public void customize(TomcatServletWebServerFactory factory) { public void customize(TomcatServletWebServerFactory factory) {
factory.addContextCustomizers((TomcatContextCustomizer) context -> factory.addContextCustomizers((context) -> context
context.addApplicationListener(WsContextListener.class.getName())); .addApplicationListener(WsContextListener.class.getName()));
} }
@Override @Override

View File

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

View File

@ -176,8 +176,7 @@ public class KafkaAutoConfigurationTests {
"spring.kafka.listener.ack-time=456", "spring.kafka.listener.ack-time=456",
"spring.kafka.listener.concurrency=3", "spring.kafka.listener.concurrency=3",
"spring.kafka.listener.poll-timeout=2000", "spring.kafka.listener.poll-timeout=2000",
"spring.kafka.jaas.enabled=true", "spring.kafka.jaas.enabled=true", "spring.kafka.jaas.login-module=foo",
"spring.kafka.jaas.login-module=foo",
"spring.kafka.jaas.control-flag=REQUISITE", "spring.kafka.jaas.control-flag=REQUISITE",
"spring.kafka.jaas.options.useKeyTab=true"); "spring.kafka.jaas.options.useKeyTab=true");
DefaultKafkaProducerFactory<?, ?> producerFactory = this.context DefaultKafkaProducerFactory<?, ?> producerFactory = this.context
@ -201,8 +200,8 @@ public class KafkaAutoConfigurationTests {
.isEqualTo(2000L); .isEqualTo(2000L);
assertThat(this.context.getBeansOfType(KafkaJaasLoginModuleInitializer.class)) assertThat(this.context.getBeansOfType(KafkaJaasLoginModuleInitializer.class))
.hasSize(1); .hasSize(1);
KafkaJaasLoginModuleInitializer jaas = this.context.getBean( KafkaJaasLoginModuleInitializer jaas = this.context
KafkaJaasLoginModuleInitializer.class); .getBean(KafkaJaasLoginModuleInitializer.class);
dfa = new DirectFieldAccessor(jaas); dfa = new DirectFieldAccessor(jaas);
assertThat(dfa.getPropertyValue("loginModule")).isEqualTo("foo"); assertThat(dfa.getPropertyValue("loginModule")).isEqualTo("foo");
assertThat(dfa.getPropertyValue("controlFlag")) 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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) { private Element getTopLevelType(Element element) {
if ((element.getEnclosingElement() == null) || if ((element.getEnclosingElement() == null)
!(element.getEnclosingElement() instanceof TypeElement)) { || !(element.getEnclosingElement() instanceof TypeElement)) {
return element; return element;
} }
return getTopLevelType(element.getEnclosingElement()); return getTopLevelType(element.getEnclosingElement());

View File

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

View File

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

View File

@ -352,12 +352,12 @@ public class ConfigurationMetadataAnnotationProcessorTests {
@Test @Test
public void innerClassPropertiesHierachical() throws Exception { public void innerClassPropertiesHierachical() throws Exception {
ConfigurationMetadata metadata = compile(InnerClassHierachicalProperties.class); ConfigurationMetadata metadata = compile(InnerClassHierachicalProperties.class);
assertThat(metadata) assertThat(metadata).has(Metadata.withGroup("config.foo")
.has(Metadata.withGroup("config.foo").ofType(InnerClassHierachicalProperties.Foo.class)); .ofType(InnerClassHierachicalProperties.Foo.class));
assertThat(metadata).has( assertThat(metadata).has(Metadata.withGroup("config.foo.bar")
Metadata.withGroup("config.foo.bar").ofType(InnerClassHierachicalProperties.Bar.class)); .ofType(InnerClassHierachicalProperties.Bar.class));
assertThat(metadata).has( assertThat(metadata).has(Metadata.withGroup("config.foo.bar.baz")
Metadata.withGroup("config.foo.bar.baz").ofType(InnerClassHierachicalProperties.Foo.Baz.class)); .ofType(InnerClassHierachicalProperties.Foo.Baz.class));
assertThat(metadata).has(Metadata.withProperty("config.foo.bar.baz.blah")); assertThat(metadata).has(Metadata.withProperty("config.foo.bar.baz.blah"));
assertThat(metadata).has(Metadata.withProperty("config.foo.bar.bling")); assertThat(metadata).has(Metadata.withProperty("config.foo.bar.bling"));
} }
@ -505,8 +505,8 @@ public class ConfigurationMetadataAnnotationProcessorTests {
@Test @Test
public void lombokInnerClassWithGetterProperties() throws IOException { public void lombokInnerClassWithGetterProperties() throws IOException {
ConfigurationMetadata metadata = ConfigurationMetadata metadata = compile(
compile(LombokInnerClassWithGetterProperties.class); LombokInnerClassWithGetterProperties.class);
assertThat(metadata).has(Metadata.withGroup("config") assertThat(metadata).has(Metadata.withGroup("config")
.fromSource(LombokInnerClassWithGetterProperties.class)); .fromSource(LombokInnerClassWithGetterProperties.class));
assertThat(metadata).has(Metadata.withGroup("config.first") 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; import org.springframework.boot.configurationsample.ConfigurationProperties;
/** /**
* Demonstrate inner classes end up in metadata regardless of * Demonstrate inner classes end up in metadata regardless of position in hierarchy and
* position in hierarchy and without the use of * without the use of
* {@link org.springframework.boot.configurationsample.NestedConfigurationProperty}. * {@link org.springframework.boot.configurationsample.NestedConfigurationProperty}.
* *
* @author Madhura Bhave * @author Madhura Bhave
@ -61,7 +61,9 @@ public class InnerClassHierachicalProperties {
public void setBlah(String blah) { public void setBlah(String blah) {
this.blah = blah; this.blah = blah;
} }
} }
} }
public static class Bar { public static class Bar {
@ -85,6 +87,7 @@ public class InnerClassHierachicalProperties {
public void setBaz(Foo.Baz baz) { public void setBaz(Foo.Baz baz) {
this.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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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) { public void setDirectBuffers(Boolean directBuffers) {
this.directBuffers = directBuffers; this.directBuffers = directBuffers;
} }
} }

View File

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

View File

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