Skip to content

Commit

Permalink
Upgrade to Jetty 9.4.14.v20181114
Browse files Browse the repository at this point in the history
Closes gh-15239
  • Loading branch information
wilkinsona committed Dec 20, 2018
1 parent bb40e2e commit aa9945c
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 45 deletions.
2 changes: 1 addition & 1 deletion spring-boot-dependencies/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@
<jedis.version>2.9.0</jedis.version>
<jersey.version>2.25.1</jersey.version>
<jest.version>2.0.4</jest.version>
<jetty.version>9.4.12.v20180830</jetty.version>
<jetty.version>9.4.14.v20181114</jetty.version>
<jetty-jsp.version>2.2.0.v201112011158</jetty-jsp.version>
<jetty-el.version>8.0.33</jetty-el.version>
<jms-api.version>1.1-rev-1</jms-api.version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

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

import java.io.IOException;
import java.net.BindException;
import java.util.List;

Expand Down Expand Up @@ -142,8 +143,9 @@ public void start() throws EmbeddedServletContainerException {
try {
connector.start();
}
catch (BindException ex) {
if (connector instanceof NetworkConnector) {
catch (IOException ex) {
if (connector instanceof NetworkConnector
&& findBindException(ex) != null) {
throw new PortInUseException(
((NetworkConnector) connector).getPort());
}
Expand All @@ -166,6 +168,16 @@ public void start() throws EmbeddedServletContainerException {
}
}

private BindException findBindException(Throwable ex) {
if (ex == null) {
return null;
}
if (ex instanceof BindException) {
return (BindException) ex;
}
return findBindException(ex.getCause());
}

private String getActualPortsDescription() {
StringBuilder ports = new StringBuilder();
for (Connector connector : this.server.getConnectors()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

import javax.servlet.ServletException;

import org.eclipse.jetty.util.component.AbstractLifeCycle;
import org.eclipse.jetty.webapp.AbstractConfiguration;
import org.eclipse.jetty.webapp.Configuration;
import org.eclipse.jetty.webapp.WebAppContext;
Expand Down Expand Up @@ -49,54 +48,35 @@ public ServletContextInitializerConfiguration(

@Override
public void configure(WebAppContext context) throws Exception {
context.addBean(new Initializer(context), true);
}

/**
* Jetty {@link AbstractLifeCycle} to call the {@link ServletContextInitializer
* ServletContextInitializers}.
*/
private class Initializer extends AbstractLifeCycle {

private final WebAppContext context;

Initializer(WebAppContext context) {
this.context = context;
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
Thread.currentThread().setContextClassLoader(context.getClassLoader());
try {
callInitializers(context);
}

@Override
protected void doStart() throws Exception {
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
Thread.currentThread().setContextClassLoader(this.context.getClassLoader());
try {
callInitializers();
}
finally {
Thread.currentThread().setContextClassLoader(classLoader);
}
finally {
Thread.currentThread().setContextClassLoader(classLoader);
}
}

private void callInitializers() throws ServletException {
try {
setExtendedListenerTypes(true);
for (ServletContextInitializer initializer : ServletContextInitializerConfiguration.this.initializers) {
initializer.onStartup(this.context.getServletContext());
}
}
finally {
setExtendedListenerTypes(false);
private void callInitializers(WebAppContext context) throws ServletException {
try {
setExtendedListenerTypes(context, true);
for (ServletContextInitializer initializer : this.initializers) {
initializer.onStartup(context.getServletContext());
}
}

private void setExtendedListenerTypes(boolean extended) {
try {
this.context.getServletContext().setExtendedListenerTypes(extended);
}
catch (NoSuchMethodError ex) {
// Not available on Jetty 8
}
finally {
setExtendedListenerTypes(context, false);
}
}

private void setExtendedListenerTypes(WebAppContext context, boolean extended) {
try {
context.getServletContext().setExtendedListenerTypes(extended);
}
catch (NoSuchMethodError ex) {
// Not available on Jetty 8
}
}

}

0 comments on commit aa9945c

Please sign in to comment.