Add support for using RemoteSpringApplication behind a proxy

This commit adds two new properties, spring.devtools.remote.proxy.host
and spring.devtools.remote.proxy.port that can be used to configure
RemoteSpringApplication to connect to the remote application through
an HTTP proxy.

Closes gh-3968
This commit is contained in:
Andy Wilkinson
2015-10-02 10:28:57 +01:00
parent 0c2f281e89
commit 434d46f583
4 changed files with 51 additions and 2 deletions

View File

@@ -50,6 +50,8 @@ public class RemoteDevToolsProperties {
private Debug debug = new Debug();
private Proxy proxy = new Proxy();
public String getContextPath() {
return this.contextPath;
}
@@ -82,6 +84,10 @@ public class RemoteDevToolsProperties {
return this.debug;
}
public Proxy getProxy() {
return this.proxy;
}
public static class Restart {
/**
@@ -131,4 +137,34 @@ public class RemoteDevToolsProperties {
}
public static class Proxy {
/**
* The host of the proxy to use to connect to the remote application.
*/
private String host;
/**
* The port of the proxy to use to connect to the remote application.
*/
private Integer port;
public String getHost() {
return this.host;
}
public void setHost(String host) {
this.host = host;
}
public Integer getPort() {
return this.port;
}
public void setPort(Integer port) {
this.port = port;
}
}
}

View File

@@ -16,6 +16,8 @@
package org.springframework.boot.devtools.remote.client;
import java.net.InetSocketAddress;
import java.net.Proxy.Type;
import java.net.URL;
import java.util.Arrays;
import java.util.List;
@@ -37,6 +39,7 @@ import org.springframework.boot.devtools.autoconfigure.DevToolsProperties;
import org.springframework.boot.devtools.autoconfigure.DevToolsProperties.Restart;
import org.springframework.boot.devtools.autoconfigure.OptionalLiveReloadServer;
import org.springframework.boot.devtools.autoconfigure.RemoteDevToolsProperties;
import org.springframework.boot.devtools.autoconfigure.RemoteDevToolsProperties.Proxy;
import org.springframework.boot.devtools.autoconfigure.TriggerFileFilter;
import org.springframework.boot.devtools.classpath.ClassPathChangedEvent;
import org.springframework.boot.devtools.classpath.ClassPathFileSystemWatcher;
@@ -91,8 +94,13 @@ public class RemoteClientConfiguration {
public ClientHttpRequestFactory clientHttpRequestFactory() {
List<ClientHttpRequestInterceptor> interceptors = Arrays
.asList(getSecurityInterceptor());
return new InterceptingClientHttpRequestFactory(
new SimpleClientHttpRequestFactory(), interceptors);
SimpleClientHttpRequestFactory requestFactory = new SimpleClientHttpRequestFactory();
Proxy proxy = this.properties.getRemote().getProxy();
if (proxy.getHost() != null && proxy.getPort() != null) {
requestFactory.setProxy(new java.net.Proxy(Type.HTTP, new InetSocketAddress(
proxy.getHost(), proxy.getPort())));
}
return new InterceptingClientHttpRequestFactory(requestFactory, interceptors);
}
private ClientHttpRequestInterceptor getSecurityInterceptor() {