Commit 07462be0 authored by Andy Wilkinson's avatar Andy Wilkinson

Polish

parent 89173bd2
...@@ -61,7 +61,8 @@ public class Token { ...@@ -61,7 +61,8 @@ public class Token {
private Map<String, Object> parseJson(String base64) { private Map<String, Object> parseJson(String base64) {
try { try {
byte[] bytes = Base64Utils.decodeFromUrlSafeString(base64); byte[] bytes = Base64Utils.decodeFromUrlSafeString(base64);
return JsonParserFactory.getJsonParser().parseMap(new String(bytes, StandardCharsets.UTF_8)); return JsonParserFactory.getJsonParser()
.parseMap(new String(bytes, StandardCharsets.UTF_8));
} }
catch (RuntimeException ex) { catch (RuntimeException ex) {
throw new CloudFoundryAuthorizationException(Reason.INVALID_TOKEN, throw new CloudFoundryAuthorizationException(Reason.INVALID_TOKEN,
......
...@@ -50,16 +50,20 @@ public class CompositeHandlerExceptionResolverTests { ...@@ -50,16 +50,20 @@ public class CompositeHandlerExceptionResolverTests {
@Test @Test
public void resolverShouldDelegateToOtherResolversInContext() throws Exception { public void resolverShouldDelegateToOtherResolversInContext() throws Exception {
load(TestConfiguration.class); load(TestConfiguration.class);
CompositeHandlerExceptionResolver resolver = (CompositeHandlerExceptionResolver) this.context.getBean(DispatcherServlet.HANDLER_EXCEPTION_RESOLVER_BEAN_NAME); CompositeHandlerExceptionResolver resolver = (CompositeHandlerExceptionResolver) this.context
ModelAndView resolved = resolver.resolveException(this.request, this.response, null, new HttpRequestMethodNotSupportedException("POST")); .getBean(DispatcherServlet.HANDLER_EXCEPTION_RESOLVER_BEAN_NAME);
ModelAndView resolved = resolver.resolveException(this.request, this.response,
null, new HttpRequestMethodNotSupportedException("POST"));
assertThat(resolved.getViewName()).isEqualTo("test-view"); assertThat(resolved.getViewName()).isEqualTo("test-view");
} }
@Test @Test
public void resolverShouldAddDefaultResolverIfNonePresent() throws Exception { public void resolverShouldAddDefaultResolverIfNonePresent() throws Exception {
load(BaseConfiguration.class); load(BaseConfiguration.class);
CompositeHandlerExceptionResolver resolver = (CompositeHandlerExceptionResolver) this.context.getBean(DispatcherServlet.HANDLER_EXCEPTION_RESOLVER_BEAN_NAME); CompositeHandlerExceptionResolver resolver = (CompositeHandlerExceptionResolver) this.context
ModelAndView resolved = resolver.resolveException(this.request, this.response, null, new HttpRequestMethodNotSupportedException("POST")); .getBean(DispatcherServlet.HANDLER_EXCEPTION_RESOLVER_BEAN_NAME);
ModelAndView resolved = resolver.resolveException(this.request, this.response,
null, new HttpRequestMethodNotSupportedException("POST"));
assertThat(resolved).isNotNull(); assertThat(resolved).isNotNull();
} }
...@@ -94,7 +98,8 @@ public class CompositeHandlerExceptionResolverTests { ...@@ -94,7 +98,8 @@ public class CompositeHandlerExceptionResolverTests {
static class TestHandlerExceptionResolver implements HandlerExceptionResolver { static class TestHandlerExceptionResolver implements HandlerExceptionResolver {
@Override @Override
public ModelAndView resolveException(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) { public ModelAndView resolveException(HttpServletRequest request,
HttpServletResponse response, Object handler, Exception ex) {
return new ModelAndView("test-view"); return new ModelAndView("test-view");
} }
......
...@@ -150,8 +150,8 @@ public class SpringIntegrationMetrics implements MeterBinder, SmartInitializingS ...@@ -150,8 +150,8 @@ public class SpringIntegrationMetrics implements MeterBinder, SmartInitializingS
private <T> void registerFunctionCounter(MeterRegistry registry, T object, private <T> void registerFunctionCounter(MeterRegistry registry, T object,
Iterable<Tag> tags, String name, String description, Iterable<Tag> tags, String name, String description,
ToDoubleFunction<T> value) { ToDoubleFunction<T> value) {
FunctionCounter.builder(name, object, value).tags(tags) FunctionCounter.builder(name, object, value).tags(tags).description(description)
.description(description).register(registry); .register(registry);
} }
@Override @Override
......
...@@ -57,7 +57,8 @@ public class ConditionEvaluationReportLoggingListener ...@@ -57,7 +57,8 @@ public class ConditionEvaluationReportLoggingListener
@Override @Override
public void initialize(ConfigurableApplicationContext applicationContext) { public void initialize(ConfigurableApplicationContext applicationContext) {
this.applicationContext = applicationContext; this.applicationContext = applicationContext;
applicationContext.addApplicationListener(new ConditionEvaluationReportListener()); applicationContext
.addApplicationListener(new ConditionEvaluationReportListener());
if (applicationContext instanceof GenericApplicationContext) { if (applicationContext instanceof GenericApplicationContext) {
// Get the report early in case the context fails to load // Get the report early in case the context fails to load
this.report = ConditionEvaluationReport this.report = ConditionEvaluationReport
......
...@@ -147,8 +147,7 @@ public class ConditionEvaluationReportLoggingListenerTests { ...@@ -147,8 +147,7 @@ public class ConditionEvaluationReportLoggingListenerTests {
private void withDebugLogging(Runnable runnable) { private void withDebugLogging(Runnable runnable) {
LoggerContext context = (LoggerContext) StaticLoggerBinder.getSingleton() LoggerContext context = (LoggerContext) StaticLoggerBinder.getSingleton()
.getLoggerFactory(); .getLoggerFactory();
Logger logger = context Logger logger = context.getLogger(ConditionEvaluationReportLoggingListener.class);
.getLogger(ConditionEvaluationReportLoggingListener.class);
Level currentLevel = logger.getLevel(); Level currentLevel = logger.getLevel();
logger.setLevel(Level.DEBUG); logger.setLevel(Level.DEBUG);
try { try {
......
...@@ -203,10 +203,10 @@ public class DefaultErrorWebExceptionHandlerIntegrationTest { ...@@ -203,10 +203,10 @@ public class DefaultErrorWebExceptionHandlerIntegrationTest {
@Target(ElementType.TYPE) @Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME) @Retention(RetentionPolicy.RUNTIME)
@Documented @Documented
@Import({ReactiveWebServerAutoConfiguration.class, @Import({ ReactiveWebServerAutoConfiguration.class,
HttpHandlerAutoConfiguration.class, WebFluxAutoConfiguration.class, HttpHandlerAutoConfiguration.class, WebFluxAutoConfiguration.class,
ErrorWebFluxAutoConfiguration.class, ErrorWebFluxAutoConfiguration.class,
PropertyPlaceholderAutoConfiguration.class}) PropertyPlaceholderAutoConfiguration.class })
private @interface MinimalWebConfiguration { private @interface MinimalWebConfiguration {
} }
......
...@@ -54,7 +54,8 @@ public class TestPropertyValuesTests { ...@@ -54,7 +54,8 @@ public class TestPropertyValuesTests {
@Test @Test
public void applyToSystemPropertySource() throws Exception { public void applyToSystemPropertySource() throws Exception {
TestPropertyValues.of("FOO_BAR=BAZ").applyTo(this.environment, Type.SYSTEM_ENVIRONMENT); TestPropertyValues.of("FOO_BAR=BAZ").applyTo(this.environment,
Type.SYSTEM_ENVIRONMENT);
assertThat(this.environment.getProperty("foo.bar")).isEqualTo("BAZ"); assertThat(this.environment.getProperty("foo.bar")).isEqualTo("BAZ");
assertThat(this.environment.getPropertySources().contains( assertThat(this.environment.getPropertySources().contains(
"test-" + StandardEnvironment.SYSTEM_ENVIRONMENT_PROPERTY_SOURCE_NAME)); "test-" + StandardEnvironment.SYSTEM_ENVIRONMENT_PROPERTY_SOURCE_NAME));
...@@ -72,8 +73,8 @@ public class TestPropertyValuesTests { ...@@ -72,8 +73,8 @@ public class TestPropertyValuesTests {
throws Exception { throws Exception {
TestPropertyValues.of("foo.bar=baz", "hello.world=hi").applyTo(this.environment, TestPropertyValues.of("foo.bar=baz", "hello.world=hi").applyTo(this.environment,
Type.MAP, "other"); Type.MAP, "other");
TestPropertyValues.of("FOO_BAR=BAZ").applyTo(this.environment, Type.SYSTEM_ENVIRONMENT, TestPropertyValues.of("FOO_BAR=BAZ").applyTo(this.environment,
"other"); Type.SYSTEM_ENVIRONMENT, "other");
assertThat(this.environment.getPropertySources().get("other")) assertThat(this.environment.getPropertySources().get("other"))
.isInstanceOf(SystemEnvironmentPropertySource.class); .isInstanceOf(SystemEnvironmentPropertySource.class);
assertThat(this.environment.getProperty("foo.bar")).isEqualTo("BAZ"); assertThat(this.environment.getProperty("foo.bar")).isEqualTo("BAZ");
......
...@@ -155,8 +155,8 @@ class OriginTrackedPropertiesLoader { ...@@ -155,8 +155,8 @@ class OriginTrackedPropertiesLoader {
private int character; private int character;
CharacterReader(Resource resource) throws IOException { CharacterReader(Resource resource) throws IOException {
this.reader = new LineNumberReader( this.reader = new LineNumberReader(new InputStreamReader(
new InputStreamReader(resource.getInputStream(), StandardCharsets.ISO_8859_1)); resource.getInputStream(), StandardCharsets.ISO_8859_1));
} }
@Override @Override
......
...@@ -197,9 +197,8 @@ public class JettyWebServer implements WebServer { ...@@ -197,9 +197,8 @@ public class JettyWebServer implements WebServer {
private String getContextPath() { private String getContextPath() {
return Arrays.stream(this.server.getHandlers()) return Arrays.stream(this.server.getHandlers())
.filter(ContextHandler.class::isInstance) .filter(ContextHandler.class::isInstance).map(ContextHandler.class::cast)
.map(handler -> ((ContextHandler) handler).getContextPath()) .map(ContextHandler::getContextPath).collect(Collectors.joining(" "));
.collect(Collectors.joining(" "));
} }
private void handleDeferredInitialize(Handler... handlers) throws Exception { private void handleDeferredInitialize(Handler... handlers) throws Exception {
......
...@@ -91,7 +91,8 @@ public class NettyReactiveWebServerFactory extends AbstractReactiveWebServerFact ...@@ -91,7 +91,8 @@ public class NettyReactiveWebServerFactory extends AbstractReactiveWebServerFact
return HttpServer.builder().options((options) -> { return HttpServer.builder().options((options) -> {
options.listenAddress(getListenAddress()); options.listenAddress(getListenAddress());
if (getSsl() != null && getSsl().isEnabled()) { if (getSsl() != null && getSsl().isEnabled()) {
SslServerCustomizer sslServerCustomizer = new SslServerCustomizer(getSsl(), getSslStoreProvider()); SslServerCustomizer sslServerCustomizer = new SslServerCustomizer(
getSsl(), getSslStoreProvider());
sslServerCustomizer.customize(options); sslServerCustomizer.customize(options);
} }
applyCustomizers(options); applyCustomizers(options);
......
...@@ -31,8 +31,8 @@ import org.springframework.boot.web.server.SslStoreProvider; ...@@ -31,8 +31,8 @@ import org.springframework.boot.web.server.SslStoreProvider;
import org.springframework.util.ResourceUtils; import org.springframework.util.ResourceUtils;
/** /**
* {@link NettyServerCustomizer} that configures SSL for the * {@link NettyServerCustomizer} that configures SSL for the given Reactor Netty server
* given Reactor Netty server instance. * instance.
* *
* @author Brian Clozel * @author Brian Clozel
*/ */
...@@ -66,7 +66,8 @@ public class SslServerCustomizer implements NettyServerCustomizer { ...@@ -66,7 +66,8 @@ public class SslServerCustomizer implements NettyServerCustomizer {
} }
} }
protected KeyManagerFactory getKeyManagerFactory(Ssl ssl, SslStoreProvider sslStoreProvider) { protected KeyManagerFactory getKeyManagerFactory(Ssl ssl,
SslStoreProvider sslStoreProvider) {
try { try {
KeyStore keyStore = getKeyStore(ssl, sslStoreProvider); KeyStore keyStore = getKeyStore(ssl, sslStoreProvider);
KeyManagerFactory keyManagerFactory = KeyManagerFactory KeyManagerFactory keyManagerFactory = KeyManagerFactory
...@@ -84,7 +85,8 @@ public class SslServerCustomizer implements NettyServerCustomizer { ...@@ -84,7 +85,8 @@ public class SslServerCustomizer implements NettyServerCustomizer {
} }
} }
private KeyStore getKeyStore(Ssl ssl, SslStoreProvider sslStoreProvider) throws Exception { private KeyStore getKeyStore(Ssl ssl, SslStoreProvider sslStoreProvider)
throws Exception {
if (sslStoreProvider != null) { if (sslStoreProvider != null) {
return sslStoreProvider.getKeyStore(); return sslStoreProvider.getKeyStore();
} }
...@@ -92,7 +94,8 @@ public class SslServerCustomizer implements NettyServerCustomizer { ...@@ -92,7 +94,8 @@ public class SslServerCustomizer implements NettyServerCustomizer {
ssl.getKeyStorePassword()); ssl.getKeyStorePassword());
} }
protected TrustManagerFactory getTrustManagerFactory(Ssl ssl, SslStoreProvider sslStoreProvider) { protected TrustManagerFactory getTrustManagerFactory(Ssl ssl,
SslStoreProvider sslStoreProvider) {
try { try {
KeyStore store = getTrustStore(ssl, sslStoreProvider); KeyStore store = getTrustStore(ssl, sslStoreProvider);
TrustManagerFactory trustManagerFactory = TrustManagerFactory TrustManagerFactory trustManagerFactory = TrustManagerFactory
...@@ -105,7 +108,8 @@ public class SslServerCustomizer implements NettyServerCustomizer { ...@@ -105,7 +108,8 @@ public class SslServerCustomizer implements NettyServerCustomizer {
} }
} }
private KeyStore getTrustStore(Ssl ssl, SslStoreProvider sslStoreProvider) throws Exception { private KeyStore getTrustStore(Ssl ssl, SslStoreProvider sslStoreProvider)
throws Exception {
if (sslStoreProvider != null) { if (sslStoreProvider != null) {
return sslStoreProvider.getTrustStore(); return sslStoreProvider.getTrustStore();
} }
......
...@@ -57,7 +57,7 @@ public class TomcatReactiveWebServerFactory extends AbstractReactiveWebServerFac ...@@ -57,7 +57,7 @@ public class TomcatReactiveWebServerFactory extends AbstractReactiveWebServerFac
private String protocol = DEFAULT_PROTOCOL; private String protocol = DEFAULT_PROTOCOL;
private List<LifecycleListener> contextLifecycleListeners = new ArrayList<LifecycleListener>( private List<LifecycleListener> contextLifecycleListeners = new ArrayList<>(
Collections.singleton(new AprLifecycleListener())); Collections.singleton(new AprLifecycleListener()));
private List<TomcatContextCustomizer> tomcatContextCustomizers = new ArrayList<>(); private List<TomcatContextCustomizer> tomcatContextCustomizers = new ArrayList<>();
......
...@@ -224,7 +224,8 @@ public class TomcatServletWebServerFactory extends AbstractServletWebServerFacto ...@@ -224,7 +224,8 @@ public class TomcatServletWebServerFactory extends AbstractServletWebServerFacto
private void configureTldSkipPatterns(TomcatEmbeddedContext context) { private void configureTldSkipPatterns(TomcatEmbeddedContext context) {
StandardJarScanFilter filter = new StandardJarScanFilter(); StandardJarScanFilter filter = new StandardJarScanFilter();
filter.setTldSkip(StringUtils.collectionToCommaDelimitedString(this.tldSkipPatterns)); filter.setTldSkip(
StringUtils.collectionToCommaDelimitedString(this.tldSkipPatterns));
context.getJarScanner().setJarScanFilter(filter); context.getJarScanner().setJarScanFilter(filter);
} }
......
...@@ -329,8 +329,8 @@ public class TomcatWebServer implements WebServer { ...@@ -329,8 +329,8 @@ public class TomcatWebServer implements WebServer {
private String getContextPath() { private String getContextPath() {
return Arrays.stream(this.tomcat.getHost().findChildren()) return Arrays.stream(this.tomcat.getHost().findChildren())
.filter(TomcatEmbeddedContext.class::isInstance) .filter(TomcatEmbeddedContext.class::isInstance)
.map(context -> ((TomcatEmbeddedContext) context).getPath()) .map(TomcatEmbeddedContext.class::cast)
.collect(Collectors.joining(" ")); .map(TomcatEmbeddedContext::getPath).collect(Collectors.joining(" "));
} }
/** /**
......
...@@ -398,7 +398,8 @@ public class TomcatServletWebServerFactoryTests ...@@ -398,7 +398,8 @@ public class TomcatServletWebServerFactoryTests
Tomcat tomcat = ((TomcatWebServer) this.webServer).getTomcat(); Tomcat tomcat = ((TomcatWebServer) this.webServer).getTomcat();
Context context = (Context) tomcat.getHost().findChildren()[0]; Context context = (Context) tomcat.getHost().findChildren()[0];
JarScanFilter jarScanFilter = context.getJarScanner().getJarScanFilter(); JarScanFilter jarScanFilter = context.getJarScanner().getJarScanFilter();
Set<String> tldSkipSet = (Set<String>) ReflectionTestUtils.getField(jarScanFilter, "tldSkipSet"); Set<String> tldSkipSet = (Set<String>) ReflectionTestUtils.getField(jarScanFilter,
"tldSkipSet");
assertThat(tldSkipSet).contains("foo.jar", "bar.jar"); assertThat(tldSkipSet).contains("foo.jar", "bar.jar");
} }
......
...@@ -17,7 +17,6 @@ ...@@ -17,7 +17,6 @@
package sample.tomcat; package sample.tomcat;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.util.zip.GZIPInputStream; import java.util.zip.GZIPInputStream;
......
...@@ -17,7 +17,6 @@ ...@@ -17,7 +17,6 @@
package sample.undertow; package sample.undertow;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.util.zip.GZIPInputStream; import java.util.zip.GZIPInputStream;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment