Skip to content
This repository has been archived by the owner on Aug 6, 2018. It is now read-only.

Commit

Permalink
Added proxy settings configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
d-smith committed Oct 15, 2014
1 parent 4866f57 commit 47bb44a
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
7 changes: 7 additions & 0 deletions .gitignore
Expand Up @@ -4,3 +4,10 @@
*.jar
*.war
*.ear

#intellij files
.idea/
*.iml
*.iws

dependency-reduced-pom.xml
Expand Up @@ -70,6 +70,49 @@ private void error(String message, Exception e) {
throw new IllegalStateException(message, e);
}

/**
* Set proxy configuration based on system properties. Some of the properties are standard
* properties documented by Oracle (http.proxyHost, http.proxyPort, http.auth.ntlm.domain),
* and others are from common convention (http.proxyUser, http.proxyPassword).
*
* Finally, for NTLM authentication the workstation name is taken from the environment as
* COMPUTERNAME. We set this on the client configuration only if the NTLM domain was specified.
*/
private ClientConfiguration setProxySettingsFromSystemProperties(ClientConfiguration clientConfiguration) {

final String proxyHost = System.getProperty("http.proxyHost");
if(proxyHost != null) {
clientConfiguration.setProxyHost(proxyHost);
}

final String proxyPort = System.getProperty("http.proxyPort");
if(proxyPort != null) {
clientConfiguration.setProxyPort(Integer.parseInt(proxyPort));
}

final String proxyUser = System.getProperty("http.proxyUser");
if(proxyUser != null) {
clientConfiguration.setProxyUsername(proxyUser);
}

final String proxyPassword = System.getProperty("http.proxyPassword");
if(proxyPassword != null) {
clientConfiguration.setProxyPassword(proxyPassword);
}

final String proxyDomain = System.getProperty("http.auth.ntlm.domain");
if(proxyDomain != null) {
clientConfiguration.setProxyDomain(proxyDomain);
}

final String workstation = System.getenv("COMPUTERNAME");
if(proxyDomain != null && workstation != null) {
clientConfiguration.setProxyWorkstation(workstation);
}

return clientConfiguration;
}

/**
* Configures this appender instance and makes it ready for use by the
* consumers. It validates mandatory parameters and confirms if the configured
Expand All @@ -94,6 +137,8 @@ public void activateOptions() {
}

ClientConfiguration clientConfiguration = new ClientConfiguration();
clientConfiguration = setProxySettingsFromSystemProperties(clientConfiguration);

clientConfiguration.setMaxErrorRetry(maxRetries);
clientConfiguration.setRetryPolicy(new RetryPolicy(PredefinedRetryPolicies.DEFAULT_RETRY_CONDITION,
PredefinedRetryPolicies.DEFAULT_BACKOFF_STRATEGY, maxRetries, true));
Expand Down

0 comments on commit 47bb44a

Please sign in to comment.