camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject svn commit: r782918 - in /camel/trunk/components/camel-http/src: main/java/org/apache/camel/component/http/HttpEndpoint.java test/java/org/apache/camel/component/http/HttpProxyTest.java
Date Tue, 09 Jun 2009 08:55:02 GMT
Author: davsclaus
Date: Tue Jun  9 08:55:02 2009
New Revision: 782918

URL: http://svn.apache.org/viewvc?rev=782918&view=rev
Log:
CAMEL-1687: camel-http now uses http proxy settings from java system properties. Thanks to
Savas for patch.

Added:
    camel/trunk/components/camel-http/src/test/java/org/apache/camel/component/http/HttpProxyTest.java
  (with props)
Modified:
    camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpEndpoint.java

Modified: camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpEndpoint.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpEndpoint.java?rev=782918&r1=782917&r2=782918&view=diff
==============================================================================
--- camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpEndpoint.java
(original)
+++ camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpEndpoint.java
Tue Jun  9 08:55:02 2009
@@ -18,7 +18,6 @@
 
 import java.net.URI;
 import java.net.URISyntaxException;
-
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 
@@ -33,15 +32,17 @@
 import org.apache.commons.httpclient.HttpClient;
 import org.apache.commons.httpclient.HttpConnectionManager;
 import org.apache.commons.httpclient.params.HttpClientParams;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 
 /**
- * Represents a <a href="http://camel.apache.org/http.html">HTTP
- * endpoint</a>
+ * Represents a <a href="http://camel.apache.org/http.html">HTTP endpoint</a>
  *
  * @version $Revision$
  */
 public class HttpEndpoint extends DefaultPollingEndpoint implements HeaderFilterStrategyAware
{
 
+    private static final transient Log LOG = LogFactory.getLog(HttpEndpoint.class);
     private HeaderFilterStrategy headerFilterStrategy = new HttpHeaderFilterStrategy();
     private HttpBinding binding;
     private HttpComponent component;
@@ -97,6 +98,19 @@
         if (configurer != null) {
             configurer.configureHttpClient(answer);
         }
+
+        // configure http proxy if defined as system property
+        // http://java.sun.com/javase/6/docs/technotes/guides/net/proxies.html
+        if (System.getProperty("http.proxyHost") != null && System.getProperty("http.proxyPort")
!= null) {
+            String host = System.getProperty("http.proxyHost");
+            int port = Integer.parseInt(System.getProperty("http.proxyPort"));
+            if (LOG.isDebugEnabled()) {
+                LOG.debug("Java System Property http.proxyHost and http.proxyPort detected.
Using http proxy host: "
+                        + host + " port: " + port);
+            }
+            answer.getHostConfiguration().setProxy(host, port);
+        }
+
         return answer;
     }
 

Added: camel/trunk/components/camel-http/src/test/java/org/apache/camel/component/http/HttpProxyTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-http/src/test/java/org/apache/camel/component/http/HttpProxyTest.java?rev=782918&view=auto
==============================================================================
--- camel/trunk/components/camel-http/src/test/java/org/apache/camel/component/http/HttpProxyTest.java
(added)
+++ camel/trunk/components/camel-http/src/test/java/org/apache/camel/component/http/HttpProxyTest.java
Tue Jun  9 08:55:02 2009
@@ -0,0 +1,51 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.http;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.commons.httpclient.HttpClient;
+
+/**
+ * @version $Revision$
+ */
+public class HttpProxyTest extends ContextTestSupport {
+
+    public void testNoHttpProxyConfigured() throws Exception {
+        HttpEndpoint http = context.getEndpoint("http://www.google.com", HttpEndpoint.class);
+
+        HttpClient client = http.createHttpClient();
+        assertNull("No proxy configured yet", client.getHostConfiguration().getProxyHost());
+        assertEquals("No proxy configured yet", -1, client.getHostConfiguration().getProxyPort());
+    }
+
+    public void testHttpProxyConfigured() throws Exception {
+        HttpEndpoint http = context.getEndpoint("http://www.google.com", HttpEndpoint.class);
+
+        System.setProperty("http.proxyHost", "myproxy");
+        System.setProperty("http.proxyPort", "1234");
+
+        try {
+            HttpClient client = http.createHttpClient();
+            assertEquals("myproxy", client.getHostConfiguration().getProxyHost());
+            assertEquals(1234, client.getHostConfiguration().getProxyPort());
+        } finally {
+            System.clearProperty("http.proxyHost");
+            System.clearProperty("http.proxyPort");
+        }
+    }
+
+}

Propchange: camel/trunk/components/camel-http/src/test/java/org/apache/camel/component/http/HttpProxyTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/components/camel-http/src/test/java/org/apache/camel/component/http/HttpProxyTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date



Mime
View raw message