camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ff...@apache.org
Subject camel git commit: [CAMEL-11720]camel-google-drive should be able to honor the proxy configuraion from the camelContext
Date Wed, 30 Aug 2017 04:57:22 GMT
Repository: camel
Updated Branches:
  refs/heads/camel-2.18.x 5f1488cdd -> 6b4e81081


[CAMEL-11720]camel-google-drive should be able to honor the proxy configuraion from the camelContext

(cherry picked from commit 02b369800f3bbee9fb69d94ba076bcfb0e094362)
(cherry picked from commit b003c155fa2762a1eb9a54275fb737bf790c8f62)

Conflicts:
	components/camel-google-drive/src/main/java/org/apache/camel/component/google/drive/BatchGoogleDriveClientFactory.java
	components/camel-google-drive/src/main/java/org/apache/camel/component/google/drive/GoogleDriveComponent.java


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/6b4e8108
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/6b4e8108
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/6b4e8108

Branch: refs/heads/camel-2.18.x
Commit: 6b4e81081ccc65cae1b12ba2d120d53f2e988909
Parents: 5f1488c
Author: Freeman Fang <freeman.fang@gmail.com>
Authored: Wed Aug 30 11:23:15 2017 +0800
Committer: Freeman Fang <freeman.fang@gmail.com>
Committed: Wed Aug 30 12:57:03 2017 +0800

----------------------------------------------------------------------
 .../drive/BatchGoogleDriveClientFactory.java      | 18 ++++++++++++++++--
 .../google/drive/GoogleDriveComponent.java        | 11 ++++++++++-
 .../drive/DriveChildrenIntegrationTest.java       |  6 +++++-
 3 files changed, 31 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/6b4e8108/components/camel-google-drive/src/main/java/org/apache/camel/component/google/drive/BatchGoogleDriveClientFactory.java
----------------------------------------------------------------------
diff --git a/components/camel-google-drive/src/main/java/org/apache/camel/component/google/drive/BatchGoogleDriveClientFactory.java
b/components/camel-google-drive/src/main/java/org/apache/camel/component/google/drive/BatchGoogleDriveClientFactory.java
index 9166aea..c2121e1 100644
--- a/components/camel-google-drive/src/main/java/org/apache/camel/component/google/drive/BatchGoogleDriveClientFactory.java
+++ b/components/camel-google-drive/src/main/java/org/apache/camel/component/google/drive/BatchGoogleDriveClientFactory.java
@@ -16,6 +16,10 @@
  */
 package org.apache.camel.component.google.drive;
 
+import java.net.InetAddress;
+import java.net.InetSocketAddress;
+import java.net.Proxy;
+import java.net.UnknownHostException;
 import java.util.Collection;
 
 import com.google.api.client.auth.oauth2.Credential;
@@ -23,7 +27,6 @@ import com.google.api.client.googleapis.auth.oauth2.GoogleCredential;
 import com.google.api.client.http.javanet.NetHttpTransport;
 import com.google.api.client.json.jackson2.JacksonFactory;
 import com.google.api.services.drive.Drive;
-
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -36,6 +39,17 @@ public class BatchGoogleDriveClientFactory implements GoogleDriveClientFactory
{
         this.transport = new NetHttpTransport();
         this.jsonFactory = new JacksonFactory();
     }
