Commit dc1e1e82 authored by Andy Wilkinson's avatar Andy Wilkinson Committed by Stephane Nicoll

Polish “Prevent reverse name lookup when configuring Jetty's address”

Closes gh-11889
parent dc48a901
/* /*
* Copyright 2012-2017 the original author or authors. * Copyright 2012-2018 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
......
...@@ -36,7 +36,6 @@ import javax.servlet.http.HttpServletRequest; ...@@ -36,7 +36,6 @@ import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import org.apache.jasper.servlet.JspServlet; import org.apache.jasper.servlet.JspServlet;
import org.eclipse.jetty.server.AbstractNetworkConnector;
import org.eclipse.jetty.server.Connector; import org.eclipse.jetty.server.Connector;
import org.eclipse.jetty.server.Handler; import org.eclipse.jetty.server.Handler;
import org.eclipse.jetty.server.Server; import org.eclipse.jetty.server.Server;
...@@ -120,27 +119,14 @@ public class JettyEmbeddedServletContainerFactoryTests ...@@ -120,27 +119,14 @@ public class JettyEmbeddedServletContainerFactoryTests
@Test @Test
public void specificIPAddressNotReverseResolved() throws Exception { public void specificIPAddressNotReverseResolved() throws Exception {
JettyEmbeddedServletContainerFactory factory = getFactory(); JettyEmbeddedServletContainerFactory factory = getFactory();
final String[] refAncHost = new String[1]; InetAddress localhost = InetAddress.getLocalHost();
refAncHost[0] = "HostNotSetInAbstractNetworkConnector"; factory.setAddress(InetAddress.getByAddress(localhost.getAddress()));
InetAddress lhAddress = InetAddress.getLocalHost(); this.container = factory.getEmbeddedServletContainer();
InetAddress address = InetAddress.getByAddress(lhAddress.getAddress()); this.container.start();
// the address should have no host name associated with ith Connector connector = ((JettyEmbeddedServletContainer) this.container).getServer()
String expectedHost = address.getHostAddress(); .getConnectors()[0];
factory.setAddress(address); assertThat(((ServerConnector) connector).getHost())
factory.addServerCustomizers(server -> { .isEqualTo(localhost.getHostAddress());
for (Connector connector : server.getConnectors()) {
if (connector instanceof AbstractNetworkConnector) {
@SuppressWarnings("resource")
AbstractNetworkConnector anc = (AbstractNetworkConnector) connector;
String ancHost = anc.getHost();
refAncHost[0] = ancHost;
break;
}
}
});
this.container = factory
.getEmbeddedServletContainer(exampleServletRegistration());
assertThat(refAncHost[0]).isEqualTo(expectedHost);
} }
@Test @Test
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment