You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2009/02/09 15:41:35 UTC

svn commit: r742534 - in /camel/trunk: camel-core/src/main/java/org/apache/camel/component/file/ camel-core/src/main/java/org/apache/camel/impl/ camel-core/src/main/java/org/apache/camel/util/ camel-core/src/test/java/org/apache/camel/util/ components/...

Author: davsclaus
Date: Mon Feb  9 14:41:34 2009
New Revision: 742534

URL: http://svn.apache.org/viewvc?rev=742534&view=rev
Log:
CAMEL-1328: Added validation of unnown paramters for option prefix. Fixed checkstyle.

Added:
    camel/trunk/components/camel-http/src/test/java/org/apache/camel/component/http/HttpInvalidHttpClientConfigurationTest.java   (contents, props changed)
      - copied, changed from r742280, camel/trunk/components/camel-http/src/test/java/org/apache/camel/component/http/HttpInvalidConfigurationTest.java
Modified:
    camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileConsumer.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultComponent.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/util/IntrospectionSupport.java
    camel/trunk/camel-core/src/test/java/org/apache/camel/util/IntrospectionSupportTest.java
    camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/BasicAuthenticationHttpClientConfigurer.java
    camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpClientConfigurer.java
    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/HttpInvalidConfigurationTest.java

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileConsumer.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileConsumer.java?rev=742534&r1=742533&r2=742534&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileConsumer.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileConsumer.java Mon Feb  9 14:41:34 2009
@@ -21,13 +21,12 @@
 import java.util.List;
 
 import org.apache.camel.AsyncCallback;
-import org.apache.camel.Processor;
 import org.apache.camel.Exchange;
-import org.apache.camel.impl.ScheduledPollConsumer;
+import org.apache.camel.Processor;
 import org.apache.camel.impl.DefaultExchange;
+import org.apache.camel.impl.ScheduledPollConsumer;
 import org.apache.camel.processor.DeadLetterChannel;
 import org.apache.camel.util.ObjectHelper;
-import org.apache.camel.util.FileUtil;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
@@ -63,7 +62,7 @@
         // gather list of files to process
         List<GenericFile<T>> files = new ArrayList<GenericFile<T>>();
 
-        String name = endpoint.getConfiguration().getFile();        
+        String name = endpoint.getConfiguration().getFile();
         boolean isDirectory = endpoint.isDirectory();
         if (isDirectory) {
             pollDirectory(name, files);
@@ -356,9 +355,9 @@
         if (endpoint.getFileExpression() != null) {
             evaluteFileExpression();
             if (fileExpressionResult != null) {
-               if (!name.equals(fileExpressionResult)) {
-                   return false;
-                }                                    
+                if (!name.equals(fileExpressionResult)) {
+                    return false;
+                }
             }
         }
 
@@ -373,5 +372,4 @@
     }
 
 
-
 }

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultComponent.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultComponent.java?rev=742534&r1=742533&r2=742534&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultComponent.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultComponent.java Mon Feb  9 14:41:34 2009
@@ -91,11 +91,8 @@
 
             // if endpoint is strict (not lenient) and we have unknown parameters configured then
             // fail if there are parameters that could not be set, then they are probably miss spelt or not supported at all
-            if (!endpoint.isLenientProperties() && parameters.size() > 0) {
-                throw new ResolveEndpointFailedException(uri, "There are " + parameters.size()
-                    + " parameters that couldn't be set on the endpoint."
-                    + " Check the uri if the parameters are spelt correctly and that they are properties of the endpoint."
-                    + " Unknown parameters=[" + parameters + "]");
+            if (!endpoint.isLenientProperties()) {
+                validateUnknownParameters(uri, parameters, null);
             }
         }
 
