From cf2c64272ef684cdab9d96671dea44912e02a348 Mon Sep 17 00:00:00 2001 From: Tobias Kellner Date: Thu, 5 Nov 2015 14:50:34 +0100 Subject: Don't use proxy in HttpClient for local connections --- .../java/at/asit/pdfover/gui/bku/BKUHelper.java | 39 ++++++++++++++-------- .../at/asit/pdfover/gui/bku/LocalBKUConnector.java | 2 +- .../pdfover/gui/workflow/states/LocalBKUState.java | 2 +- 3 files changed, 27 insertions(+), 16 deletions(-) diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/bku/BKUHelper.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/bku/BKUHelper.java index 20cc04bb..765a6706 100644 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/bku/BKUHelper.java +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/bku/BKUHelper.java @@ -36,28 +36,39 @@ public class BKUHelper { /** * Get a HTTP Client instance + * @param useProxy whether to use a potentially set proxy * @return the HttpClient */ - public static HttpClient getHttpClient() { + public static HttpClient getHttpClient(boolean useProxy) { HttpClient client = new HttpClient(); client.getParams().setParameter("http.useragent", //$NON-NLS-1$ Constants.USER_AGENT_STRING); - - String host = System.getProperty("http.proxyHost"); //$NON-NLS-1$ - String port = System.getProperty("http.proxyPort"); //$NON-NLS-1$ - if (host != null && !host.isEmpty() && - port != null && !port.isEmpty()) { - int p = Integer.parseInt(port); - client.getHostConfiguration().setProxy(host, p); - String user = System.getProperty("http.proxyUser"); //$NON-NLS-1$ - String pass = System.getProperty("http.proxyPassword"); //$NON-NLS-1$ - if (user != null && !user.isEmpty() && pass != null) { - client.getState().setProxyCredentials(new AuthScope(host, p), - new UsernamePasswordCredentials(user, pass)); + + if (useProxy) { + String host = System.getProperty("http.proxyHost"); //$NON-NLS-1$ + String port = System.getProperty("http.proxyPort"); //$NON-NLS-1$ + if (host != null && !host.isEmpty() && + port != null && !port.isEmpty()) { + int p = Integer.parseInt(port); + client.getHostConfiguration().setProxy(host, p); + String user = System.getProperty("http.proxyUser"); //$NON-NLS-1$ + String pass = System.getProperty("http.proxyPassword"); //$NON-NLS-1$ + if (user != null && !user.isEmpty() && pass != null) { + client.getState().setProxyCredentials(new AuthScope(host, p), + new UsernamePasswordCredentials(user, pass)); + } } } - + return client; } + /** + * Get a HTTP Client instance + * @return the HttpClient + */ + public static HttpClient getHttpClient() { + return getHttpClient(true); + } + } diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/bku/LocalBKUConnector.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/bku/LocalBKUConnector.java index eb1b57d6..3d18bfc8 100644 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/bku/LocalBKUConnector.java +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/bku/LocalBKUConnector.java @@ -68,7 +68,7 @@ public class LocalBKUConnector implements BkuSlConnector { @Override public SLResponse handleSLRequest(SLRequest request) throws SignatureException { try { - HttpClient client = BKUHelper.getHttpClient(); + HttpClient client = BKUHelper.getHttpClient(false); PostMethod method = new PostMethod(Constants.LOCAL_BKU_URL); String sl_request = request.getRequest(); diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/LocalBKUState.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/LocalBKUState.java index eaccae5d..5507c739 100644 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/LocalBKUState.java +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/LocalBKUState.java @@ -104,7 +104,7 @@ public class LocalBKUState extends State { public void run() { try { - HttpClient client = BKUHelper.getHttpClient(); + HttpClient client = BKUHelper.getHttpClient(false); PostMethod method = new PostMethod(Constants.LOCAL_BKU_URL); -- cgit v1.2.3