camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject svn commit: r677999 - in /activemq/camel/trunk/components/camel-http/src: main/java/org/apache/camel/component/http/ test/java/org/apache/camel/component/http/
Date Fri, 18 Jul 2008 18:58:03 GMT
Author: davsclaus
Date: Fri Jul 18 11:58:03 2008
New Revision: 677999

URL: http://svn.apache.org/viewvc?rev=677999&view=rev
Log:
CAMEL-736: Better end-user error message for invalid configuration with duplicated http protocol
as this component does not require you to duplicate it!

Added:
    activemq/camel/trunk/components/camel-http/src/test/java/org/apache/camel/component/http/HttpInvalidConfigurationTest.java
Modified:
    activemq/camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpComponent.java
    activemq/camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpProducer.java

Modified: activemq/camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpComponent.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpComponent.java?rev=677999&r1=677998&r2=677999&view=diff
==============================================================================
--- activemq/camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpComponent.java
(original)
+++ activemq/camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpComponent.java
Fri Jul 18 11:58:03 2008
@@ -20,6 +20,7 @@
 import java.util.Map;
 
 import org.apache.camel.Endpoint;
+import org.apache.camel.ResolveEndpointFailedException;
 import org.apache.camel.impl.DefaultComponent;
 import org.apache.camel.util.IntrospectionSupport;
 import org.apache.commons.httpclient.HttpConnectionManager;
@@ -40,8 +41,6 @@
 
     /**
      * Connects the URL specified on the endpoint to the specified processor.
-     *
-     * @throws Exception
      */
     public void connect(HttpConsumer consumer) throws Exception {
     }
@@ -49,8 +48,6 @@
     /**
      * Disconnects the URL specified on the endpoint from the specified
      * processor.
-     *
-     * @throws Exception
      */
     public void disconnect(HttpConsumer consumer) throws Exception {
     }
@@ -76,7 +73,19 @@
         throws Exception {
         HttpClientParams params = new HttpClientParams();
         IntrospectionSupport.setProperties(params, parameters, "httpClient.");
-        return new HttpEndpoint(uri, this, new URI(uri), params, httpConnectionManager, httpClientConfigurer);
+
+        // validate http uri that end-user did not duplicate the http part that can be a
common error
+        URI httpUri = new URI(uri);
+        String part = httpUri.getSchemeSpecificPart();
+        if (part != null) {
+            part = part.toLowerCase();
+            if (part.startsWith("//http://") || part.startsWith("//https://")) {
+                throw new ResolveEndpointFailedException(uri,
+                    "The uri part is not configured correctly. You have duplicated the http(s)
protocol.");
+            }
+        }
+
+        return new HttpEndpoint(uri, this, httpUri, params, httpConnectionManager, httpClientConfigurer);
     }
 
     @Override

Modified: activemq/camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpProducer.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpProducer.java?rev=677999&r1=677998&r2=677999&view=diff
==============================================================================
--- activemq/camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpProducer.java
(original)
+++ activemq/camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpProducer.java
Fri Jul 18 11:58:03 2008
@@ -17,8 +17,6 @@
 package org.apache.camel.component.http;
 
 
-import java.io.BufferedInputStream;
-import java.io.ByteArrayInputStream;
 import java.io.InputStream;
 import java.io.UnsupportedEncodingException;
 import java.util.Arrays;
@@ -28,6 +26,7 @@
 import org.apache.camel.Exchange;
 import org.apache.camel.Message;
 import org.apache.camel.Producer;
+import static org.apache.camel.component.http.HttpMethods.HTTP_METHOD;
 import org.apache.camel.component.http.helper.LoadingByteArrayOutputStream;
 import org.apache.camel.impl.DefaultProducer;
 import org.apache.commons.httpclient.Header;
@@ -38,9 +37,6 @@
 import org.apache.commons.httpclient.methods.StringRequestEntity;
 import org.apache.commons.io.IOUtils;
 
-
-import static org.apache.camel.component.http.HttpMethods.HTTP_METHOD;
-
 /**
  * @version $Revision$
  */
@@ -111,6 +107,7 @@
 
         RequestEntity requestEntity = createRequestEntity(exchange);
         Object m = exchange.getIn().getHeader(HTTP_METHOD);
+        // TODO: Damm this is not readable code (nested ? - please dont)
         HttpMethods ms = m instanceof HttpMethods
             ? (HttpMethods)m : HttpMethods.valueOf(m == null
                                                        ? requestEntity == null

Added: activemq/camel/trunk/components/camel-http/src/test/java/org/apache/camel/component/http/HttpInvalidConfigurationTest.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-http/src/test/java/org/apache/camel/component/http/HttpInvalidConfigurationTest.java?rev=677999&view=auto
==============================================================================
--- activemq/camel/trunk/components/camel-http/src/test/java/org/apache/camel/component/http/HttpInvalidConfigurationTest.java
(added)
+++ activemq/camel/trunk/components/camel-http/src/test/java/org/apache/camel/component/http/HttpInvalidConfigurationTest.java
Fri Jul 18 11:58:03 2008
@@ -0,0 +1,35 @@
+package org.apache.camel.component.http;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.ResolveEndpointFailedException;
+import static org.apache.camel.component.http.HttpMethods.HTTP_METHOD;
+import static org.apache.camel.component.http.HttpMethods.POST;
+import org.apache.camel.builder.RouteBuilder;
+
+/**
+ * Unit test of invalid configuraiton
+ */
+public class HttpInvalidConfigurationTest 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."));
+        }
+    }
+
+    public void testInvalidHostConfiguratiob() {
+        // 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");
+            }
+        };
+    }
+
+}



Mime
View raw message