Hook up proxy definition to code

git-svn-id: https://svn.apache.org/repos/asf/manifoldcf/branches/CONNECTORS-1104@1640174 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/connectors/sharepoint/connector/src/main/java/org/apache/manifoldcf/authorities/authorities/sharepoint/SharePointAuthority.java b/connectors/sharepoint/connector/src/main/java/org/apache/manifoldcf/authorities/authorities/sharepoint/SharePointAuthority.java
index 2251fd3..7ec91a0 100644
--- a/connectors/sharepoint/connector/src/main/java/org/apache/manifoldcf/authorities/authorities/sharepoint/SharePointAuthority.java
+++ b/connectors/sharepoint/connector/src/main/java/org/apache/manifoldcf/authorities/authorities/sharepoint/SharePointAuthority.java
@@ -56,6 +56,7 @@
 import org.apache.http.util.EntityUtils;
 import org.apache.http.client.HttpRequestRetryHandler;
 import org.apache.http.protocol.HttpContext;
+import org.apache.http.HttpHost;
 
 
 /** This is the native SharePoint implementation of the IAuthorityConnector interface.
@@ -90,6 +91,12 @@
   private String encodedServerLocation = null;
   private String keystoreData = null;
   
+  private String proxyHost = null;
+  private String proxyPortString = null;
+  private String proxyUsername = null;
+  private String proxyPassword = null;
+  private String proxyDomain = null;
+  
   private String cacheLRUsize = null;
   private String cacheLifetime = null;
   
@@ -205,6 +212,12 @@
       ntlmDomain = null;
     }
     
+    proxyHost = params.getParameter(SharePointConfig.PARAM_PROXYHOST);
+    proxyPortString = params.getParameter(SharePointConfig.PARAM_PROXYPORT);
+    proxyUsername = params.getParameter(SharePointConfig.PARAM_PROXYUSER);
+    proxyPassword = params.getParameter(SharePointConfig.PARAM_PROXYPASSWORD);
+    proxyDomain = params.getParameter(SharePointConfig.PARAM_PROXYDOMAIN);
+
     keystoreData = params.getParameter(SharePointConfig.PARAM_SERVERKEYSTORE);
 
   }
@@ -289,6 +302,12 @@
     encodedServerLocation = null;
     serverPort = -1;
 
+    proxyHost = null;
+    proxyPortString = null;
+    proxyUsername = null;
+    proxyPassword = null;
+    proxyDomain = null;
+    
     keystoreData = null;
     keystoreManager = null;
 
@@ -741,6 +760,19 @@
         throw new ManifoldCFException(e.getMessage(),e);
       }
       
+      int proxyPort = 8080;
+      if (proxyPortString != null && proxyPortString.length() > 0)
+      {
+        try
+        {
+          proxyPort = Integer.parseInt(proxyPortString);
+        }
+        catch (NumberFormatException e)
+        {
+          throw new ManifoldCFException(e.getMessage(),e);
+        }
+      }
+
       serverUrl = serverProtocol + "://" + serverName;
       if (serverProtocol.equals("https"))
       {
@@ -786,6 +818,28 @@
           .setConnectTimeout(connectionTimeout)
           .setConnectionRequestTimeout(socketTimeout);
 
+      // If there's a proxy, set that too.
+      if (proxyHost != null && proxyHost.length() > 0)
+      {
+
+        // Configure proxy authentication
+        if (proxyUsername != null && proxyUsername.length() > 0)
+        {
+          if (proxyPassword == null)
+            proxyPassword = "";
+          if (proxyDomain == null)
+            proxyDomain = "";
+
+          credentialsProvider.setCredentials(
+            new AuthScope(proxyHost, proxyPort),
+            new NTCredentials(proxyUsername, proxyPassword, currentHost, proxyDomain));
+        }
+
+        HttpHost proxy = new HttpHost(proxyHost, proxyPort);
+
+        requestBuilder.setProxy(proxy);
+      }
+
       HttpClientBuilder builder = HttpClients.custom()
         .setConnectionManager(connectionManager)
         .setMaxConnTotal(1)
diff --git a/connectors/sharepoint/connector/src/main/java/org/apache/manifoldcf/crawler/connectors/sharepoint/SharePointRepository.java b/connectors/sharepoint/connector/src/main/java/org/apache/manifoldcf/crawler/connectors/sharepoint/SharePointRepository.java
index e245a61..2fafb88 100644
--- a/connectors/sharepoint/connector/src/main/java/org/apache/manifoldcf/crawler/connectors/sharepoint/SharePointRepository.java
+++ b/connectors/sharepoint/connector/src/main/java/org/apache/manifoldcf/crawler/connectors/sharepoint/SharePointRepository.java
@@ -66,6 +66,7 @@
 import org.apache.http.util.EntityUtils;
 import org.apache.http.client.HttpRequestRetryHandler;
 import org.apache.http.protocol.HttpContext;
+import org.apache.http.HttpHost;
 
 /** This is the "repository connector" for Microsoft SharePoint.
 * Document identifiers for this connector come in three forms:
@@ -216,6 +217,24 @@
         ntlmDomain = null;
       }
 
+      String proxyHost = params.getParameter(SharePointConfig.PARAM_PROXYHOST);
+      String proxyPortString = params.getParameter(SharePointConfig.PARAM_PROXYPORT);
+      int proxyPort = 8080;
+      if (proxyPortString != null && proxyPortString.length() > 0)
+      {
+        try
+        {
+          proxyPort = Integer.parseInt(proxyPortString);
+        }
+        catch (NumberFormatException e)
+        {
+          throw new ManifoldCFException(e.getMessage(),e);
+        }
+      }
+      String proxyUsername = params.getParameter(SharePointConfig.PARAM_PROXYUSER);
+      String proxyPassword = params.getParameter(SharePointConfig.PARAM_PROXYPASSWORD);
+      String proxyDomain = params.getParameter(SharePointConfig.PARAM_PROXYDOMAIN);
+      
       serverUrl = serverProtocol + "://" + serverName;
       if (serverProtocol.equals("https"))
       {
@@ -262,6 +281,28 @@
           .setConnectTimeout(connectionTimeout)
           .setConnectionRequestTimeout(socketTimeout);
 
+      // If there's a proxy, set that too.
+      if (proxyHost != null && proxyHost.length() > 0)
+      {
+
+        // Configure proxy authentication
+        if (proxyUsername != null && proxyUsername.length() > 0)
+        {
+          if (proxyPassword == null)
+            proxyPassword = "";
+          if (proxyDomain == null)
+            proxyDomain = "";
+
+          credentialsProvider.setCredentials(
+            new AuthScope(proxyHost, proxyPort),
+            new NTCredentials(proxyUsername, proxyPassword, currentHost, proxyDomain));
+        }
+
+        HttpHost proxy = new HttpHost(proxyHost, proxyPort);
+
+        requestBuilder.setProxy(proxy);
+      }
+
       HttpClientBuilder builder = HttpClients.custom()
         .setConnectionManager(connectionManager)
         .setMaxConnTotal(1)