Skip to content

Commit 38c79d3

Browse files
authored
Merge pull request #2137 from matdue/switch-to-tomcat
Use Tomcat instead of Jetty
2 parents f340beb + 39b4154 commit 38c79d3

File tree

6 files changed

+23
-54
lines changed

6 files changed

+23
-54
lines changed

integration-tests/src/test/kotlin/com/adobe/testing/s3mock/its/PlainHttpIT.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ internal class PlainHttpIT : S3TestBase() {
100100
fun putHeadObject_withUserMetadata(testInfo: TestInfo) {
101101
val targetBucket = givenBucketV2(testInfo)
102102
val byteArray = UUID.randomUUID().toString().toByteArray()
103-
val amzMetaHeaderKey = "X-Amz-Meta-My-Key"
103+
val amzMetaHeaderKey = "x-amz-meta-my-key"
104104
val amzMetaHeaderValue = "MY_DATA"
105105
val putObject = HttpPut("/$targetBucket/testObjectName").apply {
106106
this.entity = ByteArrayEntity(byteArray)

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@
128128
<!-- Run Docker build by default -->
129129
<skipDocker>false</skipDocker>
130130
<sortpom-maven-plugin.version>4.0.0</sortpom-maven-plugin.version>
131-
<spring-boot.version>3.3.3</spring-boot.version>
131+
<spring-boot.version>3.3.5</spring-boot.version>
132132
<testcontainers.version>1.20.4</testcontainers.version>
133133
<testng.version>7.10.2</testng.version>
134134
<xmlunit-assertj3.version>2.10.0</xmlunit-assertj3.version>

server/pom.xml

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -110,11 +110,6 @@
110110
<artifactId>spring-boot-devtools</artifactId>
111111
<optional>true</optional>
112112
</dependency>
113-
<!-- Use Jetty instead of tomcat -->
114-
<dependency>
115-
<groupId>org.springframework.boot</groupId>
116-
<artifactId>spring-boot-starter-jetty</artifactId>
117-
</dependency>
118113
<dependency>
119114
<groupId>org.springframework.boot</groupId>
120115
<artifactId>spring-boot-starter-test</artifactId>
@@ -123,12 +118,6 @@
123118
<dependency>
124119
<groupId>org.springframework.boot</groupId>
125120
<artifactId>spring-boot-starter-web</artifactId>
126-
<exclusions>
127-
<exclusion>
128-
<groupId>org.springframework.boot</groupId>
129-
<artifactId>spring-boot-starter-tomcat</artifactId>
130-
</exclusion>
131-
</exclusions>
132121
</dependency>
133122
<dependency>
134123
<groupId>org.xmlunit</groupId>

server/src/main/java/com/adobe/testing/s3mock/S3MockApplication.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2017-2023 Adobe.
2+
* Copyright 2017-2024 Adobe.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -283,7 +283,7 @@ public int getPort() {
283283
*/
284284
@Deprecated(since = "2.12.2", forRemoval = true)
285285
public int getHttpPort() {
286-
return config.getHttpServerConnector().getLocalPort();
286+
return config.getHttpConnector().getLocalPort();
287287
}
288288

289289
/**

server/src/main/java/com/adobe/testing/s3mock/S3MockConfiguration.java

Lines changed: 17 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -31,18 +31,12 @@
3131
import jakarta.servlet.Filter;
3232
import jakarta.servlet.http.HttpServletRequest;
3333
import java.util.ArrayList;
34-
import java.util.Arrays;
35-
import java.util.Objects;
36-
import org.eclipse.jetty.http.UriCompliance;
37-
import org.eclipse.jetty.server.Connector;
38-
import org.eclipse.jetty.server.HttpConnectionFactory;
39-
import org.eclipse.jetty.server.SecureRequestCustomizer;
40-
import org.eclipse.jetty.server.Server;
41-
import org.eclipse.jetty.server.ServerConnector;
34+
import org.apache.catalina.connector.Connector;
35+
import org.apache.tomcat.util.buf.EncodedSolidusHandling;
4236
import org.slf4j.Logger;
4337
import org.slf4j.LoggerFactory;
4438
import org.springframework.boot.context.properties.EnableConfigurationProperties;
45-
import org.springframework.boot.web.embedded.jetty.JettyServletWebServerFactory;
39+
import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory;
4640
import org.springframework.boot.web.servlet.filter.OrderedFormContentFilter;
4741
import org.springframework.boot.web.servlet.server.ServletWebServerFactory;
4842
import org.springframework.context.annotation.Bean;
@@ -63,7 +57,7 @@
6357
@Configuration
6458
@EnableConfigurationProperties(S3MockProperties.class)
6559
public class S3MockConfiguration implements WebMvcConfigurer {
66-
private ServerConnector httpServerConnector;
60+
private Connector httpConnector;
6761

6862
/**
6963
* Create a ServletWebServerFactory bean reconfigured for an additional HTTP port.
@@ -72,37 +66,24 @@ public class S3MockConfiguration implements WebMvcConfigurer {
7266
*/
7367
@Bean
7468
ServletWebServerFactory webServerFactory(S3MockProperties properties) {
75-
var factory = new JettyServletWebServerFactory();
76-
factory.addServerCustomizers(
77-
server -> server.addConnector(createHttpConnector(server, properties.httpPort())),
78-
server -> Arrays.stream(server.getConnectors())
79-
.filter(ServerConnector.class::isInstance)
80-
.forEach(
81-
connector -> connector.getConnectionFactories()
82-
.stream()
83-
.filter(HttpConnectionFactory.class::isInstance)
84-
.map(cf -> (HttpConnectionFactory) cf)
85-
.map(HttpConnectionFactory::getHttpConfiguration)
86-
.map(hc -> {
87-
//disable UriCompliance checks. S3 allows object keys that do not conform to
88-
//URI specs as defined here: https://datatracker.ietf.org/doc/html/rfc3986
89-
hc.setUriCompliance(UriCompliance.UNSAFE);
90-
return hc.getCustomizer(SecureRequestCustomizer.class);
91-
})
92-
.filter(Objects::nonNull)
93-
.forEach(customizer -> customizer.setSniHostCheck(false))
94-
));
69+
var factory = new TomcatServletWebServerFactory();
70+
factory.addAdditionalTomcatConnectors(createHttpConnector(properties.httpPort()));
71+
factory.addConnectorCustomizers(connector -> {
72+
// Allow encoded slashes in URL
73+
connector.setEncodedSolidusHandling(EncodedSolidusHandling.DECODE.getValue());
74+
connector.setAllowBackslash(true);
75+
});
9576
return factory;
9677
}
9778

98-
private Connector createHttpConnector(final Server server, int httpPort) {
99-
httpServerConnector = new ServerConnector(server);
100-
httpServerConnector.setPort(httpPort);
101-
return httpServerConnector;
79+
private Connector createHttpConnector(int httpPort) {
80+
httpConnector = new Connector();
81+
httpConnector.setPort(httpPort);
82+
return httpConnector;
10283
}
10384

104-
ServerConnector getHttpServerConnector() {
105-
return httpServerConnector;
85+
Connector getHttpConnector() {
86+
return httpConnector;
10687
}
10788

10889
@Bean

server/src/main/resources/application.properties

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#
2-
# Copyright 2017-2022 Adobe.
2+
# Copyright 2017-2024 Adobe.
33
#
44
# Licensed under the Apache License, Version 2.0 (the "License");
55
# you may not use this file except in compliance with the License.
@@ -15,10 +15,9 @@
1515
#
1616

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

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

2322
# deactivate JMX to save resources and startup time
2423
spring.jmx.enabled=false

0 commit comments

Comments
 (0)