Skip to content

Commit aa9945c

Browse files
committed
Upgrade to Jetty 9.4.14.v20181114
Closes gh-15239
1 parent bb40e2e commit aa9945c

File tree

3 files changed

+37
-45
lines changed

3 files changed

+37
-45
lines changed

spring-boot-dependencies/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@
111111
<jedis.version>2.9.0</jedis.version>
112112
<jersey.version>2.25.1</jersey.version>
113113
<jest.version>2.0.4</jest.version>
114-
<jetty.version>9.4.12.v20180830</jetty.version>
114+
<jetty.version>9.4.14.v20181114</jetty.version>
115115
<jetty-jsp.version>2.2.0.v201112011158</jetty-jsp.version>
116116
<jetty-el.version>8.0.33</jetty-el.version>
117117
<jms-api.version>1.1-rev-1</jms-api.version>

spring-boot/src/main/java/org/springframework/boot/context/embedded/jetty/JettyEmbeddedServletContainer.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
package org.springframework.boot.context.embedded.jetty;
1818

19+
import java.io.IOException;
1920
import java.net.BindException;
2021
import java.util.List;
2122

@@ -142,8 +143,9 @@ public void start() throws EmbeddedServletContainerException {
142143
try {
143144
connector.start();
144145
}
145-
catch (BindException ex) {
146-
if (connector instanceof NetworkConnector) {
146+
catch (IOException ex) {
147+
if (connector instanceof NetworkConnector
148+
&& findBindException(ex) != null) {
147149
throw new PortInUseException(
148150
((NetworkConnector) connector).getPort());
149151
}
@@ -166,6 +168,16 @@ public void start() throws EmbeddedServletContainerException {
166168
}
167169
}
168170

171+
private BindException findBindException(Throwable ex) {
172+
if (ex == null) {
173+
return null;
174+
}
175+
if (ex instanceof BindException) {
176+
return (BindException) ex;
177+
}
178+
return findBindException(ex.getCause());
179+
}
180+
169181
private String getActualPortsDescription() {
170182
StringBuilder ports = new StringBuilder();
171183
for (Connector connector : this.server.getConnectors()) {

spring-boot/src/main/java/org/springframework/boot/context/embedded/jetty/ServletContextInitializerConfiguration.java

Lines changed: 22 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818

1919
import javax.servlet.ServletException;
2020

21-
import org.eclipse.jetty.util.component.AbstractLifeCycle;
2221
import org.eclipse.jetty.webapp.AbstractConfiguration;
2322
import org.eclipse.jetty.webapp.Configuration;
2423
import org.eclipse.jetty.webapp.WebAppContext;
@@ -49,54 +48,35 @@ public ServletContextInitializerConfiguration(
4948

5049
@Override
5150
public void configure(WebAppContext context) throws Exception {
52-
context.addBean(new Initializer(context), true);
53-
}
54-
55-
/**
56-
* Jetty {@link AbstractLifeCycle} to call the {@link ServletContextInitializer
57-
* ServletContextInitializers}.
58-
*/
59-
private class Initializer extends AbstractLifeCycle {
60-
61-
private final WebAppContext context;
62-
63-
Initializer(WebAppContext context) {
64-
this.context = context;
51+
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
52+
Thread.currentThread().setContextClassLoader(context.getClassLoader());
53+
try {
54+
callInitializers(context);
6555
}
66-
67-
@Override
68-
protected void doStart() throws Exception {
69-
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
70-
Thread.currentThread().setContextClassLoader(this.context.getClassLoader());
71-
try {
72-
callInitializers();
73-
}
74-
finally {
75-
Thread.currentThread().setContextClassLoader(classLoader);
76-
}
56+
finally {
57+
Thread.currentThread().setContextClassLoader(classLoader);
7758
}
59+
}
7860

79-
private void callInitializers() throws ServletException {
80-
try {
81-
setExtendedListenerTypes(true);
82-
for (ServletContextInitializer initializer : ServletContextInitializerConfiguration.this.initializers) {
83-
initializer.onStartup(this.context.getServletContext());
84-
}
85-
}
86-
finally {
87-
setExtendedListenerTypes(false);
61+
private void callInitializers(WebAppContext context) throws ServletException {
62+
try {
63+
setExtendedListenerTypes(context, true);
64+
for (ServletContextInitializer initializer : this.initializers) {
65+
initializer.onStartup(context.getServletContext());
8866
}
8967
}
90-
91-
private void setExtendedListenerTypes(boolean extended) {
92-
try {
93-
this.context.getServletContext().setExtendedListenerTypes(extended);
94-
}
95-
catch (NoSuchMethodError ex) {
96-
// Not available on Jetty 8
97-
}
68+
finally {
69+
setExtendedListenerTypes(context, false);
9870
}
71+
}
9972

73+
private void setExtendedListenerTypes(WebAppContext context, boolean extended) {
74+
try {
75+
context.getServletContext().setExtendedListenerTypes(extended);
76+
}
77+
catch (NoSuchMethodError ex) {
78+
// Not available on Jetty 8
79+
}
10080
}
10181

10282
}

0 commit comments

Comments
 (0)