Commit 434d46f5 authored by Andy Wilkinson's avatar Andy Wilkinson

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
parent 0c2f281e
...@@ -50,6 +50,8 @@ public class RemoteDevToolsProperties { ...@@ -50,6 +50,8 @@ public class RemoteDevToolsProperties {
private Debug debug = new Debug(); private Debug debug = new Debug();
private Proxy proxy = new Proxy();
public String getContextPath() { public String getContextPath() {
return this.contextPath; return this.contextPath;
} }
...@@ -82,6 +84,10 @@ public class RemoteDevToolsProperties { ...@@ -82,6 +84,10 @@ public class RemoteDevToolsProperties {
return this.debug; return this.debug;
} }
public Proxy getProxy() {
return this.proxy;
}
public static class Restart { public static class Restart {
/** /**
...@@ -131,4 +137,34 @@ public class RemoteDevToolsProperties { ...@@ -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;
}
}
} }
...@@ -16,6 +16,8 @@ ...@@ -16,6 +16,8 @@
package org.springframework.boot.devtools.remote.client; package org.springframework.boot.devtools.remote.client;
import java.net.InetSocketAddress;
import java.net.Proxy.Type;
import java.net.URL; import java.net.URL;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
...@@ -37,6 +39,7 @@ import org.springframework.boot.devtools.autoconfigure.DevToolsProperties; ...@@ -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.DevToolsProperties.Restart;
import org.springframework.boot.devtools.autoconfigure.OptionalLiveReloadServer; import org.springframework.boot.devtools.autoconfigure.OptionalLiveReloadServer;
import org.springframework.boot.devtools.autoconfigure.RemoteDevToolsProperties; 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.autoconfigure.TriggerFileFilter;
import org.springframework.boot.devtools.classpath.ClassPathChangedEvent; import org.springframework.boot.devtools.classpath.ClassPathChangedEvent;
import org.springframework.boot.devtools.classpath.ClassPathFileSystemWatcher; import org.springframework.boot.devtools.classpath.ClassPathFileSystemWatcher;
...@@ -91,8 +94,13 @@ public class RemoteClientConfiguration { ...@@ -91,8 +94,13 @@ public class RemoteClientConfiguration {
public ClientHttpRequestFactory clientHttpRequestFactory() { public ClientHttpRequestFactory clientHttpRequestFactory() {
List<ClientHttpRequestInterceptor> interceptors = Arrays List<ClientHttpRequestInterceptor> interceptors = Arrays
.asList(getSecurityInterceptor()); .asList(getSecurityInterceptor());
return new InterceptingClientHttpRequestFactory( SimpleClientHttpRequestFactory requestFactory = new SimpleClientHttpRequestFactory();
new SimpleClientHttpRequestFactory(), interceptors); 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() { private ClientHttpRequestInterceptor getSecurityInterceptor() {
......
...@@ -674,6 +674,8 @@ content into your application; rather pick only the properties that you need. ...@@ -674,6 +674,8 @@ content into your application; rather pick only the properties that you need.
spring.devtools.remote.context-path=/.~~spring-boot!~ # context path used to handle the remote connection spring.devtools.remote.context-path=/.~~spring-boot!~ # context path used to handle the remote connection
spring.devtools.remote.debug.enabled=true # enable remote debug support spring.devtools.remote.debug.enabled=true # enable remote debug support
spring.devtools.remote.debug.local-port=8000 # local remote debug server port spring.devtools.remote.debug.local-port=8000 # local remote debug server port
spring.devtools.remote.proxy.host= # the host of the proxy to use to connect to the remote application
spring.devtools.remote.proxy.port= # the port of the proxy to use to connect to the remote application
spring.devtools.remote.restart.enabled=true # enable remote restart spring.devtools.remote.restart.enabled=true # enable remote restart
spring.devtools.remote.secret= # a shared secret required to establish a connection spring.devtools.remote.secret= # a shared secret required to establish a connection
spring.devtools.remote.secret-header-name=X-AUTH-TOKEN # HTTP header used to transfer the shared secret spring.devtools.remote.secret-header-name=X-AUTH-TOKEN # HTTP header used to transfer the shared secret
......
...@@ -1064,6 +1064,9 @@ property is read and passed to the server for authentication. ...@@ -1064,6 +1064,9 @@ property is read and passed to the server for authentication.
TIP: It's always advisable to use `https://` as the connection protocol so that traffic is TIP: It's always advisable to use `https://` as the connection protocol so that traffic is
encrypted and passwords cannot be intercepted. encrypted and passwords cannot be intercepted.
TIP: If you need to use a proxy to access the remote application, configure the
`spring.devtools.remote.proxy.host` and `spring.devtools.remote.proxy.port` properties.
[[using-boot-devtools-remote-update]] [[using-boot-devtools-remote-update]]
......
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