Commit 68aec8b6 authored by Phillip Webb's avatar Phillip Webb

Polish

parent 23a923d1
......@@ -90,7 +90,8 @@ import org.springframework.core.env.Environment;
* @author Stephane Nicoll
* @since 2.0.0
* @see Endpoint
* @deprecated as of 2.2.0 in favor of {@link ConditionalOnAvailableEndpoint}
* @deprecated as of 2.2.0 in favor of
* {@link ConditionalOnAvailableEndpoint @ConditionalOnAvailableEndpoint}
*/
@Retention(RetentionPolicy.RUNTIME)
@Target({ ElementType.METHOD, ElementType.TYPE })
......
......@@ -31,7 +31,6 @@ import org.springframework.boot.autoconfigure.data.neo4j.Neo4jDataAutoConfigurat
import org.springframework.boot.autoconfigure.data.neo4j.Neo4jRepositoriesAutoConfiguration;
import org.springframework.boot.autoconfigure.data.redis.RedisAutoConfiguration;
import org.springframework.boot.autoconfigure.data.redis.RedisRepositoriesAutoConfiguration;
import org.springframework.boot.autoconfigure.elasticsearch.jest.JestAutoConfiguration;
import org.springframework.boot.autoconfigure.flyway.FlywayAutoConfiguration;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.test.util.ApplicationContextTestUtils;
......@@ -73,8 +72,7 @@ public class SpringApplicationHierarchyTests {
MongoDataAutoConfiguration.class, MongoReactiveDataAutoConfiguration.class,
Neo4jDataAutoConfiguration.class, Neo4jRepositoriesAutoConfiguration.class,
RedisAutoConfiguration.class, RedisRepositoriesAutoConfiguration.class,
FlywayAutoConfiguration.class, JestAutoConfiguration.class,
MetricsAutoConfiguration.class },
FlywayAutoConfiguration.class, MetricsAutoConfiguration.class },
excludeName = {
"org.springframework.boot.autoconfigure.data.elasticsearch.ElasticsearchAutoConfiguration" })
public static class Child {
......@@ -87,8 +85,7 @@ public class SpringApplicationHierarchyTests {
MongoDataAutoConfiguration.class, MongoReactiveDataAutoConfiguration.class,
Neo4jDataAutoConfiguration.class, Neo4jRepositoriesAutoConfiguration.class,
RedisAutoConfiguration.class, RedisRepositoriesAutoConfiguration.class,
FlywayAutoConfiguration.class, JestAutoConfiguration.class,
MetricsAutoConfiguration.class },
FlywayAutoConfiguration.class, MetricsAutoConfiguration.class },
excludeName = {
"org.springframework.boot.autoconfigure.data.elasticsearch.ElasticsearchAutoConfiguration" })
public static class Parent {
......
......@@ -35,6 +35,7 @@ import static org.assertj.core.api.Assertions.assertThat;
* @author Andy Wilkinson
*/
@Deprecated
@SuppressWarnings("deprecation")
public class ConditionalOnEnabledEndpointTests {
private final ApplicationContextRunner contextRunner = new ApplicationContextRunner();
......
......@@ -54,14 +54,6 @@ public final class Autotime {
? percentiles.stream().mapToDouble(Double::doubleValue).toArray() : null;
}
/**
* Create an instance that disable auto-timed requests.
* @return an instance that disable auto-timed requests
*/
public static Autotime disabled() {
return new Autotime(false, false, null);
}
public boolean isEnabled() {
return this.enabled;
}
......@@ -86,4 +78,12 @@ public final class Autotime {
this.percentiles = percentiles;
}
/**
* Create an instance that disable auto-timed requests.
* @return an instance that disable auto-timed requests
*/
public static Autotime disabled() {
return new Autotime(false, false, null);
}
}
......@@ -75,6 +75,8 @@ public class RSocketStrategiesAutoConfiguration {
@ConditionalOnClass({ ObjectMapper.class, CBORFactory.class })
protected static class JacksonCborStrategyConfiguration {
private static final MediaType[] SUPPORTED_TYPES = { MediaType.APPLICATION_CBOR };
@Bean
@Order(0)
@ConditionalOnBean(Jackson2ObjectMapperBuilder.class)
......@@ -82,10 +84,8 @@ public class RSocketStrategiesAutoConfiguration {
Jackson2ObjectMapperBuilder builder) {
return (strategy) -> {
ObjectMapper objectMapper = builder.factory(new CBORFactory()).build();
MediaType[] supportedTypes = new MediaType[] {
MediaType.APPLICATION_CBOR };
strategy.decoder(new Jackson2CborDecoder(objectMapper, supportedTypes));
strategy.encoder(new Jackson2CborEncoder(objectMapper, supportedTypes));
strategy.decoder(new Jackson2CborDecoder(objectMapper, SUPPORTED_TYPES));
strategy.encoder(new Jackson2CborEncoder(objectMapper, SUPPORTED_TYPES));
};
}
......@@ -95,16 +95,17 @@ public class RSocketStrategiesAutoConfiguration {
@ConditionalOnClass(ObjectMapper.class)
protected static class JacksonJsonStrategyConfiguration {
private static final MediaType[] SUPPORTED_TYPES = { MediaType.APPLICATION_JSON,
new MediaType("application", "*+json") };
@Bean
@Order(1)
@ConditionalOnBean(ObjectMapper.class)
public RSocketStrategiesCustomizer jacksonJsonStrategyCustomizer(
ObjectMapper objectMapper) {
return (strategy) -> {
MediaType[] supportedTypes = new MediaType[] { MediaType.APPLICATION_JSON,
new MediaType("application", "*+json") };
strategy.decoder(new Jackson2JsonDecoder(objectMapper, supportedTypes));
strategy.encoder(new Jackson2JsonEncoder(objectMapper, supportedTypes));
strategy.decoder(new Jackson2JsonDecoder(objectMapper, SUPPORTED_TYPES));
strategy.encoder(new Jackson2JsonEncoder(objectMapper, SUPPORTED_TYPES));
};
}
......
......@@ -25,7 +25,7 @@ import org.springframework.boot.testsupport.assertj.Matched;
import org.springframework.http.CacheControl;
import static org.assertj.core.api.Assertions.assertThat;
import static org.hamcrest.CoreMatchers.endsWith;
import static org.hamcrest.Matchers.endsWith;
/**
* Tests for {@link ResourceProperties}.
......
......@@ -20,7 +20,6 @@ import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.TimeZone;
import org.eclipse.jetty.server.Connector;
import org.eclipse.jetty.server.CustomRequestLog;
......@@ -88,7 +87,6 @@ public class JettyWebServerFactoryCustomizerTests {
@Test
public void accessLogCanBeCustomized() throws IOException {
File logFile = File.createTempFile("jetty_log", ".log");
String timezone = TimeZone.getDefault().getID();
bind("server.jetty.accesslog.enabled=true",
"server.jetty.accesslog.format=extended_ncsa",
"server.jetty.accesslog.filename="
......
......@@ -46,8 +46,7 @@ public class ClientHttpConnectorConfigurationTests {
jettyResourceFactory.setExecutor(executor);
jettyResourceFactory.setByteBufferPool(byteBufferPool);
jettyResourceFactory.setScheduler(scheduler);
JettyClientHttpConnector connector = new ClientHttpConnectorConfiguration.JettyClient()
.jettyClientHttpConnector(jettyResourceFactory);
JettyClientHttpConnector connector = getClientHttpConnector(jettyResourceFactory);
HttpClient httpClient = (HttpClient) ReflectionTestUtils.getField(connector,
"httpClient");
assertThat(httpClient.getExecutor()).isSameAs(executor);
......@@ -59,11 +58,18 @@ public class ClientHttpConnectorConfigurationTests {
public void JettyResourceFactoryHasSslContextFactory() {
// gh-16810
JettyResourceFactory jettyResourceFactory = new JettyResourceFactory();
JettyClientHttpConnector connector = new ClientHttpConnectorConfiguration.JettyClient()
.jettyClientHttpConnector(jettyResourceFactory);
JettyClientHttpConnector connector = getClientHttpConnector(jettyResourceFactory);
HttpClient httpClient = (HttpClient) ReflectionTestUtils.getField(connector,
"httpClient");
assertThat(httpClient.getSslContextFactory()).isNotNull();
}
private JettyClientHttpConnector getClientHttpConnector(
JettyResourceFactory jettyResourceFactory) {
ClientHttpConnectorConfiguration.JettyClient jettyClient = new ClientHttpConnectorConfiguration.JettyClient();
// We shouldn't usually call this method directly since it's on a non-proxy config
return ReflectionTestUtils.invokeMethod(jettyClient, "jettyClientHttpConnector",
jettyResourceFactory);
}
}
......@@ -63,7 +63,8 @@ import static org.springframework.test.web.servlet.request.MockMvcRequestBuilder
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
/**
* Tests for {@link BasicErrorController} using {@link MockMvc} and {@link SpringRunner}.
* Tests for {@link BasicErrorController} using {@link MockMvc} and
* {@link SpringBootTest @SpringBootTest}.
*
* @author Dave Syer
*/
......
......@@ -133,8 +133,10 @@ public class WebSocketMessagingAutoConfigurationTests {
@SuppressWarnings("unchecked")
private List<MessageConverter> getDefaultConverters() {
CompositeMessageConverter compositeDefaultConverter = new DelegatingWebSocketMessageBrokerConfiguration()
.brokerMessageConverter();
DelegatingWebSocketMessageBrokerConfiguration configuration = new DelegatingWebSocketMessageBrokerConfiguration();
// We shouldn't usually call this method directly since it's on a non-proxy config
CompositeMessageConverter compositeDefaultConverter = ReflectionTestUtils
.invokeMethod(configuration, "brokerMessageConverter");
return (List<MessageConverter>) ReflectionTestUtils
.getField(compositeDefaultConverter, "converters");
}
......
......@@ -3379,6 +3379,8 @@ NOTE: `TomcatServletWebServerFactory`, `JettyServletWebServerFactory` and `Under
are dedicated variants of `ConfigurableServletWebServerFactory` that have additional customization setter methods
for Tomcat, Jetty and Undertow respectively.
[[boot-features-customizing-configurableservletwebserverfactory-directly]]
===== Customizing ConfigurableServletWebServerFactory Directly
If the preceding customization techniques are too limited, you can register the
......@@ -3403,6 +3405,7 @@ are also provided should you need to do something more exotic. See the
code documentation] for details.
[[boot-features-jsp-limitations]]
==== JSP Limitations
When running a Spring Boot application that uses an embedded servlet container (and is
......@@ -3422,17 +3425,19 @@ instead.
There is a {github-code}/spring-boot-samples/spring-boot-sample-web-jsp[JSP sample] so
that you can see how to set things up.
[[boot-features-reactive-server]]
=== Embedded Reactive Server Support
Spring Boot includes support for the following embedded reactive web servers:
Reactor Netty, Tomcat, Jetty, and Undertow. Most developers use the appropriate “Starter”
to obtain a fully configured instance. By default, the embedded server listens for HTTP
requests on port 8080.
[[boot-features-reactive-server-resources]]
=== Reactive Server Resources Configuration
When auto-configuring a Reactor Netty or Jetty server, Spring Boot will create specific
beans that will provide HTTP resources to the server instance: `ReactorResourceFactory`
or `JettyResourceFactory`.
......@@ -3451,6 +3456,8 @@ both clients and servers.
You can learn more about the resource configuration on the client side in the
<<boot-features-webclient-runtime, WebClient Runtime section>>.
[[boot-features-rsocket]]
== RSocket
......@@ -3483,6 +3490,8 @@ The following code shows a typical `@Controller`:
}
----
[[boot-features-rsocket-strategies-auto-configuration]]
=== RSocket Strategies Auto-configuration
Spring Boot auto-configures an `RSocketStrategies` bean that provides all the required
......@@ -3499,6 +3508,7 @@ implement the `RSocketStrategiesCustomizer` interface. Note that their `@Order`
important, as it determines the order of codecs.
[[boot-features-rsocket-server-auto-configuration]]
=== RSocket server Auto-configuration
Spring Boot provides auto-configuration for RSocket servers. The required dependencies
......@@ -3544,6 +3554,8 @@ about customization possibilities.
Developers can create `RSocketStrategiesCustomizer` beans to add other strategies,
assuming there are `Encoder` and `Decoder` implementations available.
[[boot-features-rsocket-requester]]
=== Calling RSocket Services with `RSocketRequester`
......@@ -3582,6 +3594,7 @@ The following code shows a typical example:
----
[[boot-features-security]]
== Security
If {spring-security}[Spring Security] is on the classpath, then web applications are
......@@ -3620,6 +3633,7 @@ the entire application (including actuator endpoints if actuator is on the class
You can provide a different `AuthenticationEventPublisher` by adding a bean for it.
[[boot-features-security-mvc]]
=== MVC Security
The default security configuration is implemented in `SecurityAutoConfiguration` and
......
......@@ -29,7 +29,7 @@ import org.springframework.boot.web.server.LocalServerPort;
import org.springframework.test.context.junit4.SpringRunner;
import static io.restassured.RestAssured.given;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.Matchers.is;
import static org.springframework.restdocs.restassured3.RestAssuredRestDocumentation.document;
@RunWith(SpringRunner.class)
......
......@@ -39,7 +39,7 @@ import org.springframework.util.FileSystemUtils;
import static io.restassured.RestAssured.given;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.contentOf;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.Matchers.is;
import static org.springframework.restdocs.operation.preprocess.Preprocessors.modifyUris;
import static org.springframework.restdocs.operation.preprocess.Preprocessors.preprocessRequest;
import static org.springframework.restdocs.payload.PayloadDocumentation.fieldWithPath;
......
......@@ -34,7 +34,7 @@ import org.springframework.util.FileSystemUtils;
import static io.restassured.RestAssured.given;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.contentOf;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.Matchers.is;
import static org.springframework.restdocs.operation.preprocess.Preprocessors.modifyUris;
import static org.springframework.restdocs.operation.preprocess.Preprocessors.preprocessRequest;
import static org.springframework.restdocs.restassured3.RestAssuredRestDocumentation.document;
......
......@@ -23,7 +23,7 @@ import org.junit.jupiter.api.extension.ExtensionContext;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Tests for {@link OutputCapture} when used via {@link ExtendWith}.
* Tests for {@link OutputCapture} when used via {@link ExtendWith @ExtendWith}.
*
* @author Madhura Bhave
*/
......
......@@ -21,7 +21,8 @@ import org.junit.jupiter.api.extension.RegisterExtension;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Tests for {@link OutputCapture} when used via {@link RegisterExtension}.
* Tests for {@link OutputCapture} when used via
* {@link RegisterExtension @RegisterExtension}.
*
* @author Madhura Bhave
*/
......
......@@ -31,7 +31,7 @@ import org.testcontainers.lifecycle.Startable;
* @author Andy Wilkinson
* @author Madhura Bhave
*/
public class SkippableContainer<T extends GenericContainer> implements Startable {
public class SkippableContainer<T extends GenericContainer<?>> implements Startable {
private final Supplier<T> containerFactory;
......
......@@ -21,7 +21,7 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import static org.assertj.core.api.Assertions.assertThat;
import static org.hamcrest.CoreMatchers.isA;
import static org.hamcrest.Matchers.isA;
/**
* Tests for {@link ModifiedClassPathRunner} excluding entries from the class path.
......
......@@ -134,7 +134,7 @@ class SslServerCustomizer implements JettyServerCustomizer {
/**
* Configure the SSL connection.
* @param factory the Jetty {@link SslContextFactory.Server}.
* @param factory the Jetty {@link Server SslContextFactory.Server}.
* @param ssl the ssl details.
* @param sslStoreProvider the ssl store provider
*/
......
......@@ -19,12 +19,15 @@ package org.springframework.boot.web.embedded.netty;
import java.time.Duration;
import java.util.Collections;
import java.util.List;
import java.util.function.Predicate;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import reactor.netty.ChannelBindException;
import reactor.netty.DisposableServer;
import reactor.netty.http.server.HttpServer;
import reactor.netty.http.server.HttpServerRequest;
import reactor.netty.http.server.HttpServerRoutes;
import org.springframework.boot.web.server.PortInUseException;
import org.springframework.boot.web.server.WebServer;
......@@ -44,6 +47,8 @@ import org.springframework.util.Assert;
*/
public class NettyWebServer implements WebServer {
private static final Predicate<HttpServerRequest> ALWAYS = (r) -> true;
private static final Log logger = LogFactory.getLog(NettyWebServer.class);
private final HttpServer httpServer;
......@@ -93,10 +98,7 @@ public class NettyWebServer implements WebServer {
server = server.handle(this.handlerAdapter);
}
else {
server = server.route((routes) -> {
this.routeProviders.forEach((provider) -> provider.apply(routes));
routes.route((r) -> true, this.handlerAdapter);
});
server = server.route(this::applyRouteProviders);
}
if (this.lifecycleTimeout != null) {
return server.bindNow(this.lifecycleTimeout);
......@@ -104,6 +106,11 @@ public class NettyWebServer implements WebServer {
return server.bindNow();
}
private void applyRouteProviders(HttpServerRoutes routes) {
this.routeProviders.forEach((provider) -> provider.apply(routes));
routes.route(ALWAYS, this.handlerAdapter);
}
private ChannelBindException findBindException(Exception ex) {
Throwable candidate = ex;
while (candidate != null) {
......
......@@ -122,7 +122,7 @@ import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import static org.assertj.core.api.Assertions.assertThatIOException;
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
import static org.hamcrest.CoreMatchers.notNullValue;
import static org.hamcrest.Matchers.notNullValue;
import static org.junit.Assert.fail;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.BDDMockito.given;
......
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