@@ -103,6 +100,28 @@
     }
 
     /**
+     * Strategy for validation of unknown parameters not able to be resolved to any endpoint options.
+     *
+     * @param uri          the uri - the uri the end user provided untouched
+     * @param parameters   the parameters, an empty map if no parameters given
+     * @param optionPrefix optional prefix to filter the parameters for validation. Use <tt>null</tt> for validate all.
+     * @throws ResolveEndpointFailedException should be thrown if the URI validation failed
+     */
+    protected void validateUnknownParameters(String uri, Map parameters, String optionPrefix) {
+        Map param = parameters;
+        if (optionPrefix != null) {
+            param = IntrospectionSupport.extractProperties(parameters, optionPrefix);
+        }
+
+        if (param.size() > 0) {
+            throw new ResolveEndpointFailedException(uri, "There are " + param.size()
+                + " parameters that couldn't be set on the endpoint."
+                + " Check the uri if the parameters are spelt correctly and that they are properties of the endpoint."
+                + " Unknown parameters=[" + param + "]");
+        }
+    }
+
+    /**
      * Strategy for validation of the uri when creating the endpoint.
      *
      * @param uri        the uri - the uri the end user provided untouched

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/util/IntrospectionSupport.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/util/IntrospectionSupport.java?rev=742534&r1=742533&r2=742534&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/util/IntrospectionSupport.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/util/IntrospectionSupport.java Mon Feb  9 14:41:34 2009
@@ -108,6 +108,23 @@
         return rc;
     }
 
+    public static boolean hasProperties(Map properties, String optionPrefix) {
+        ObjectHelper.notNull(properties, "properties");
+
+        if (ObjectHelper.isNotEmpty(optionPrefix)) {
+            for (Object o : properties.keySet()) {
+                String name = (String) o;
+                if (name.startsWith(optionPrefix)) {
+                    return true;
+                }
+            }
+            // no parameters with this prefix
+            return false;
+        } else {
+            return !properties.isEmpty();
+        }
+    }
+
     public static Object getProperty(Object target, String property) throws SecurityException, NoSuchMethodException, IllegalArgumentException, IllegalAccessException, InvocationTargetException {
         ObjectHelper.notNull(target, "target");
         ObjectHelper.notNull(property, "property");

Modified: camel/trunk/camel-core/src/test/java/org/apache/camel/util/IntrospectionSupportTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/util/IntrospectionSupportTest.java?rev=742534&r1=742533&r2=742534&view=diff
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/util/IntrospectionSupportTest.java (original)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/util/IntrospectionSupportTest.java Mon Feb  9 14:41:34 2009
@@ -16,6 +16,10 @@
  */
 package org.apache.camel.util;
 
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+
 import org.apache.camel.ContextTestSupport;
 import org.apache.camel.util.jndi.ExampleBean;
 
@@ -63,5 +67,26 @@
         }
     }
 
+    public void testHasProperties() throws Exception {
+        assertFalse(IntrospectionSupport.hasProperties(Collections.EMPTY_MAP, null));
+        assertFalse(IntrospectionSupport.hasProperties(Collections.EMPTY_MAP, ""));
+        assertFalse(IntrospectionSupport.hasProperties(Collections.EMPTY_MAP, "foo."));
+
+        Map<String, String> param = new HashMap<String, String>();
+        assertFalse(IntrospectionSupport.hasProperties(param, null));
+        assertFalse(IntrospectionSupport.hasProperties(param, ""));
+        assertFalse(IntrospectionSupport.hasProperties(param, "foo."));
+
+        param.put("name", "Claus");
+        assertTrue(IntrospectionSupport.hasProperties(param, null));
+        assertTrue(IntrospectionSupport.hasProperties(param, ""));
+        assertFalse(IntrospectionSupport.hasProperties(param, "foo."));
+
+        param.put("foo.name", "Hadrian");
+        assertTrue(IntrospectionSupport.hasProperties(param, null));
+        assertTrue(IntrospectionSupport.hasProperties(param, ""));
+        assertTrue(IntrospectionSupport.hasProperties(param, "foo."));
+    }
+
 }
 

Modified: camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/BasicAuthenticationHttpClientConfigurer.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/BasicAuthenticationHttpClientConfigurer.java?rev=742534&r1=742533&r2=742534&view=diff
==============================================================================
--- camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/BasicAuthenticationHttpClientConfigurer.java (original)
+++ camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/BasicAuthenticationHttpClientConfigurer.java Mon Feb  9 14:41:34 2009
@@ -31,10 +31,8 @@
     }
 
     public void configureHttpClient(HttpClient client) {
-        
         Credentials defaultcreds = new UsernamePasswordCredentials(username, password);
         client.getState().setCredentials(AuthScope.ANY, defaultcreds);
-
     }
 
 }

