Skip to content

Commit

Permalink
Allow proxy configuration to be passed as environment variables
Browse files Browse the repository at this point in the history
Reads the proxy configuration from these env:
 * `HTTP_PROXY_HOST`
 * `HTTP_PROXY_PORT`
 * `HTTP_PROXY_USERNAME`
 * `HTTP_PROXY_PASSWORD`

A part of resolving redhat-developer/vscode-xml#416

Signed-off-by: David Thompson <[email protected]>
  • Loading branch information
datho7561 committed Apr 6, 2021
1 parent 81298da commit 177c960
Showing 1 changed file with 19 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,25 @@ public class XMLServerLauncher {
* and output streams.
*/
public static void main(String[] args) {

final String HTTP_PROXY_HOST = System.getenv("HTTP_PROXY_HOST");
final String HTTP_PROXY_PORT = System.getenv("HTTP_PROXY_PORT");
final String HTTP_PROXY_USERNAME = System.getenv("HTTP_PROXY_USERNAME");
final String HTTP_PROXY_PASSWORD = System.getenv("HTTP_PROXY_PASSWORD");

if (HTTP_PROXY_HOST != null && HTTP_PROXY_PORT != null) {
System.setProperty("http.proxyHost", HTTP_PROXY_HOST);
System.setProperty("http.proxyPort", HTTP_PROXY_PORT);
}

if (HTTP_PROXY_USERNAME != null && HTTP_PROXY_PASSWORD != null) {
System.setProperty("http.proxyUser", HTTP_PROXY_USERNAME);
System.setProperty("http.proxyPassword", HTTP_PROXY_PASSWORD);
}

final String username = System.getProperty("http.proxyUser");
final String password = System.getProperty("http.proxyPassword");

if (username != null && password != null) {
Authenticator.setDefault(new Authenticator() {

Expand All @@ -60,7 +77,7 @@ protected PasswordAuthentication getPasswordAuthentication() {
/**
* Launches {@link XMLLanguageServer} and makes it accessible through the JSON
* RPC protocol defined by the LSP.
*
*
* @param launcherFuture The future returned by
* {@link org.eclipse.lsp4j.jsonrpc.Launcher#startListening()}.
* (I'm not 100% sure how it meant to be used though, as
Expand All @@ -84,7 +101,7 @@ public static Future<?> launch(InputStream in, OutputStream out) {
* Threads are started with the given executor service. The wrapper function is
* applied to the incoming and outgoing message streams so additional message
* handling such as validation and tracing can be included.
*
*
* @param server - the server that receives method calls from the
* remote client
* @param in - input stream to listen for incoming messages
Expand Down

0 comments on commit 177c960

Please sign in to comment.