+    
+    public BatchGoogleDriveClientFactory(String proxyHost, int proxyPort) {
+        try {
+            Proxy proxy = new Proxy(Proxy.Type.HTTP, 
+                                    new InetSocketAddress(InetAddress.getByName(proxyHost),
proxyPort));
+            this.transport = new NetHttpTransport.Builder().setProxy(proxy).build();
+            this.jsonFactory = new JacksonFactory();
+        } catch (UnknownHostException e) {
+            LOG.error("Unknow proxy host", e);
+        }
+    }
 
     @Override
     public Drive makeClient(String clientId, String clientSecret, Collection<String>
scopes, String applicationName, String refreshToken, String accessToken) {
@@ -65,4 +79,4 @@ public class BatchGoogleDriveClientFactory implements GoogleDriveClientFactory
{
             .setClientSecrets(clientId, clientSecret)
             .build();
     }
-}
\ No newline at end of file
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/6b4e8108/components/camel-google-drive/src/main/java/org/apache/camel/component/google/drive/GoogleDriveComponent.java
----------------------------------------------------------------------
diff --git a/components/camel-google-drive/src/main/java/org/apache/camel/component/google/drive/GoogleDriveComponent.java
b/components/camel-google-drive/src/main/java/org/apache/camel/component/google/drive/GoogleDriveComponent.java
index 84dc9e2..d364904 100644
--- a/components/camel-google-drive/src/main/java/org/apache/camel/component/google/drive/GoogleDriveComponent.java
+++ b/components/camel-google-drive/src/main/java/org/apache/camel/component/google/drive/GoogleDriveComponent.java
@@ -21,6 +21,7 @@ import org.apache.camel.CamelContext;
 import org.apache.camel.Endpoint;
 import org.apache.camel.component.google.drive.internal.GoogleDriveApiCollection;
 import org.apache.camel.component.google.drive.internal.GoogleDriveApiName;
+import org.apache.camel.util.ObjectHelper;
 import org.apache.camel.util.component.AbstractApiComponent;
 
 /**
@@ -55,7 +56,15 @@ public class GoogleDriveComponent extends AbstractApiComponent<GoogleDriveApiNam
     
     public GoogleDriveClientFactory getClientFactory() {
         if (clientFactory == null) {
-            clientFactory = new BatchGoogleDriveClientFactory();
+            // configure https proxy from camelContext
+            if (ObjectHelper.isNotEmpty(getCamelContext().getProperty("http.proxyHost"))

+                    && ObjectHelper.isNotEmpty(getCamelContext().getProperty("http.proxyPort")))
{
+                String host = getCamelContext().getProperty("http.proxyHost");
+                int port = Integer.parseInt(getCamelContext().getProperty("http.proxyPort"));
+                clientFactory = new BatchGoogleDriveClientFactory(host, port);
+            } else {
+                clientFactory = new BatchGoogleDriveClientFactory();
+            }
         }
         return clientFactory;
     }

http://git-wip-us.apache.org/repos/asf/camel/blob/6b4e8108/components/camel-google-drive/src/test/java/org/apache/camel/component/google/drive/DriveChildrenIntegrationTest.java
----------------------------------------------------------------------
diff --git a/components/camel-google-drive/src/test/java/org/apache/camel/component/google/drive/DriveChildrenIntegrationTest.java
b/components/camel-google-drive/src/test/java/org/apache/camel/component/google/drive/DriveChildrenIntegrationTest.java
index c7c0942..99b7a64 100644
--- a/components/camel-google-drive/src/test/java/org/apache/camel/component/google/drive/DriveChildrenIntegrationTest.java
+++ b/components/camel-google-drive/src/test/java/org/apache/camel/component/google/drive/DriveChildrenIntegrationTest.java
@@ -39,7 +39,7 @@ public class DriveChildrenIntegrationTest extends AbstractGoogleDriveTestSupport
 
     @Test
     public void testUploadFileToFolder() throws Exception {
-        File folder = uploadTestFolder();        
+        File folder = uploadTestFolder();
         File file = uploadTestFile();
         
         final Map<String, Object> headers = new HashMap<String, Object>();
@@ -101,6 +101,10 @@ public class DriveChildrenIntegrationTest extends AbstractGoogleDriveTestSupport
     protected RouteBuilder createRouteBuilder() throws Exception {
         return new RouteBuilder() {
             public void configure() {
+                //set proxy if necessary
+               
+                //this.getContext().getGlobalOptions().put("http.proxyHost", "...");
+                //this.getContext().getGlobalOptions().put("http.proxyPort", "...");
                 // test route for delete
                 from("direct://DELETE")
                     .to("google-drive://" + PATH_PREFIX + "/delete");


Mime
View raw message