202 changed files with 392 additions and 272 deletions
@ -0,0 +1,53 @@
@@ -0,0 +1,53 @@
|
||||
/* |
||||
* Copyright 2012-present 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. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* https://www.apache.org/licenses/LICENSE-2.0 |
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
|
||||
plugins { |
||||
id "java-library" |
||||
id "java-test-fixtures" |
||||
id "org.springframework.boot.deployed" |
||||
id "org.springframework.boot.optional-dependencies" |
||||
} |
||||
|
||||
description = "Spring Boot Web Server" |
||||
|
||||
dependencies { |
||||
api(project(":spring-boot-project:spring-boot")) |
||||
api("org.springframework:spring-web") |
||||
|
||||
optional("io.projectreactor:reactor-core") |
||||
optional("jakarta.servlet:jakarta.servlet-api") |
||||
optional("org.springframework:spring-test") |
||||
|
||||
testFixturesCompileOnly(project(":spring-boot-project:spring-boot-tools:spring-boot-test-support")) |
||||
testFixturesCompileOnly("io.projectreactor:reactor-test") |
||||
testFixturesCompileOnly("io.projectreactor.netty:reactor-netty-http") |
||||
testFixturesCompileOnly("org.apache.httpcomponents.client5:httpclient5") |
||||
testFixturesCompileOnly("org.apache.tomcat.embed:tomcat-embed-jasper") |
||||
testFixturesCompileOnly("org.eclipse.jetty.http2:jetty-http2-client") |
||||
testFixturesCompileOnly("org.eclipse.jetty.http2:jetty-http2-client-transport") |
||||
testFixturesCompileOnly("jakarta.servlet:jakarta.servlet-api") |
||||
testFixturesCompileOnly("org.mockito:mockito-core") |
||||
testFixturesCompileOnly("org.springframework:spring-tx") |
||||
testFixturesCompileOnly("org.springframework:spring-webflux") |
||||
|
||||
testImplementation(project(":spring-boot-project:spring-boot-tools:spring-boot-test-support")) |
||||
testImplementation(testFixtures(project(":spring-boot-project:spring-boot"))) |
||||
testImplementation("org.apache.tomcat.embed:tomcat-embed-core") |
||||
testImplementation("org.springframework:spring-webmvc") |
||||
|
||||
testRuntimeOnly("ch.qos.logback:logback-classic") |
||||
} |
||||
0
spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/server/reactive/context/AnnotationConfigReactiveWebServerApplicationContext.java → spring-boot-project/spring-boot-web-server/src/main/java/org/springframework/boot/web/server/reactive/context/AnnotationConfigReactiveWebServerApplicationContext.java
0
spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/server/reactive/context/AnnotationConfigReactiveWebServerApplicationContext.java → spring-boot-project/spring-boot-web-server/src/main/java/org/springframework/boot/web/server/reactive/context/AnnotationConfigReactiveWebServerApplicationContext.java
0
spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/server/reactive/context/ReactiveWebServerApplicationContextFactory.java → spring-boot-project/spring-boot-web-server/src/main/java/org/springframework/boot/web/server/reactive/context/ReactiveWebServerApplicationContextFactory.java
0
spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/server/reactive/context/ReactiveWebServerApplicationContextFactory.java → spring-boot-project/spring-boot-web-server/src/main/java/org/springframework/boot/web/server/reactive/context/ReactiveWebServerApplicationContextFactory.java
0
spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/server/servlet/context/AnnotationConfigServletWebServerApplicationContext.java → spring-boot-project/spring-boot-web-server/src/main/java/org/springframework/boot/web/server/servlet/context/AnnotationConfigServletWebServerApplicationContext.java
0
spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/server/servlet/context/AnnotationConfigServletWebServerApplicationContext.java → spring-boot-project/spring-boot-web-server/src/main/java/org/springframework/boot/web/server/servlet/context/AnnotationConfigServletWebServerApplicationContext.java
0
spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/server/servlet/context/ServletComponentRegisteringPostProcessor.java → spring-boot-project/spring-boot-web-server/src/main/java/org/springframework/boot/web/server/servlet/context/ServletComponentRegisteringPostProcessor.java
0
spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/server/servlet/context/ServletComponentRegisteringPostProcessor.java → spring-boot-project/spring-boot-web-server/src/main/java/org/springframework/boot/web/server/servlet/context/ServletComponentRegisteringPostProcessor.java
0
spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/server/servlet/context/ServletWebServerApplicationContextFactory.java → spring-boot-project/spring-boot-web-server/src/main/java/org/springframework/boot/web/server/servlet/context/ServletWebServerApplicationContextFactory.java
0
spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/server/servlet/context/ServletWebServerApplicationContextFactory.java → spring-boot-project/spring-boot-web-server/src/main/java/org/springframework/boot/web/server/servlet/context/ServletWebServerApplicationContextFactory.java
0
spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/server/servlet/context/WebApplicationContextServletContextAwareProcessor.java → spring-boot-project/spring-boot-web-server/src/main/java/org/springframework/boot/web/server/servlet/context/WebApplicationContextServletContextAwareProcessor.java
0
spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/server/servlet/context/WebApplicationContextServletContextAwareProcessor.java → spring-boot-project/spring-boot-web-server/src/main/java/org/springframework/boot/web/server/servlet/context/WebApplicationContextServletContextAwareProcessor.java
@ -0,0 +1,13 @@
@@ -0,0 +1,13 @@
|
||||
# Application Context Factories |
||||
org.springframework.boot.ApplicationContextFactory=\ |
||||
org.springframework.boot.web.server.reactive.context.ReactiveWebServerApplicationContextFactory,\ |
||||
org.springframework.boot.web.server.servlet.context.ServletWebServerApplicationContextFactory |
||||
|
||||
# Application Context Initializers |
||||
org.springframework.context.ApplicationContextInitializer=\ |
||||
org.springframework.boot.web.server.context.ServerPortInfoApplicationContextInitializer |
||||
|
||||
# Failure Analyzers |
||||
org.springframework.boot.diagnostics.FailureAnalyzer=\ |
||||
org.springframework.boot.web.server.PortInUseFailureAnalyzer,\ |
||||
org.springframework.boot.web.server.context.MissingWebServerFactoryBeanFailureAnalyzer |
||||
@ -0,0 +1,2 @@
@@ -0,0 +1,2 @@
|
||||
org.springframework.aot.hint.RuntimeHintsRegistrar=\ |
||||
org.springframework.boot.web.server.MimeMappings$MimeMappingsRuntimeHints |
||||
@ -0,0 +1,188 @@
@@ -0,0 +1,188 @@
|
||||
/* |
||||
* Copyright 2012-present 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. |
||||
* You may obtain a copy of the License at |
||||
* |
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software |
||||
* distributed under the License is distributed on an "AS IS" BASIS, |
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
* See the License for the specific language governing permissions and |
||||
* limitations under the License. |
||||
*/ |
||||
|
||||
package org.springframework.boot.web.server; |
||||
|
||||
import java.util.Iterator; |
||||
|
||||
import org.junit.jupiter.api.AfterEach; |
||||
import org.junit.jupiter.api.BeforeEach; |
||||
import org.junit.jupiter.api.Test; |
||||
import reactor.core.publisher.Mono; |
||||
|
||||
import org.springframework.boot.SpringApplication; |
||||
import org.springframework.boot.WebApplicationType; |
||||
import org.springframework.boot.context.event.ApplicationEnvironmentPreparedEvent; |
||||
import org.springframework.boot.testsupport.classpath.resources.WithResource; |
||||
import org.springframework.boot.web.context.reactive.ReactiveWebApplicationContext; |
||||
import org.springframework.boot.web.context.reactive.StandardReactiveWebEnvironment; |
||||
import org.springframework.boot.web.server.reactive.MockReactiveWebServerFactory; |
||||
import org.springframework.boot.web.server.reactive.context.AnnotationConfigReactiveWebServerApplicationContext; |
||||
import org.springframework.boot.web.server.servlet.MockServletWebServerFactory; |
||||
import org.springframework.boot.web.server.servlet.context.AnnotationConfigServletWebServerApplicationContext; |
||||
import org.springframework.context.ApplicationListener; |
||||
import org.springframework.context.ConfigurableApplicationContext; |
||||
import org.springframework.context.annotation.Bean; |
||||
import org.springframework.context.annotation.Configuration; |
||||
import org.springframework.core.env.PropertySource; |
||||
import org.springframework.http.server.reactive.HttpHandler; |
||||
import org.springframework.test.context.support.TestPropertySourceUtils; |
||||
import org.springframework.web.context.WebApplicationContext; |
||||
import org.springframework.web.context.support.StandardServletEnvironment; |
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat; |
||||
|
||||
/** |
||||
* Tests for {@link SpringApplication} with a {@link WebServer}. |
||||
* |
||||
* @author Andy wilkinson |
||||
*/ |
||||
class SpringApplicationWebServerTests { |
||||
|
||||
private String headlessProperty; |
||||
|
||||
private ConfigurableApplicationContext context; |
||||
|
||||
@BeforeEach |
||||
void storeAndClearHeadlessProperty() { |
||||
this.headlessProperty = System.getProperty("java.awt.headless"); |
||||
System.clearProperty("java.awt.headless"); |
||||
} |
||||
|
||||
@AfterEach |
||||
void reinstateHeadlessProperty() { |
||||
if (this.headlessProperty == null) { |
||||
System.clearProperty("java.awt.headless"); |
||||
} |
||||
else { |
||||
System.setProperty("java.awt.headless", this.headlessProperty); |
||||
} |
||||
} |
||||
|
||||
@AfterEach |
||||
void cleanUp() { |
||||
if (this.context != null) { |
||||
this.context.close(); |
||||
} |
||||
System.clearProperty("spring.main.banner-mode"); |
||||
} |
||||
|
||||
@Test |
||||
void defaultApplicationContextForWeb() { |
||||
SpringApplication application = new SpringApplication(ExampleWebConfig.class); |
||||
application.setWebApplicationType(WebApplicationType.SERVLET); |
||||
this.context = application.run(); |
||||
assertThat(this.context).isInstanceOf(AnnotationConfigServletWebServerApplicationContext.class); |
||||
} |
||||
|
||||
@Test |
||||
void defaultApplicationContextForReactiveWeb() { |
||||
SpringApplication application = new SpringApplication(ExampleReactiveWebConfig.class); |
||||
application.setWebApplicationType(WebApplicationType.REACTIVE); |
||||
this.context = application.run(); |
||||
assertThat(this.context).isInstanceOf(AnnotationConfigReactiveWebServerApplicationContext.class); |
||||
} |
||||
|
||||
@Test |
||||
void environmentForWeb() { |
||||
SpringApplication application = new SpringApplication(ExampleWebConfig.class); |
||||
application.setWebApplicationType(WebApplicationType.SERVLET); |
||||
this.context = application.run(); |
||||
assertThat(this.context.getEnvironment()).isInstanceOf(StandardServletEnvironment.class); |
||||
assertThat(this.context.getEnvironment().getClass().getName()).endsWith("ApplicationServletEnvironment"); |
||||
} |
||||
|
||||
@Test |
||||
void environmentForReactiveWeb() { |
||||
SpringApplication application = new SpringApplication(ExampleReactiveWebConfig.class); |
||||
application.setWebApplicationType(WebApplicationType.REACTIVE); |
||||
this.context = application.run(); |
||||
assertThat(this.context.getEnvironment()).isInstanceOf(StandardReactiveWebEnvironment.class); |
||||
assertThat(this.context.getEnvironment().getClass().getName()).endsWith("ApplicationReactiveWebEnvironment"); |
||||
} |
||||
|
||||
@Test |
||||
void webApplicationConfiguredViaAPropertyHasTheCorrectTypeOfContextAndEnvironment() { |
||||
ConfigurableApplicationContext context = new SpringApplication(ExampleWebConfig.class) |
||||
.run("--spring.main.web-application-type=servlet"); |
||||
assertThat(context).isInstanceOf(WebApplicationContext.class); |
||||
assertThat(context.getEnvironment()).isInstanceOf(StandardServletEnvironment.class); |
||||
assertThat(context.getEnvironment().getClass().getName()).endsWith("ApplicationServletEnvironment"); |
||||
} |
||||
|
||||
@Test |
||||
void reactiveApplicationConfiguredViaAPropertyHasTheCorrectTypeOfContextAndEnvironment() { |
||||
ConfigurableApplicationContext context = new SpringApplication(ExampleReactiveWebConfig.class) |
||||
.run("--spring.main.web-application-type=reactive"); |
||||
assertThat(context).isInstanceOf(ReactiveWebApplicationContext.class); |
||||
assertThat(context.getEnvironment()).isInstanceOf(StandardReactiveWebEnvironment.class); |
||||
assertThat(context.getEnvironment().getClass().getName()).endsWith("ApplicationReactiveWebEnvironment"); |
||||
} |
||||
|
||||
@Test |
||||
@WithResource(name = "application-withwebapplicationtype.properties", |
||||
content = "spring.main.web-application-type=reactive") |
||||
void environmentIsConvertedIfTypeDoesNotMatch() { |
||||
ConfigurableApplicationContext context = new SpringApplication(ExampleReactiveWebConfig.class) |
||||
.run("--spring.profiles.active=withwebapplicationtype"); |
||||
assertThat(context).isInstanceOf(ReactiveWebApplicationContext.class); |
||||
assertThat(context.getEnvironment()).isInstanceOf(StandardReactiveWebEnvironment.class); |
||||
assertThat(context.getEnvironment().getClass().getName()).endsWith("ApplicationReactiveWebEnvironment"); |
||||
} |
||||
|
||||
@Test |
||||
void webApplicationSwitchedOffInListener() { |
||||
SpringApplication application = new SpringApplication(ExampleWebConfig.class); |
||||
application.addListeners((ApplicationListener<ApplicationEnvironmentPreparedEvent>) (event) -> { |
||||
assertThat(event.getEnvironment().getClass().getName()).endsWith("ApplicationServletEnvironment"); |
||||
TestPropertySourceUtils.addInlinedPropertiesToEnvironment(event.getEnvironment(), "foo=bar"); |
||||
event.getSpringApplication().setWebApplicationType(WebApplicationType.NONE); |
||||
}); |
||||
this.context = application.run(); |
||||
assertThat(this.context.getEnvironment()).isNotInstanceOf(StandardServletEnvironment.class); |
||||
assertThat(this.context.getEnvironment().getProperty("foo")).isEqualTo("bar"); |
||||
Iterator<PropertySource<?>> iterator = this.context.getEnvironment().getPropertySources().iterator(); |
||||
assertThat(iterator.next().getName()).isEqualTo("configurationProperties"); |
||||
assertThat(iterator.next().getName()) |
||||
.isEqualTo(TestPropertySourceUtils.INLINED_PROPERTIES_PROPERTY_SOURCE_NAME); |
||||
} |
||||
|
||||
@Configuration(proxyBeanMethods = false) |
||||
static class ExampleWebConfig { |
||||
|
||||
@Bean |
||||
MockServletWebServerFactory webServer() { |
||||
return new MockServletWebServerFactory(); |
||||
} |
||||
|
||||
} |
||||
|
||||
@Configuration(proxyBeanMethods = false) |
||||
static class ExampleReactiveWebConfig { |
||||
|
||||
@Bean |
||||
MockReactiveWebServerFactory webServerFactory() { |
||||
return new MockReactiveWebServerFactory(); |
||||
} |
||||
|
||||
@Bean |
||||
HttpHandler httpHandler() { |
||||
return (serverHttpRequest, serverHttpResponse) -> Mono.empty(); |
||||
} |
||||
|
||||
} |
||||
|
||||
} |
||||
0
spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/server/context/MissingWebServerFactoryBeanFailureAnalyzerTests.java → spring-boot-project/spring-boot-web-server/src/test/java/org/springframework/boot/web/server/context/MissingWebServerFactoryBeanFailureAnalyzerTests.java
0
spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/server/context/MissingWebServerFactoryBeanFailureAnalyzerTests.java → spring-boot-project/spring-boot-web-server/src/test/java/org/springframework/boot/web/server/context/MissingWebServerFactoryBeanFailureAnalyzerTests.java
0
spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/server/reactive/context/AnnotationConfigReactiveWebServerApplicationContextTests.java → spring-boot-project/spring-boot-web-server/src/test/java/org/springframework/boot/web/server/reactive/context/AnnotationConfigReactiveWebServerApplicationContextTests.java
0
spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/server/reactive/context/AnnotationConfigReactiveWebServerApplicationContextTests.java → spring-boot-project/spring-boot-web-server/src/test/java/org/springframework/boot/web/server/reactive/context/AnnotationConfigReactiveWebServerApplicationContextTests.java
0
spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/server/reactive/context/ApplicationReactiveWebEnvironmentTests.java → spring-boot-project/spring-boot-web-server/src/test/java/org/springframework/boot/web/server/reactive/context/ApplicationReactiveWebEnvironmentTests.java
0
spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/server/reactive/context/ApplicationReactiveWebEnvironmentTests.java → spring-boot-project/spring-boot-web-server/src/test/java/org/springframework/boot/web/server/reactive/context/ApplicationReactiveWebEnvironmentTests.java
0
spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/server/reactive/context/ReactiveWebServerApplicationContextTests.java → spring-boot-project/spring-boot-web-server/src/test/java/org/springframework/boot/web/server/reactive/context/ReactiveWebServerApplicationContextTests.java
0
spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/server/reactive/context/ReactiveWebServerApplicationContextTests.java → spring-boot-project/spring-boot-web-server/src/test/java/org/springframework/boot/web/server/reactive/context/ReactiveWebServerApplicationContextTests.java
0
spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/server/reactive/context/config/ExampleReactiveWebServerApplicationConfiguration.java → spring-boot-project/spring-boot-web-server/src/test/java/org/springframework/boot/web/server/reactive/context/config/ExampleReactiveWebServerApplicationConfiguration.java
0
spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/server/reactive/context/config/ExampleReactiveWebServerApplicationConfiguration.java → spring-boot-project/spring-boot-web-server/src/test/java/org/springframework/boot/web/server/reactive/context/config/ExampleReactiveWebServerApplicationConfiguration.java
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue