Skip to content

Commit 245265c

Browse files
committed
Allow specifying a proxy for http API connections via mirthApi.http.proxyHost
Signed-off-by: Mitch Gaffigan <mitch.gaffigan@comcast.net>
1 parent 6865d88 commit 245265c

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

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

Lines changed: 15 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;
@@ -134,7 +135,20 @@ public ServerConnection(int timeout, String[] httpsProtocols, String[] httpsCiph
134135

135136
cookieStore = new BasicCookieStore();
136137
socketConfig = SocketConfig.custom().setSoTimeout(timeout).build();
137-
requestConfig = RequestConfig.custom().setConnectTimeout(CONNECT_TIMEOUT).setSocketTimeout(timeout).build();
138+
139+
RequestConfig.Builder requestConfigBuilder = RequestConfig.custom()
140+
.setConnectTimeout(CONNECT_TIMEOUT)
141+
.setSocketTimeout(timeout);
142+
143+
// If HTTP Proxy is set, configure it
144+
String httpProxyHost = System.getProperty("mirthApi.http.proxyHost");
145+
if (allowHTTP && StringUtils.isNotBlank(httpProxyHost)) {
146+
String httpProxyPort = System.getProperty("mirthApi.http.proxyPort");
147+
int proxyPort = StringUtils.isNotBlank(httpProxyPort) ? Integer.parseInt(httpProxyPort) : 8888;
148+
requestConfigBuilder.setProxy(new HttpHost(httpProxyHost, proxyPort));
149+
}
150+
151+
requestConfig = requestConfigBuilder.build();
138152
keepAliveStrategy = new CustomKeepAliveStrategy();
139153

140154
createClient();

0 commit comments

Comments
 (0)