From d5047b55ca5fc5ad2b72ca376becd6944bf4efd7 Mon Sep 17 00:00:00 2001 From: tkellner Date: Wed, 24 Jul 2013 14:58:23 +0000 Subject: Enable proxy usage for HttpClient git-svn-id: https://joinup.ec.europa.eu/svn/pdf-over/trunk@470 174cde9d-5d70-4d2a-aa98-46368bc2aaf7 --- .../workflow/states/mobilebku/MobileBKUHelper.java | 30 ++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/mobilebku/MobileBKUHelper.java') diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/mobilebku/MobileBKUHelper.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/mobilebku/MobileBKUHelper.java index b5f781cc..65ffc9b0 100644 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/mobilebku/MobileBKUHelper.java +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/mobilebku/MobileBKUHelper.java @@ -19,9 +19,13 @@ package at.asit.pdfover.gui.workflow.states.mobilebku; import java.util.regex.Matcher; import java.util.regex.Pattern; +import org.apache.commons.httpclient.HttpClient; +import org.apache.commons.httpclient.UsernamePasswordCredentials; +import org.apache.commons.httpclient.auth.AuthScope; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import at.asit.pdfover.gui.Constants; import at.asit.pdfover.gui.exceptions.InvalidNumberException; import at.asit.pdfover.gui.exceptions.InvalidPasswordException; import at.asit.pdfover.gui.exceptions.PasswordTooLongException; @@ -145,4 +149,30 @@ public class MobileBKUHelper { } return query; } + + /** + * Get a HTTP Client instance + * @return the HttpClient + */ + public static HttpClient getHttpClient() { + 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)); + } + } + + return client; + } } -- cgit v1.2.3