Updated Branches: refs/heads/camel-2.11.x 6250b4826 -> 57dde3c8c refs/heads/camel-2.12.x 81e557402 -> 25930b8d8
CAMEL-7066 Supported to setting the proxy from camel-twitter uri Project: http://git-wip-us.apache.org/repos/asf/camel/repo Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/25930b8d Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/25930b8d Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/25930b8d Branch: refs/heads/camel-2.12.x Commit: 25930b8d8b042d44dcb9ef70e5ea32a4f65a51ba Parents: 81e5574 Author: Willem Jiang <willem.ji...@gmail.com> Authored: Fri Dec 13 15:12:38 2013 +0800 Committer: Willem Jiang <willem.ji...@gmail.com> Committed: Fri Dec 13 15:15:24 2013 +0800 ---------------------------------------------------------------------- .../component/twitter/TwitterConfiguration.java | 58 ++++++++++++++++++++ .../component/twitter/UriConfigurationTest.java | 12 ++++ 2 files changed, 70 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/25930b8d/components/camel-twitter/src/main/java/org/apache/camel/component/twitter/TwitterConfiguration.java ---------------------------------------------------------------------- diff --git a/components/camel-twitter/src/main/java/org/apache/camel/component/twitter/TwitterConfiguration.java b/components/camel-twitter/src/main/java/org/apache/camel/component/twitter/TwitterConfiguration.java index f2df043..0acb20d 100644 --- a/components/camel-twitter/src/main/java/org/apache/camel/component/twitter/TwitterConfiguration.java +++ b/components/camel-twitter/src/main/java/org/apache/camel/component/twitter/TwitterConfiguration.java @@ -116,6 +116,18 @@ public class TwitterConfiguration { */ @UriParam private Integer numberOfPages = new Integer(1); + + @UriParam + private String httpProxyHost; + + @UriParam + private String httpProxyUser; + + @UriParam + private String httpProxyPassword; + + @UriParam + private Integer httpProxyPort; /** * Singleton, on demand instances of Twitter4J's Twitter & TwitterStream. @@ -143,11 +155,25 @@ public class TwitterConfiguration { * @return Configuration */ public Configuration getConfiguration() { + checkComplete(); ConfigurationBuilder confBuilder = new ConfigurationBuilder(); confBuilder.setOAuthConsumerKey(consumerKey); confBuilder.setOAuthConsumerSecret(consumerSecret); confBuilder.setOAuthAccessToken(accessToken); confBuilder.setOAuthAccessTokenSecret(accessTokenSecret); + if (getHttpProxyHost() != null) { + confBuilder.setHttpProxyHost(getHttpProxyHost()); + } + if (getHttpProxyUser() != null) { + confBuilder.setHttpProxyHost(getHttpProxyUser()); + } + if (getHttpProxyPassword() != null) { + confBuilder.setHttpProxyHost(getHttpProxyPassword()); + } + if (httpProxyPort != null) { + confBuilder.setHttpProxyPort(httpProxyPort); + } + return confBuilder.build(); } @@ -315,6 +341,38 @@ public class TwitterConfiguration { public void setNumberOfPages(Integer numberOfPages) { this.numberOfPages = numberOfPages; } + + public void setHttpProxyHost(String httpProxyHost) { + this.httpProxyHost = httpProxyHost; + } + + public String getHttpProxyHost() { + return httpProxyHost; + } + + public void setHttpProxyUser(String httpProxyUser) { + this.httpProxyUser = httpProxyUser; + } + + public String getHttpProxyUser() { + return httpProxyUser; + } + + public void setHttpProxyPassword(String httpProxyPassword) { + this.httpProxyPassword = httpProxyPassword; + } + + public String getHttpProxyPassword() { + return httpProxyPassword; + } + + public void setHttpProxyPort(int httpProxyPort) { + this.httpProxyPort = httpProxyPort; + } + + public int getHttpProxyPort() { + return httpProxyPort; + } } http://git-wip-us.apache.org/repos/asf/camel/blob/25930b8d/components/camel-twitter/src/test/java/org/apache/camel/component/twitter/UriConfigurationTest.java ---------------------------------------------------------------------- diff --git a/components/camel-twitter/src/test/java/org/apache/camel/component/twitter/UriConfigurationTest.java b/components/camel-twitter/src/test/java/org/apache/camel/component/twitter/UriConfigurationTest.java index 9c6d124..a003032 100644 --- a/components/camel-twitter/src/test/java/org/apache/camel/component/twitter/UriConfigurationTest.java +++ b/components/camel-twitter/src/test/java/org/apache/camel/component/twitter/UriConfigurationTest.java @@ -48,4 +48,16 @@ public class UriConfigurationTest extends Assert { assertEquals(new Integer(50), twitterEndpoint.getProperties().getCount()); assertEquals(new Integer(2), twitterEndpoint.getProperties().getNumberOfPages()); } + + @Test + public void testHttpProxySetting() throws Exception { + Endpoint endpoint = context.getEndpoint("twitter:todo/todo?httpProxyHost=example.com&httpProxyPort=3338&httpProxyUser=test&httpProxyPassword=pwd"); + assertTrue("Endpoint not a TwitterEndpoint: " + endpoint, endpoint instanceof TwitterEndpoint); + TwitterEndpoint twitterEndpoint = (TwitterEndpoint) endpoint; + + assertEquals("example.com", twitterEndpoint.getProperties().getHttpProxyHost()); + assertEquals(3338, twitterEndpoint.getProperties().getHttpProxyPort()); + assertEquals("test", twitterEndpoint.getProperties().getHttpProxyUser()); + assertEquals("pwd", twitterEndpoint.getProperties().getHttpProxyPassword()); + } }