Modified: camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpClientConfigurer.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpClientConfigurer.java?rev=742534&r1=742533&r2=742534&view=diff
==============================================================================
--- camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpClientConfigurer.java (original)
+++ camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpClientConfigurer.java Mon Feb  9 14:41:34 2009
@@ -27,6 +27,8 @@
 
     /**
      * Configure the HttpClient such as setting the authentication or proxying details
+     *
+     * @param client the client
      */
     void configureHttpClient(HttpClient client);
 }

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=742534&r1=742533&r2=742534&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 Mon Feb  9 14:41:34 2009
@@ -99,9 +99,11 @@
         throws Exception {
 
         // http client can be configured from URI options
-        HttpClientParams params = new HttpClientParams();
-        IntrospectionSupport.setProperties(params, parameters, "httpClient.");        
-        
+        HttpClientParams clientParams = new HttpClientParams();
+        IntrospectionSupport.setProperties(clientParams, parameters, "httpClient.");
+        // validate that we could resolve all httpClient. parameters as this component is lenient
+        validateUnknownParameters(uri, parameters, "httpClient.");
+
         configureParameters(parameters);
 
         // restructure uri to be based on the parameters left as we dont want to include the Camel internal options
@@ -118,7 +120,8 @@
             }
         }
 
-        HttpEndpoint endpoint = new HttpEndpoint(uri, this, httpUri, params, httpConnectionManager, httpClientConfigurer);
+
+        HttpEndpoint endpoint = new HttpEndpoint(uri, this, httpUri, clientParams, httpConnectionManager, httpClientConfigurer);
         if (httpBinding != null) {
             endpoint.setBinding(httpBinding);
         }

Modified: camel/trunk/components/camel-http/src/test/java/org/apache/camel/component/http/HttpInvalidConfigurationTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-http/src/test/java/org/apache/camel/component/http/HttpInvalidConfigurationTest.java?rev=742534&r1=742533&r2=742534&view=diff
==============================================================================
--- camel/trunk/components/camel-http/src/test/java/org/apache/camel/component/http/HttpInvalidConfigurationTest.java (original)
+++ camel/trunk/components/camel-http/src/test/java/org/apache/camel/component/http/HttpInvalidConfigurationTest.java Mon Feb  9 14:41:34 2009
@@ -37,7 +37,7 @@
         }
     }
 
-    public void testInvalidHostConfiguratiob() {
+    public void testInvalidHostConfiguration() {
         // dummy
     }
 

Copied: camel/trunk/components/camel-http/src/test/java/org/apache/camel/component/http/HttpInvalidHttpClientConfigurationTest.java (from r742280, camel/trunk/components/camel-http/src/test/java/org/apache/camel/component/http/HttpInvalidConfigurationTest.java)
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-http/src/test/java/org/apache/camel/component/http/HttpInvalidHttpClientConfigurationTest.java?p2=camel/trunk/components/camel-http/src/test/java/org/apache/camel/component/http/HttpInvalidHttpClientConfigurationTest.java&p1=camel/trunk/components/camel-http/src/test/java/org/apache/camel/component/http/HttpInvalidConfigurationTest.java&r1=742280&r2=742534&rev=742534&view=diff
==============================================================================
--- camel/trunk/components/camel-http/src/test/java/org/apache/camel/component/http/HttpInvalidConfigurationTest.java (original)
+++ camel/trunk/components/camel-http/src/test/java/org/apache/camel/component/http/HttpInvalidHttpClientConfigurationTest.java Mon Feb  9 14:41:34 2009
@@ -26,27 +26,27 @@
 /**
  * Unit test of invalid configuraiton
  */
-public class HttpInvalidConfigurationTest extends ContextTestSupport {
+public class HttpInvalidHttpClientConfigurationTest extends ContextTestSupport {
 
     protected void setUp() throws Exception {
         try {
             super.setUp();
             fail("Should have thrown ResolveEndpointFailedException");
         } catch (ResolveEndpointFailedException e) {
-            assertTrue(e.getMessage().endsWith("You have duplicated the http(s) protocol."));
+            assertTrue(e.getMessage().endsWith("Unknown parameters=[{xxx=true}]"));
         }
     }
 
-    public void testInvalidHostConfiguratiob() {
+    public void testInvalidHostConfiguration() {
         // dummy
     }
 
     protected RouteBuilder createRouteBuilder() throws Exception {
         return new RouteBuilder() {
             public void configure() {
-                from("direct:start").setHeader(HTTP_METHOD, POST).to("http://http://www.google.com");
+                from("direct:start").setHeader(HTTP_METHOD, POST).to("http://www.google.com?httpClient.xxx=true");
             }
         };
     }
 
-}
+}
\ No newline at end of file

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

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

Propchange: camel/trunk/components/camel-http/src/test/java/org/apache/camel/component/http/HttpInvalidHttpClientConfigurationTest.java
------------------------------------------------------------------------------
    svn:mergeinfo =