Skip to content

Commit 553311c

Browse files
committed
Merge branch '2.1.x' into 2.2.x
Closes gh-19970
2 parents b420bdb + 140f5e7 commit 553311c

File tree

2 files changed

+30
-4
lines changed

2 files changed

+30
-4
lines changed

spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/embedded/jetty/JettyWebServer.java

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2019 the original author or authors.
2+
* Copyright 2012-2020 the original author or authors.
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.
@@ -20,6 +20,7 @@
2020
import java.net.BindException;
2121
import java.util.Arrays;
2222
import java.util.List;
23+
import java.util.Objects;
2324
import java.util.stream.Collectors;
2425

2526
import org.apache.commons.logging.Log;
@@ -206,8 +207,18 @@ private String getProtocols(Connector connector) {
206207
}
207208

208209
private String getContextPath() {
209-
return Arrays.stream(this.server.getHandlers()).filter(ContextHandler.class::isInstance)
210-
.map(ContextHandler.class::cast).map(ContextHandler::getContextPath).collect(Collectors.joining(" "));
210+
return Arrays.stream(this.server.getHandlers()).map(this::findContextHandler).filter(Objects::nonNull)
211+
.map(ContextHandler::getContextPath).collect(Collectors.joining(" "));
212+
}
213+
214+
private ContextHandler findContextHandler(Handler handler) {
215+
while (handler instanceof HandlerWrapper) {
216+
if (handler instanceof ContextHandler) {
217+
return (ContextHandler) handler;
218+
}
219+
handler = ((HandlerWrapper) handler).getHandler();
220+
}
221+
return null;
211222
}
212223

213224
private void handleDeferredInitialize(Handler... handlers) throws Exception {

spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/embedded/jetty/AbstractJettyServletWebServerFactoryTests.java

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2019 the original author or authors.
2+
* Copyright 2012-2020 the original author or authors.
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.
@@ -24,7 +24,10 @@
2424
import org.eclipse.jetty.server.ServerConnector;
2525
import org.eclipse.jetty.servlet.ServletHolder;
2626
import org.eclipse.jetty.webapp.WebAppContext;
27+
import org.junit.jupiter.api.Test;
2728

29+
import org.springframework.boot.testsupport.system.CapturedOutput;
30+
import org.springframework.boot.web.server.Compression;
2831
import org.springframework.boot.web.server.PortInUseException;
2932
import org.springframework.boot.web.servlet.server.AbstractServletWebServerFactory;
3033
import org.springframework.boot.web.servlet.server.AbstractServletWebServerFactoryTests;
@@ -88,4 +91,16 @@ protected void handleExceptionCausedByBlockedPortOnSecondaryConnector(RuntimeExc
8891
this.handleExceptionCausedByBlockedPortOnPrimaryConnector(ex, blockedPort);
8992
}
9093

94+
@Test
95+
void contextPathIsLoggedOnStartupWhenCompressionIsEnabled(CapturedOutput output) {
96+
AbstractServletWebServerFactory factory = getFactory();
97+
factory.setContextPath("/custom");
98+
Compression compression = new Compression();
99+
compression.setEnabled(true);
100+
factory.setCompression(compression);
101+
this.webServer = factory.getWebServer(exampleServletRegistration());
102+
this.webServer.start();
103+
assertThat(output).containsOnlyOnce("with context path '/custom'");
104+
}
105+
91106
}

0 commit comments

Comments
 (0)