Author: davsclaus
Date: Fri Apr 23 08:02:43 2010
New Revision: 937181

URL: http://svn.apache.org/viewvc?rev=937181&view=rev
Log:
Fixed http component to validate auth and auth proxy options is all provided.

Modified:
    
camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpComponent.java
    
camel/trunk/components/camel-http/src/test/java/org/apache/camel/component/http/HttpQueryGoogleProxyTest.java

Modified: 
camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpComponent.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpComponent.java?rev=937181&r1=937180&r2=937181&view=diff
==============================================================================
--- 
camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpComponent.java
 (original)
+++ 
camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpComponent.java
 Fri Apr 23 08:02:43 2010
@@ -127,14 +127,23 @@ public class HttpComponent extends Heade
      */
     protected HttpClientConfigurer configureAuth(HttpClientConfigurer 
configurer, AuthMethod authMethod, String username,
                                                  String password, String 
domain, String host, Set<AuthMethod> authMethods) {
-        if (authMethod == null) {
+
+        // no auth is in use
+        if (username == null && authMethod == null) {
             return configurer;
         }
-        authMethods.add(authMethod);
 
+        // validate mandatory options given
+        if (username != null && authMethod == null) {
+            throw new IllegalArgumentException("Option authMethod must be 
provided to use authentication");
+        }
+        ObjectHelper.notNull(authMethod, "authMethod");
         ObjectHelper.notNull(username, "authUsername");
         ObjectHelper.notNull(password, "authPassword");
 
+        // add it as a auth method used
+        authMethods.add(authMethod);
+
         if (authMethod == AuthMethod.Basic || authMethod == AuthMethod.Digest) 
{
             return CompositeHttpConfigurer.combineConfigurers(configurer,
                     new BasicAuthenticationHttpClientConfigurer(false, 
username, password));
@@ -155,14 +164,22 @@ public class HttpComponent extends Heade
      */
     protected HttpClientConfigurer configureProxyAuth(HttpClientConfigurer 
configurer, AuthMethod authMethod, String username,
                                                       String password, String 
domain, String host, Set<AuthMethod> authMethods) {
-        if (authMethod == null) {
+        // no proxy auth is in use
+        if (username == null && authMethod == null) {
             return configurer;
         }
-        authMethods.add(authMethod);
 
+        // validate mandatory options given
+        if (username != null && authMethod == null) {
+            throw new IllegalArgumentException("Option proxyAuthMethod must be 
provided to use proxy authentication");
+        }
+        ObjectHelper.notNull(authMethod, "proxyAuthMethod");
         ObjectHelper.notNull(username, "proxyAuthUsername");
         ObjectHelper.notNull(password, "proxyAuthPassword");
 
+        // add it as a auth method used
+        authMethods.add(authMethod);
+
         if (authMethod == AuthMethod.Basic || authMethod == AuthMethod.Digest) 
{
             return CompositeHttpConfigurer.combineConfigurers(configurer,
                     new BasicAuthenticationHttpClientConfigurer(true, 
username, password));

Modified: 
camel/trunk/components/camel-http/src/test/java/org/apache/camel/component/http/HttpQueryGoogleProxyTest.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/components/camel-http/src/test/java/org/apache/camel/component/http/HttpQueryGoogleProxyTest.java?rev=937181&r1=937180&r2=937181&view=diff
==============================================================================
--- 
camel/trunk/components/camel-http/src/test/java/org/apache/camel/component/http/HttpQueryGoogleProxyTest.java
 (original)
+++ 
camel/trunk/components/camel-http/src/test/java/org/apache/camel/component/http/HttpQueryGoogleProxyTest.java
 Fri Apr 23 08:02:43 2010
@@ -33,12 +33,12 @@ public class HttpQueryGoogleProxyTest ex
     @Ignore("Run manually")
     public void testQueryGoogleProxy() throws Exception {
         HttpConfiguration config = new HttpConfiguration();
-        config.setProxyHost("aa");
-        config.setProxyPort(80);
+        config.setProxyHost("myProxyHost");
+        config.setProxyPort(8877);
         config.setProxyAuthMethod(AuthMethod.Basic);
-        config.setAuthMethodPriority("Basic,Digest");
-        config.setProxyAuthUsername("aa");
-        config.setProxyAuthPassword("aa");
+        config.setAuthMethodPriority("Digest,Basic");
+        config.setProxyAuthUsername("myProxyUsername");
+        config.setProxyAuthPassword("myProxyPassword");
 
         HttpComponent http = context.getComponent("http", HttpComponent.class);
         http.setHttpConfiguration(config);


Reply via email to