Skip to content

Commit

Permalink
Merge pull request #2137 from matdue/switch-to-tomcat
Browse files Browse the repository at this point in the history
Use Tomcat instead of Jetty
  • Loading branch information
afranken authored Dec 7, 2024
2 parents f340beb + 39b4154 commit 38c79d3
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ internal class PlainHttpIT : S3TestBase() {
fun putHeadObject_withUserMetadata(testInfo: TestInfo) {
val targetBucket = givenBucketV2(testInfo)
val byteArray = UUID.randomUUID().toString().toByteArray()
val amzMetaHeaderKey = "X-Amz-Meta-My-Key"
val amzMetaHeaderKey = "x-amz-meta-my-key"
val amzMetaHeaderValue = "MY_DATA"
val putObject = HttpPut("/$targetBucket/testObjectName").apply {
this.entity = ByteArrayEntity(byteArray)
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@
<!-- Run Docker build by default -->
<skipDocker>false</skipDocker>
<sortpom-maven-plugin.version>4.0.0</sortpom-maven-plugin.version>
<spring-boot.version>3.3.3</spring-boot.version>
<spring-boot.version>3.3.5</spring-boot.version>
<testcontainers.version>1.20.4</testcontainers.version>
<testng.version>7.10.2</testng.version>
<xmlunit-assertj3.version>2.10.0</xmlunit-assertj3.version>
Expand Down
11 changes: 0 additions & 11 deletions server/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,6 @@
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional>
</dependency>
<!-- Use Jetty instead of tomcat -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jetty</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
Expand All @@ -123,12 +118,6 @@
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.xmlunit</groupId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2017-2023 Adobe.
* Copyright 2017-2024 Adobe.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -283,7 +283,7 @@ public int getPort() {
*/
@Deprecated(since = "2.12.2", forRemoval = true)
public int getHttpPort() {
return config.getHttpServerConnector().getLocalPort();
return config.getHttpConnector().getLocalPort();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,12 @@
import jakarta.servlet.Filter;
import jakarta.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Objects;
import org.eclipse.jetty.http.UriCompliance;
import org.eclipse.jetty.server.Connector;
import org.eclipse.jetty.server.HttpConnectionFactory;
import org.eclipse.jetty.server.SecureRequestCustomizer;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.ServerConnector;
import org.apache.catalina.connector.Connector;
import org.apache.tomcat.util.buf.EncodedSolidusHandling;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.boot.web.embedded.jetty.JettyServletWebServerFactory;
import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory;
import org.springframework.boot.web.servlet.filter.OrderedFormContentFilter;
import org.springframework.boot.web.servlet.server.ServletWebServerFactory;
import org.springframework.context.annotation.Bean;
Expand All @@ -63,7 +57,7 @@
@Configuration
@EnableConfigurationProperties(S3MockProperties.class)
public class S3MockConfiguration implements WebMvcConfigurer {
private ServerConnector httpServerConnector;
private Connector httpConnector;

/**
* Create a ServletWebServerFactory bean reconfigured for an additional HTTP port.
Expand All @@ -72,37 +66,24 @@ public class S3MockConfiguration implements WebMvcConfigurer {
*/
@Bean
ServletWebServerFactory webServerFactory(S3MockProperties properties) {
var factory = new JettyServletWebServerFactory();
factory.addServerCustomizers(
server -> server.addConnector(createHttpConnector(server, properties.httpPort())),
server -> Arrays.stream(server.getConnectors())
.filter(ServerConnector.class::isInstance)
.forEach(
connector -> connector.getConnectionFactories()
.stream()
.filter(HttpConnectionFactory.class::isInstance)
.map(cf -> (HttpConnectionFactory) cf)
.map(HttpConnectionFactory::getHttpConfiguration)
.map(hc -> {
//disable UriCompliance checks. S3 allows object keys that do not conform to
//URI specs as defined here: https://datatracker.ietf.org/doc/html/rfc3986
hc.setUriCompliance(UriCompliance.UNSAFE);
return hc.getCustomizer(SecureRequestCustomizer.class);
})
.filter(Objects::nonNull)
.forEach(customizer -> customizer.setSniHostCheck(false))
));
var factory = new TomcatServletWebServerFactory();
factory.addAdditionalTomcatConnectors(createHttpConnector(properties.httpPort()));
factory.addConnectorCustomizers(connector -> {
// Allow encoded slashes in URL
connector.setEncodedSolidusHandling(EncodedSolidusHandling.DECODE.getValue());
connector.setAllowBackslash(true);
});
return factory;
}

private Connector createHttpConnector(final Server server, int httpPort) {
httpServerConnector = new ServerConnector(server);
httpServerConnector.setPort(httpPort);
return httpServerConnector;
private Connector createHttpConnector(int httpPort) {
httpConnector = new Connector();
httpConnector.setPort(httpPort);
return httpConnector;
}

ServerConnector getHttpServerConnector() {
return httpServerConnector;
Connector getHttpConnector() {
return httpConnector;
}

@Bean
Expand Down
5 changes: 2 additions & 3 deletions server/src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Copyright 2017-2022 Adobe.
# Copyright 2017-2024 Adobe.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -15,10 +15,9 @@
#

# server.ssl.* are moved to S3MockApplication#start so users can override them
# The values in application.properties can't be overriden by SpringApplicationBuilder#properties
# The values in application.properties can't be overridden by SpringApplicationBuilder#properties

logging.level.org.springframework.web.servlet.mvc.method.annotation.ExceptionHandlerExceptionResolver=ERROR
logging.level.org.eclipse.jetty.util.ssl.SslContextFactory.config=ERROR

# deactivate JMX to save resources and startup time
spring.jmx.enabled=false
Expand Down

0 comments on commit 38c79d3

Please sign in to comment.