Restructure embedded web server packages
Rework `org.springframework.boot.context.embedded` to relocate classes to `org.springframework.boot.web`. Packages are now organized around the following areas: Packages for shared concerns, for example the `WebServer` interface to start/stop a server and the common configuration elements: - org.springframework.boot.web.context - org.springframework.boot.web.server Servlet specific packages: - org.springframework.boot.web.servlet.server - org.springframework.boot.web.servlet.context - org.springframework.boot.web.servlet.filter Reactive specific packages: - org.springframework.boot.web.reactive.context - org.springframework.boot.web.reactive.server Embedded server implementations (both reactive and servlet): - org.springframework.boot.web.embedded In addition: - Rename `EmbeddedServletContainerFactory` to `ServletWebServerFactory` to align with the `ReactiveWebServerFactory`. - Rename `EmbeddedWebApplicationContext` to `ServletWebServerApplicationContext` and - Rename `EmbeddedReactiveWebApplicationContext` to `ReactiveWebServerApplicationContext`. - Add checkstyle rules to restrict imports. - Fixup all affected code to use the correct imports and local names. Fixes gh-8532
This commit is contained in:
@@ -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.
|
||||
@@ -19,8 +19,10 @@ package org.springframework.boot.context.embedded;
|
||||
import org.apache.catalina.Context;
|
||||
import org.apache.tomcat.util.http.LegacyCookieProcessor;
|
||||
|
||||
import org.springframework.boot.context.embedded.tomcat.TomcatContextCustomizer;
|
||||
import org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory;
|
||||
import org.springframework.boot.web.embedded.tomcat.TomcatContextCustomizer;
|
||||
import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory;
|
||||
import org.springframework.boot.web.servlet.server.ConfigurableServletWebServerFactory;
|
||||
import org.springframework.boot.web.servlet.server.ServletWebServerFactoryCustomizer;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@@ -33,20 +35,20 @@ public class TomcatLegacyCookieProcessorExample {
|
||||
|
||||
/**
|
||||
* Configuration class that declares the required
|
||||
* {@link EmbeddedServletContainerCustomizer}.
|
||||
* {@link ServletWebServerFactoryCustomizer}.
|
||||
*/
|
||||
@Configuration
|
||||
static class LegacyCookieProcessorConfiguration {
|
||||
|
||||
// tag::customizer[]
|
||||
@Bean
|
||||
public EmbeddedServletContainerCustomizer cookieProcessorCustomizer() {
|
||||
return new EmbeddedServletContainerCustomizer() {
|
||||
public ServletWebServerFactoryCustomizer cookieProcessorCustomizer() {
|
||||
return new ServletWebServerFactoryCustomizer() {
|
||||
|
||||
@Override
|
||||
public void customize(ConfigurableEmbeddedServletContainer container) {
|
||||
if (container instanceof TomcatEmbeddedServletContainerFactory) {
|
||||
((TomcatEmbeddedServletContainerFactory) container)
|
||||
public void customize(ConfigurableServletWebServerFactory serverFactory) {
|
||||
if (serverFactory instanceof TomcatServletWebServerFactory) {
|
||||
((TomcatServletWebServerFactory) serverFactory)
|
||||
.addContextCustomizers(new TomcatContextCustomizer() {
|
||||
|
||||
@Override
|
||||
|
||||
@@ -22,8 +22,10 @@ import org.junit.Test;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.context.embedded.TomcatLegacyCookieProcessorExample.LegacyCookieProcessorConfiguration;
|
||||
import org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainer;
|
||||
import org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory;
|
||||
import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory;
|
||||
import org.springframework.boot.web.embedded.tomcat.TomcatWebServer;
|
||||
import org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext;
|
||||
import org.springframework.boot.web.servlet.server.ServletWebServerFactoryCustomizerBeanPostProcessor;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@@ -38,10 +40,10 @@ public class TomcatLegacyCookieProcessorExampleTests {
|
||||
|
||||
@Test
|
||||
public void cookieProcessorIsCustomized() {
|
||||
EmbeddedWebApplicationContext applicationContext = (EmbeddedWebApplicationContext) new SpringApplication(
|
||||
ServletWebServerApplicationContext applicationContext = (ServletWebServerApplicationContext) new SpringApplication(
|
||||
TestConfiguration.class, LegacyCookieProcessorConfiguration.class).run();
|
||||
Context context = (Context) ((TomcatEmbeddedServletContainer) applicationContext
|
||||
.getEmbeddedWebServer()).getTomcat().getHost().findChildren()[0];
|
||||
Context context = (Context) ((TomcatWebServer) applicationContext
|
||||
.getWebServer()).getTomcat().getHost().findChildren()[0];
|
||||
assertThat(context.getCookieProcessor())
|
||||
.isInstanceOf(LegacyCookieProcessor.class);
|
||||
}
|
||||
@@ -50,13 +52,13 @@ public class TomcatLegacyCookieProcessorExampleTests {
|
||||
static class TestConfiguration {
|
||||
|
||||
@Bean
|
||||
public TomcatEmbeddedServletContainerFactory tomcatFactory() {
|
||||
return new TomcatEmbeddedServletContainerFactory(0);
|
||||
public TomcatServletWebServerFactory tomcatFactory() {
|
||||
return new TomcatServletWebServerFactory(0);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public EmbeddedServletContainerCustomizerBeanPostProcessor postProcessor() {
|
||||
return new EmbeddedServletContainerCustomizerBeanPostProcessor();
|
||||
public ServletWebServerFactoryCustomizerBeanPostProcessor postProcessor() {
|
||||
return new ServletWebServerFactoryCustomizerBeanPostProcessor();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user