use of org.springframework.boot.web.context.ServerPortInfoApplicationContextInitializer in project spring-boot by spring-projects.
the class ServletComponentScanIntegrationTests method multipartConfigIsHonoured.
@Test
public void multipartConfigIsHonoured() {
this.context = new AnnotationConfigServletWebServerApplicationContext();
this.context.register(TestConfiguration.class);
new ServerPortInfoApplicationContextInitializer().initialize(this.context);
this.context.refresh();
@SuppressWarnings("rawtypes") Map<String, ServletRegistrationBean> beans = this.context.getBeansOfType(ServletRegistrationBean.class);
ServletRegistrationBean<?> servletRegistrationBean = beans.get(TestMultipartServlet.class.getName());
assertThat(servletRegistrationBean).isNotNull();
MultipartConfigElement multipartConfig = servletRegistrationBean.getMultipartConfig();
assertThat(multipartConfig).isNotNull();
assertThat(multipartConfig.getLocation()).isEqualTo("test");
assertThat(multipartConfig.getMaxRequestSize()).isEqualTo(2048);
assertThat(multipartConfig.getMaxFileSize()).isEqualTo(1024);
assertThat(multipartConfig.getFileSizeThreshold()).isEqualTo(512);
}
use of org.springframework.boot.web.context.ServerPortInfoApplicationContextInitializer in project spring-boot by spring-projects.
the class ReactiveWebServerApplicationContextTests method whenContextIsRefreshedThenLocalServerPortIsAvailableFromTheEnvironment.
@Test
void whenContextIsRefreshedThenLocalServerPortIsAvailableFromTheEnvironment() {
addWebServerFactoryBean();
addHttpHandlerBean();
new ServerPortInfoApplicationContextInitializer().initialize(this.context);
this.context.refresh();
ConfigurableEnvironment environment = this.context.getEnvironment();
assertThat(environment.containsProperty("local.server.port")).isTrue();
assertThat(environment.getProperty("local.server.port")).isEqualTo("8080");
}
use of org.springframework.boot.web.context.ServerPortInfoApplicationContextInitializer in project spring-boot by spring-projects.
the class ServletComponentScanIntegrationTests method indexedComponentsAreRegistered.
@ParameterizedTest(name = "{0}")
@MethodSource("testConfiguration")
void indexedComponentsAreRegistered(String serverName, Class<?> configuration) throws IOException {
writeIndex(this.temp);
this.context = new AnnotationConfigServletWebServerApplicationContext();
try (URLClassLoader classLoader = new URLClassLoader(new URL[] { this.temp.toURI().toURL() }, getClass().getClassLoader())) {
this.context.setClassLoader(classLoader);
this.context.register(configuration);
new ServerPortInfoApplicationContextInitializer().initialize(this.context);
this.context.refresh();
String port = this.context.getEnvironment().getProperty("local.server.port");
String response = new RestTemplate().getForObject("http://localhost:" + port + "/test", String.class);
assertThat(response).isEqualTo("alpha bravo charlie");
}
}
use of org.springframework.boot.web.context.ServerPortInfoApplicationContextInitializer in project spring-boot by spring-projects.
the class WebSocketMessagingAutoConfigurationTests method performStompSubscription.
private Object performStompSubscription(String topic) throws Throwable {
TestPropertyValues.of("server.port:0", "spring.jackson.serialization.indent-output:true").applyTo(this.context);
this.context.register(WebSocketMessagingConfiguration.class);
new ServerPortInfoApplicationContextInitializer().initialize(this.context);
this.context.refresh();
WebSocketStompClient stompClient = new WebSocketStompClient(this.sockJsClient);
final AtomicReference<Throwable> failure = new AtomicReference<>();
final AtomicReference<Object> result = new AtomicReference<>();
final CountDownLatch latch = new CountDownLatch(1);
StompSessionHandler handler = new StompSessionHandlerAdapter() {
@Override
public void afterConnected(StompSession session, StompHeaders connectedHeaders) {
session.subscribe(topic, new StompFrameHandler() {
@Override
public void handleFrame(StompHeaders headers, Object payload) {
result.set(payload);
latch.countDown();
}
@Override
public Type getPayloadType(StompHeaders headers) {
return Object.class;
}
});
}
@Override
public void handleFrame(StompHeaders headers, Object payload) {
latch.countDown();
}
@Override
public void handleException(StompSession session, StompCommand command, StompHeaders headers, byte[] payload, Throwable exception) {
failure.set(exception);
latch.countDown();
}
@Override
public void handleTransportError(StompSession session, Throwable exception) {
failure.set(exception);
latch.countDown();
}
};
stompClient.setMessageConverter(new SimpleMessageConverter());
stompClient.connect("ws://localhost:{port}/messaging", handler, this.context.getEnvironment().getProperty("local.server.port"));
if (!latch.await(30, TimeUnit.SECONDS)) {
if (failure.get() != null) {
throw failure.get();
}
fail("Response was not received within 30 seconds");
}
return result.get();
}
use of org.springframework.boot.web.context.ServerPortInfoApplicationContextInitializer in project spring-boot by spring-projects.
the class EndpointWebMvcAutoConfigurationTests method portPropertiesOnDifferentPort.
@Test
public void portPropertiesOnDifferentPort() throws Exception {
EnvironmentTestUtils.addEnvironment(this.applicationContext, "management.port=" + ports.get().management);
new ServerPortInfoApplicationContextInitializer().initialize(this.applicationContext);
this.applicationContext.register(RootConfig.class, DifferentPortConfig.class, BaseConfiguration.class, EndpointWebMvcAutoConfiguration.class, ErrorMvcAutoConfiguration.class);
this.applicationContext.refresh();
Integer localServerPort = this.applicationContext.getEnvironment().getProperty("local.server.port", Integer.class);
Integer localManagementPort = this.applicationContext.getEnvironment().getProperty("local.management.port", Integer.class);
assertThat(localServerPort).isNotNull();
assertThat(localManagementPort).isNotNull();
assertThat(localServerPort).isNotEqualTo(localManagementPort);
}
Aggregations