Skip to content

Commit 4681156

Browse files
committed
Allow specifying a proxy for http API connections
Adds support for the client to connect to the server via an HTTP proxy. Client examines the engine.http.proxyHost and engine.http.proxyPort system properties to determine the proxy to use. Closes #190 in OIE Signed-off-by: Mitch Gaffigan <mitch.gaffigan@comcast.net>
1 parent 6865d88 commit 4681156

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

server/src/com/mirth/connect/client/core/ServerConnection.java

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import org.apache.commons.lang3.StringUtils;
3737
import org.apache.http.Header;
3838
import org.apache.http.HttpEntity;
39+
import org.apache.http.HttpHost;
3940
import org.apache.http.HttpResponse;
4041
import org.apache.http.HttpStatus;
4142
import org.apache.http.StatusLine;
@@ -91,6 +92,8 @@ public class ServerConnection implements Connector {
9192
public static final String EXECUTE_TYPE_PROPERTY = "executeType";
9293
public static final String OPERATION_PROPERTY = "operation";
9394
public static final String CUSTOM_HEADERS_PROPERTY = "customHeaders";
95+
private static final String PROXY_HOST_PROPERTY = "engine.http.proxyHost";
96+
private static final String PROXY_PORT_PROPERTY = "engine.http.proxyPort";
9497

9598
private static final int CONNECT_TIMEOUT = 10000;
9699
private static final int IDLE_TIMEOUT = 300000;
@@ -134,7 +137,21 @@ public ServerConnection(int timeout, String[] httpsProtocols, String[] httpsCiph
134137

135138
cookieStore = new BasicCookieStore();
136139
socketConfig = SocketConfig.custom().setSoTimeout(timeout).build();
137-
requestConfig = RequestConfig.custom().setConnectTimeout(CONNECT_TIMEOUT).setSocketTimeout(timeout).build();
140+
141+
RequestConfig.Builder requestConfigBuilder = RequestConfig.custom()
142+
.setConnectTimeout(CONNECT_TIMEOUT)
143+
.setSocketTimeout(timeout);
144+
145+
// If HTTP Proxy is set, configure it
146+
String httpProxyHost = System.getProperty(PROXY_HOST_PROPERTY);
147+
if (allowHTTP && StringUtils.isNotBlank(httpProxyHost)) {
148+
String httpProxyPort = System.getProperty(PROXY_PORT_PROPERTY);
149+
int proxyPort = StringUtils.isNotBlank(httpProxyPort) ? Integer.parseInt(httpProxyPort) : 8888;
150+
logger.info("Using API HTTP Proxy {}:{}", httpProxyHost, proxyPort);
151+
requestConfigBuilder.setProxy(new HttpHost(httpProxyHost, proxyPort));
152+
}
153+
154+
requestConfig = requestConfigBuilder.build();
138155
keepAliveStrategy = new CustomKeepAliveStrategy();
139156

140157
createClient();

0 commit comments

Comments
 (0)