Commit 61cba640 authored by Andy Wilkinson's avatar Andy Wilkinson

Merge pull request #11889 from Henrich Kraemer

* gh-11889:
  Polish “Prevent reverse name lookup when configuring Jetty's address”
  Prevent reverse name lookup when configuring Jetty's address
parents 09a64bc8 a1b823fc
/* /*
* 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.
...@@ -101,6 +101,8 @@ import org.springframework.util.StringUtils; ...@@ -101,6 +101,8 @@ import org.springframework.util.StringUtils;
* @author Eddú Meléndez * @author Eddú Meléndez
* @author Venil Noronha * @author Venil Noronha
* @author Henri Kerola * @author Henri Kerola
* @author Henrich Krämer
*
* @see #setPort(int) * @see #setPort(int)
* @see #setConfigurations(Collection) * @see #setConfigurations(Collection)
* @see JettyEmbeddedServletContainer * @see JettyEmbeddedServletContainer
...@@ -895,7 +897,7 @@ public class JettyEmbeddedServletContainerFactory ...@@ -895,7 +897,7 @@ public class JettyEmbeddedServletContainerFactory
ReflectionUtils.findMethod(connectorClass, "setPort", int.class) ReflectionUtils.findMethod(connectorClass, "setPort", int.class)
.invoke(connector, address.getPort()); .invoke(connector, address.getPort());
ReflectionUtils.findMethod(connectorClass, "setHost", String.class) ReflectionUtils.findMethod(connectorClass, "setHost", String.class)
.invoke(connector, address.getHostName()); .invoke(connector, address.getHostString());
if (acceptors > 0) { if (acceptors > 0) {
ReflectionUtils.findMethod(connectorClass, "setAcceptors", int.class) ReflectionUtils.findMethod(connectorClass, "setAcceptors", int.class)
.invoke(connector, acceptors); .invoke(connector, acceptors);
...@@ -924,7 +926,7 @@ public class JettyEmbeddedServletContainerFactory ...@@ -924,7 +926,7 @@ public class JettyEmbeddedServletContainerFactory
public AbstractConnector createConnector(Server server, InetSocketAddress address, public AbstractConnector createConnector(Server server, InetSocketAddress address,
int acceptors, int selectors) { int acceptors, int selectors) {
ServerConnector connector = new ServerConnector(server, acceptors, selectors); ServerConnector connector = new ServerConnector(server, acceptors, selectors);
connector.setHost(address.getHostName()); connector.setHost(address.getHostString());
connector.setPort(address.getPort()); connector.setPort(address.getPort());
for (ConnectionFactory connectionFactory : connector for (ConnectionFactory connectionFactory : connector
.getConnectionFactories()) { .getConnectionFactories()) {
......
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
package org.springframework.boot.context.embedded.jetty; package org.springframework.boot.context.embedded.jetty;
import java.io.IOException; import java.io.IOException;
import java.net.InetAddress;
import java.nio.charset.Charset; import java.nio.charset.Charset;
import java.util.Arrays; import java.util.Arrays;
import java.util.Locale; import java.util.Locale;
...@@ -35,6 +36,7 @@ import javax.servlet.http.HttpServletRequest; ...@@ -35,6 +36,7 @@ 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.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;
import org.eclipse.jetty.server.ServerConnector; import org.eclipse.jetty.server.ServerConnector;
...@@ -114,6 +116,19 @@ public class JettyEmbeddedServletContainerFactoryTests ...@@ -114,6 +116,19 @@ public class JettyEmbeddedServletContainerFactoryTests
} }
} }
@Test
public void specificIPAddressNotReverseResolved() throws Exception {
JettyEmbeddedServletContainerFactory factory = getFactory();
InetAddress localhost = InetAddress.getLocalHost();
factory.setAddress(InetAddress.getByAddress(localhost.getAddress()));
this.container = factory.getEmbeddedServletContainer();
this.container.start();
Connector connector = ((JettyEmbeddedServletContainer) this.container).getServer()
.getConnectors()[0];
assertThat(((ServerConnector) connector).getHost())
.isEqualTo(localhost.getHostAddress());
}
@Test @Test
public void sessionTimeout() throws Exception { public void sessionTimeout() throws Exception {
JettyEmbeddedServletContainerFactory factory = getFactory(); JettyEmbeddedServletContainerFactory factory = getFactory();
......
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