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 2010/03/21 13:28:45 UTC

svn commit: r925759 - in /camel/trunk/components: camel-http/ camel-http/src/main/java/org/apache/camel/component/http/ camel-http/src/test/java/org/apache/camel/component/http/ camel-jetty/ camel-jetty/src/main/java/org/apache/camel/component/jetty/ c...

Author: davsclaus
Date: Sun Mar 21 12:28:45 2010
New Revision: 925759

URL: http://svn.apache.org/viewvc?rev=925759&view=rev
Log:
CAMEL-2559: Fixed Http/Jetty components overriding component configured binding with endpoint. And some more fixes.

Added:
    camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpTwoServerPortsTest.java
      - copied, changed from r925107, camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpTwoEndpointTest.java
Modified:
    camel/trunk/components/camel-http/pom.xml
    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/HttpClientConfigurerTest.java
    camel/trunk/components/camel-http/src/test/java/org/apache/camel/component/http/HttpProducerSelectMethodTest.java
    camel/trunk/components/camel-jetty/pom.xml
    camel/trunk/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyHttpComponent.java
    camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/SpringHttpsRouteTest.java
    camel/trunk/components/camel-servlet/src/main/java/org/apache/camel/component/servlet/ServletComponent.java

Modified: camel/trunk/components/camel-http/pom.xml
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-http/pom.xml?rev=925759&r1=925758&r2=925759&view=diff
==============================================================================
--- camel/trunk/components/camel-http/pom.xml (original)
+++ camel/trunk/components/camel-http/pom.xml Sun Mar 21 12:28:45 2010
@@ -15,76 +15,90 @@
   See the License for the specific language governing permissions and
   limitations under the License.
 -->
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
 
-  <modelVersion>4.0.0</modelVersion>
+    <modelVersion>4.0.0</modelVersion>
+
+    <parent>
+        <groupId>org.apache.camel</groupId>
+        <artifactId>camel-parent</artifactId>
+        <version>2.3-SNAPSHOT</version>
+    </parent>
+
+    <artifactId>camel-http</artifactId>
+    <packaging>bundle</packaging>
+    <name>Camel :: HTTP</name>
+    <description>Camel HTTP support</description>
+
+    <properties>
+        <camel.osgi.export.pkg>org.apache.camel.component.http.*</camel.osgi.export.pkg>
+    </properties>
+
+    <dependencies>
+
+        <dependency>
+            <groupId>org.apache.camel</groupId>
+            <artifactId>camel-core</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.geronimo.specs</groupId>
+            <artifactId>geronimo-servlet_2.4_spec</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.httpcomponents</groupId>
+            <artifactId>httpclient</artifactId>
+            <version>${httpclient4-version}</version>
+        </dependency>
+
+        <!-- testing -->
+        <dependency>
+            <groupId>org.apache.camel</groupId>
+            <artifactId>camel-test</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <!-- to allow Spring annotations (jmx) to be tested -->
+        <dependency>
+            <groupId>org.springframework</groupId>
+            <artifactId>spring-context</artifactId>
+            <optional>true</optional>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.springframework</groupId>
+            <artifactId>spring-aop</artifactId>
+            <optional>true</optional>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>junit</groupId>
+            <artifactId>junit</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>log4j</groupId>
+            <artifactId>log4j</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.httpcomponents</groupId>
+            <artifactId>httpclient</artifactId>
+            <version>${httpclient4-version}</version>
+            <classifier>tests</classifier>
+            <scope>test</scope>
+        </dependency>
+    </dependencies>
+
+    <build>
+        <plugins>
+            <!-- use per test fork mode to avoid side effects -->
+            <plugin>
+              <artifactId>maven-surefire-plugin</artifactId>
+              <configuration>
+                <forkMode>pertest</forkMode>
+              </configuration>
+            </plugin>
+        </plugins>
+    </build>
 
-  <parent>
-    <groupId>org.apache.camel</groupId>
-    <artifactId>camel-parent</artifactId>
-    <version>2.3-SNAPSHOT</version>
-  </parent>
-
-  <artifactId>camel-http</artifactId>
-  <packaging>bundle</packaging>
-  <name>Camel :: HTTP</name>
-  <description>Camel HTTP support</description>
-
-  <properties>
-	<camel.osgi.export.pkg>org.apache.camel.component.http.*</camel.osgi.export.pkg>
-  </properties>
-
-  <dependencies>
-
-    <dependency>
-      <groupId>org.apache.camel</groupId>
-      <artifactId>camel-core</artifactId>
-    </dependency>
-    <dependency>
-      <groupId>org.apache.geronimo.specs</groupId>
-      <artifactId>geronimo-servlet_2.4_spec</artifactId>
-    </dependency>
-    <dependency>
-    	<groupId>org.apache.httpcomponents</groupId>
-    	<artifactId>httpclient</artifactId>
-    	<version>${httpclient4-version}</version>
-    </dependency>
-
-    <!-- testing -->
-    <dependency>
-      <groupId>org.apache.camel</groupId>
-      <artifactId>camel-test</artifactId>      
-      <scope>test</scope>
-    </dependency>
-    <!-- to allow Spring annotations (jmx) to be tested -->
-    <dependency>
-      <groupId>org.springframework</groupId>
-      <artifactId>spring-context</artifactId>
-      <optional>true</optional>
-      <scope>test</scope>
-    </dependency>
-    <dependency>
-      <groupId>org.springframework</groupId>
-      <artifactId>spring-aop</artifactId>
-      <optional>true</optional>
-      <scope>test</scope>
-    </dependency>
-    <dependency>
-      <groupId>junit</groupId>
-      <artifactId>junit</artifactId>
-      <scope>test</scope>
-    </dependency>
-    <dependency>
-      <groupId>log4j</groupId>
-      <artifactId>log4j</artifactId>
-      <scope>test</scope>
-    </dependency>
-    <dependency>
-    	<groupId>org.apache.httpcomponents</groupId>
-    	<artifactId>httpclient</artifactId>
-    	<version>${httpclient4-version}</version>
-    	<classifier>tests</classifier>
-    	<scope>test</scope>
-    </dependency>
-  </dependencies>
 </project>
\ No newline at end of file

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=925759&r1=925758&r2=925759&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 Sun Mar 21 12:28:45 2010
@@ -65,7 +65,7 @@ public class HttpComponent extends Heade
     /**
      * Connects the URL specified on the endpoint to the specified processor.
      *
-     * @param  consumer the consumer
+     * @param consumer the consumer
      * @throws Exception can be thrown
      */
     public void connect(HttpConsumer consumer) throws Exception {
@@ -74,30 +74,25 @@ public class HttpComponent extends Heade
     /**
      * Disconnects the URL specified on the endpoint from the specified processor.
      *
-     * @param  consumer the consumer
+     * @param consumer the consumer
      * @throws Exception can be thrown
      */
     public void disconnect(HttpConsumer consumer) throws Exception {
     }
 
     /**
-     * Setting http binding and http client configurer according to the parameters
-     * Also setting the BasicAuthenticationHttpClientConfigurer if the username
-     * and password option are not null.
+     * Creates the HttpClientConfigurer based on the given parameters
      *
      * @param parameters the map of parameters
+     * @return the configurer
      */
-    protected void configureParameters(Map<String, Object> parameters) {
-        // lookup http binding in registry if provided
-        if ( httpBinding == null ) {
-            httpBinding = resolveAndRemoveReferenceParameter(
-                    parameters, "httpBindingRef", HttpBinding.class);
-        }
-
-        // lookup http client front configurer in the registry if provided
-        if ( httpClientConfigurer == null ) {
-            httpClientConfigurer = resolveAndRemoveReferenceParameter(
-                    parameters, "httpClientConfigurerRef", HttpClientConfigurer.class);
+    protected HttpClientConfigurer createHttpClientConfigurer(Map<String, Object> parameters) {
+        // prefer to use endpoint configured over component configured
+        HttpClientConfigurer configurer = resolveAndRemoveReferenceParameter(
+                parameters, "httpClientConfigurerRef", HttpClientConfigurer.class);
+        if (configurer == null) {
+            // fallback to component configured
+            configurer = getHttpClientConfigurer();
         }
 
         // check the user name and password for basic authentication
@@ -106,8 +101,8 @@ public class HttpComponent extends Heade
         String domain = getAndRemoveParameter(parameters, "domain", String.class);
         String host = getAndRemoveParameter(parameters, "host", String.class);
         if (username != null && password != null) {
-            httpClientConfigurer = CompositeHttpConfigurer.combineConfigurers(
-                    httpClientConfigurer,
+            configurer = CompositeHttpConfigurer.combineConfigurers(
+                    configurer,
                     new BasicAuthenticationHttpClientConfigurer(username, password, domain, host));
         }
 
@@ -120,13 +115,15 @@ public class HttpComponent extends Heade
             String proxyDomain = getAndRemoveParameter(parameters, "proxyDomain", String.class);
             String proxyNtHost = getAndRemoveParameter(parameters, "proxyNtHost", String.class);
             if (proxyUsername != null && proxyPassword != null) {
-                httpClientConfigurer = CompositeHttpConfigurer.combineConfigurers(
-                        httpClientConfigurer, new ProxyHttpClientConfigurer(proxyHost, proxyPort, proxyUsername, proxyPassword, proxyDomain, proxyNtHost));
+                configurer = CompositeHttpConfigurer.combineConfigurers(
+                        configurer, new ProxyHttpClientConfigurer(proxyHost, proxyPort, proxyUsername, proxyPassword, proxyDomain, proxyNtHost));
             } else {
-                httpClientConfigurer = CompositeHttpConfigurer.combineConfigurers(
-                        httpClientConfigurer, new ProxyHttpClientConfigurer(proxyHost, proxyPort));
+                configurer = CompositeHttpConfigurer.combineConfigurers(
+                        configurer, new ProxyHttpClientConfigurer(proxyHost, proxyPort));
             }
         }
+
+        return configurer;
     }
 
     @Override
@@ -134,16 +131,17 @@ public class HttpComponent extends Heade
         // http client can be configured from URI options
         HttpParams clientParams = configureHttpParams(parameters);
 
-        // validate that we could resolve all httpClient. parameters as this component is lenient
-        validateParameters(uri, parameters, "httpClient.");
-        configureParameters(parameters);
-
-        // should we use an exception for failed error codes?
+        // must extract well known parameters before we create the endpoint
+        HttpBinding binding = resolveAndRemoveReferenceParameter(parameters, "httpBindingRef", HttpBinding.class);
         Boolean throwExceptionOnFailure = getAndRemoveParameter(parameters, "throwExceptionOnFailure", Boolean.class);
-
         Boolean bridgeEndpoint = getAndRemoveParameter(parameters, "bridgeEndpoint", Boolean.class);
+        Boolean matchOnUriPrefix = getAndRemoveParameter(parameters, "matchOnUriPrefix", Boolean.class);
+
+        // validate that we could resolve all httpClient. parameters as this component is lenient
+        validateParameters(uri, parameters, "httpClient.");
+        // create the configurer to use for this endpoint
+        HttpClientConfigurer configurer = createHttpClientConfigurer(parameters);
 
-        Boolean matchOnUriPrefix = Boolean.parseBoolean(getAndRemoveParameter(parameters, "matchOnUriPrefix", String.class));
         // restructure uri to be based on the parameters left as we dont want to include the Camel internal options
         URI httpUri = URISupport.createRemainingURI(new URI(uri), CastUtils.cast(parameters));
         uri = httpUri.toString();
@@ -158,18 +156,24 @@ public class HttpComponent extends Heade
             }
         }
 
-        // create default connection manager if none provided
-        if (clientConnectionManager == null) {
-            clientConnectionManager = createConnectionManager(clientParams, uri);
-        } else if (LOG.isDebugEnabled()) {
-            LOG.debug("Using existing ClientConnectionManager: " + clientConnectionManager);
-        }
+        // register port on schema registry
+        boolean secure = isSecureConnection(uri);
+        int port = getPort(httpUri);
+        registerPort(secure, port);
 
-        HttpEndpoint endpoint = new HttpEndpoint(uri, this, httpUri, clientParams, clientConnectionManager, httpClientConfigurer);
-        if (httpBinding != null) {
-            endpoint.setBinding(httpBinding);
-        }
+        // create the endpoint
+        HttpEndpoint endpoint = new HttpEndpoint(uri, this, httpUri, clientParams, clientConnectionManager, configurer);
         setEndpointHeaderFilterStrategy(endpoint);
+
+        // prefer to use endpoint configured over component configured
+        if (binding == null) {
+            // fallback to component configured
+            binding = getHttpBinding();
+        }
+        if (binding != null) {
+            endpoint.setBinding(binding);
+        }
+        // should we use an exception for failed error codes?
         if (throwExceptionOnFailure != null) {
             endpoint.setThrowExceptionOnFailure(throwExceptionOnFailure);
         }
@@ -179,20 +183,42 @@ public class HttpComponent extends Heade
         if (matchOnUriPrefix != null) {
             endpoint.setMatchOnUriPrefix(matchOnUriPrefix);
         }
+
         setProperties(endpoint, parameters);
         return endpoint;
     }
 
-    protected ClientConnectionManager createConnectionManager(HttpParams clientParams, String uri) {
-        SchemeRegistry schemeRegistry = new SchemeRegistry();
-        if (isSecureConnection(uri)) {
-            schemeRegistry.register(new Scheme("https", SSLSocketFactory.getSocketFactory(), 443));
+    private static int getPort(URI uri) {
+        int port = uri.getPort();
+        if (port < 0) {
+            if ("http".equals(uri.getScheme())) {
+                port = 80;
+            } else if ("https".equals(uri.getScheme())) {
+                port = 443;
+            } else {
+                throw new IllegalArgumentException("Unknown scheme, cannot determine port number for uri: " + uri);
+            }
+        }
+        return port;
+    }
+
+    protected void registerPort(boolean secure, int port) {
+        SchemeRegistry registry = clientConnectionManager.getSchemeRegistry();
+        if (secure) {
+            registry.register(new Scheme("https", SSLSocketFactory.getSocketFactory(), port));
+            LOG.info("Registering SSL scheme https on port " + port);
         } else {
-            schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
+            registry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), port));
+            LOG.info("Registering PLAIN scheme http on port " + port);
         }
+    }
+
+    protected ClientConnectionManager createConnectionManager() {
+        SchemeRegistry schemeRegistry = new SchemeRegistry();
 
         // configure additional configurations
-        ConnManagerParamBean param = new ConnManagerParamBean(clientParams);
+        HttpParams params = new BasicHttpParams();
+        ConnManagerParamBean param = new ConnManagerParamBean(params);
         if (getMaxTotalConnections() > 0) {
             param.setMaxTotalConnections(getMaxTotalConnections());
         }
@@ -200,9 +226,7 @@ public class HttpComponent extends Heade
             param.setConnectionsPerRoute(new ConnPerRouteBean(getConnectionsPerRoute()));
         }
 
-        ThreadSafeClientConnManager answer;
-        answer = new ThreadSafeClientConnManager(clientParams, schemeRegistry);
-
+        ThreadSafeClientConnManager answer = new ThreadSafeClientConnManager(params, schemeRegistry);
         LOG.info("Created ClientConnectionManager " + answer);
 
         return answer;
@@ -288,6 +312,14 @@ public class HttpComponent extends Heade
     }
 
     @Override
+    public void start() throws Exception {
+        super.start();
+        if (clientConnectionManager == null) {
+            clientConnectionManager = createConnectionManager();
+        }
+    }
+
+    @Override
     public void stop() throws Exception {
         // shutdown connection manager
         if (clientConnectionManager != null) {

Modified: camel/trunk/components/camel-http/src/test/java/org/apache/camel/component/http/HttpClientConfigurerTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-http/src/test/java/org/apache/camel/component/http/HttpClientConfigurerTest.java?rev=925759&r1=925758&r2=925759&view=diff
==============================================================================
--- camel/trunk/components/camel-http/src/test/java/org/apache/camel/component/http/HttpClientConfigurerTest.java (original)
+++ camel/trunk/components/camel-http/src/test/java/org/apache/camel/component/http/HttpClientConfigurerTest.java Sun Mar 21 12:28:45 2010
@@ -18,36 +18,26 @@ package org.apache.camel.component.http;
 
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.test.junit4.CamelTestSupport;
-import org.junit.Ignore;
 import org.junit.Test;
 
 /**
  * @version $Revision: 905992 $
  */
 public class HttpClientConfigurerTest extends CamelTestSupport {
-    protected String expectedText = "activemq";
+    private HttpClientConfigurer configurer;
     
     @Test
     public void testHttpClientConfigurer() throws Exception {
-        HttpClientConfigurer configurer = getMandatoryEndpoint("http://www.google.com/search", HttpEndpoint.class).getHttpClientConfigurer();
-
-        assertNotNull("Client configurer should not be null!", configurer);
-
+        HttpClientConfigurer gotConfigurer = getMandatoryEndpoint("http://www.google.com/search", HttpEndpoint.class).getHttpClientConfigurer();
+        assertSame(configurer, gotConfigurer);
     }
 
     @Override
     protected RouteBuilder createRouteBuilder() throws Exception {
         return new RouteBuilder() {
             public void configure() {
-
-                ProxyHttpClientConfigurer configurer = new ProxyHttpClientConfigurer(
-                        "proxyhost",
-                        80,
-                        "user",
-                        "password",
-                        null,
-                        null);
-
+                // add configurer to http component
+                configurer = new ProxyHttpClientConfigurer("proxyhost", 80, "user", "password", null, null);
                 getContext().getComponent("http", HttpComponent.class).setHttpClientConfigurer(configurer);
 
                 from("direct:start")

Modified: camel/trunk/components/camel-http/src/test/java/org/apache/camel/component/http/HttpProducerSelectMethodTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-http/src/test/java/org/apache/camel/component/http/HttpProducerSelectMethodTest.java?rev=925759&r1=925758&r2=925759&view=diff
==============================================================================
--- camel/trunk/components/camel-http/src/test/java/org/apache/camel/component/http/HttpProducerSelectMethodTest.java (original)
+++ camel/trunk/components/camel-http/src/test/java/org/apache/camel/component/http/HttpProducerSelectMethodTest.java Sun Mar 21 12:28:45 2010
@@ -34,8 +34,8 @@ public class HttpProducerSelectMethodTes
     public void noDataDefaultIsGet() throws Exception {
         localServer.register("/", new BasicValidationHandler("GET", null, null, getExpectedContent()));
 
-        HttpComponent component = new HttpComponent();
-        component.setCamelContext(context);
+        HttpComponent component = context.getComponent("http", HttpComponent.class);
+        
         HttpEndpoint endpoiont = (HttpEndpoint) component.createEndpoint("http://" + getHostName() + ":" + getPort());
         HttpProducer producer = new HttpProducer(endpoiont);
         Exchange exchange = producer.createExchange();
@@ -51,8 +51,8 @@ public class HttpProducerSelectMethodTes
     public void dataDefaultIsPost() throws Exception {
         localServer.register("/", new BasicValidationHandler("POST", null, null, getExpectedContent()));
 
-        HttpComponent component = new HttpComponent();
-        component.setCamelContext(context);
+        HttpComponent component = context.getComponent("http", HttpComponent.class);
+
         HttpEndpoint endpoiont = (HttpEndpoint) component.createEndpoint("http://" + getHostName() + ":" + getPort());
         HttpProducer producer = new HttpProducer(endpoiont);
 
@@ -69,8 +69,8 @@ public class HttpProducerSelectMethodTes
     public void withMethodPostInHeader() throws Exception {
         localServer.register("/", new BasicValidationHandler("POST", null, null, getExpectedContent()));
 
-        HttpComponent component = new HttpComponent();
-        component.setCamelContext(context);
+        HttpComponent component = context.getComponent("http", HttpComponent.class);
+
         HttpEndpoint endpoiont = (HttpEndpoint) component.createEndpoint("http://" + getHostName() + ":" + getPort());
         HttpProducer producer = new HttpProducer(endpoiont);
 
@@ -86,8 +86,8 @@ public class HttpProducerSelectMethodTes
     public void withMethodGetInHeader() throws Exception {
         localServer.register("/", new BasicValidationHandler("GET", null, null, getExpectedContent()));
 
-        HttpComponent component = new HttpComponent();
-        component.setCamelContext(context);
+        HttpComponent component = context.getComponent("http", HttpComponent.class);
+
         HttpEndpoint endpoiont = (HttpEndpoint) component.createEndpoint("http://" + getHostName() + ":" + getPort());
         HttpProducer producer = new HttpProducer(endpoiont);
 
@@ -103,8 +103,8 @@ public class HttpProducerSelectMethodTes
     public void withEndpointQuery() throws Exception {
         localServer.register("/", new BasicValidationHandler("GET", "q=Camel", null, getExpectedContent()));
 
-        HttpComponent component = new HttpComponent();
-        component.setCamelContext(context);
+        HttpComponent component = context.getComponent("http", HttpComponent.class);
+
         HttpEndpoint endpoiont = (HttpEndpoint) component.createEndpoint("http://" + getHostName() + ":" + getPort() + "?q=Camel");
         HttpProducer producer = new HttpProducer(endpoiont);
 
@@ -119,8 +119,8 @@ public class HttpProducerSelectMethodTes
     public void withQueryInHeader() throws Exception {
         localServer.register("/", new BasicValidationHandler("GET", "q=Camel", null, getExpectedContent()));
 
-        HttpComponent component = new HttpComponent();
-        component.setCamelContext(context);
+        HttpComponent component = context.getComponent("http", HttpComponent.class);
+
         HttpEndpoint endpoiont = (HttpEndpoint) component.createEndpoint("http://" + getHostName() + ":" + getPort());
         HttpProducer producer = new HttpProducer(endpoiont);
 
@@ -136,8 +136,8 @@ public class HttpProducerSelectMethodTes
     public void withQueryInHeaderOverrideEndpoint() throws Exception {
         localServer.register("/", new BasicValidationHandler("GET", "q=Camel", null, getExpectedContent()));
 
-        HttpComponent component = new HttpComponent();
-        component.setCamelContext(context);
+        HttpComponent component = context.getComponent("http", HttpComponent.class);
+
         HttpEndpoint endpoiont = (HttpEndpoint) component.createEndpoint("http://" + getHostName() + ":" + getPort() + "?q=Donkey");
         HttpProducer producer = new HttpProducer(endpoiont);
 

Modified: camel/trunk/components/camel-jetty/pom.xml
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-jetty/pom.xml?rev=925759&r1=925758&r2=925759&view=diff
==============================================================================
--- camel/trunk/components/camel-jetty/pom.xml (original)
+++ camel/trunk/components/camel-jetty/pom.xml Sun Mar 21 12:28:45 2010
@@ -15,128 +15,124 @@
   See the License for the specific language governing permissions and
   limitations under the License.
 -->
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
 
-  <modelVersion>4.0.0</modelVersion>
+    <modelVersion>4.0.0</modelVersion>
+
+    <parent>
+        <groupId>org.apache.camel</groupId>
+        <artifactId>camel-parent</artifactId>
+        <version>2.3-SNAPSHOT</version>
+    </parent>
+
+    <artifactId>camel-jetty</artifactId>
+    <packaging>bundle</packaging>
+    <name>Camel :: Jetty</name>
+    <description>Camel Jetty support</description>
+
+    <properties>
+        <camel.osgi.export.pkg>org.apache.camel.component.jetty.*</camel.osgi.export.pkg>
+    </properties>
+
+    <dependencies>
+
+        <dependency>
+            <groupId>org.apache.camel</groupId>
+            <artifactId>camel-core</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.camel</groupId>
+            <artifactId>camel-http</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.eclipse.jetty</groupId>
+            <artifactId>jetty-server</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.eclipse.jetty</groupId>
+            <artifactId>jetty-security</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.eclipse.jetty</groupId>
+            <artifactId>jetty-servlet</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.eclipse.jetty</groupId>
+            <artifactId>jetty-servlets</artifactId>
+            <version>${jetty-version}</version>
+        </dependency>
+        <dependency>
+            <groupId>org.eclipse.jetty</groupId>
+            <artifactId>jetty-client</artifactId>
+        </dependency>
+
+        <!-- testing -->
+        <dependency>
+            <groupId>org.apache.camel</groupId>
+            <artifactId>camel-test</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.camel</groupId>
+            <artifactId>camel-spring</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.httpcomponents</groupId>
+            <artifactId>httpmime</artifactId>
+            <version>${httpclient4-version}</version>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.httpcomponents</groupId>
+            <artifactId>httpclient</artifactId>
+            <version>${httpclient4-version}</version>
+            <classifier>tests</classifier>
+            <scope>test</scope>
+        </dependency>
+        <!-- to allow Spring annotations (jmx) to be tested -->
+        <dependency>
+            <groupId>org.springframework</groupId>
+            <artifactId>spring-context</artifactId>
+            <optional>true</optional>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.springframework</groupId>
+            <artifactId>spring-aop</artifactId>
+            <optional>true</optional>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.springframework</groupId>
+            <artifactId>spring-test</artifactId>
+            <optional>true</optional>
+            <scope>test</scope>
+        </dependency>
+
+        <dependency>
+            <groupId>junit</groupId>
+            <artifactId>junit</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>log4j</groupId>
+            <artifactId>log4j</artifactId>
+            <scope>test</scope>
+        </dependency>
+    </dependencies>
+
+    <build>
+        <plugins>
+            <!-- use per test fork mode to avoid side effects -->
+            <plugin>
+                <artifactId>maven-surefire-plugin</artifactId>
+                <configuration>
+                    <forkMode>pertest</forkMode>
+                </configuration>
+            </plugin>
+        </plugins>
+    </build>
 
-  <parent>
-    <groupId>org.apache.camel</groupId>
-    <artifactId>camel-parent</artifactId>
-    <version>2.3-SNAPSHOT</version>
-  </parent>
-
-  <artifactId>camel-jetty</artifactId>
-  <packaging>bundle</packaging>
-  <name>Camel :: Jetty</name>
-  <description>Camel Jetty support</description>
-
-  <properties>
-	<camel.osgi.export.pkg>org.apache.camel.component.jetty.*</camel.osgi.export.pkg>
-  </properties>
-  
-  <dependencies>
-
-    <dependency>
-      <groupId>org.apache.camel</groupId>
-      <artifactId>camel-core</artifactId>
-    </dependency>
-    <dependency>
-      <groupId>org.apache.camel</groupId>
-      <artifactId>camel-http</artifactId>
-    </dependency>
-    <dependency>
-      <groupId>org.eclipse.jetty</groupId>
-      <artifactId>jetty-server</artifactId>
-    </dependency>
-    <dependency>
-      <groupId>org.eclipse.jetty</groupId>
-      <artifactId>jetty-security</artifactId>
-    </dependency>
-    <dependency>
-      <groupId>org.eclipse.jetty</groupId>
-      <artifactId>jetty-servlet</artifactId>
-    </dependency>
-    <dependency>
-      <groupId>org.eclipse.jetty</groupId>
-      <artifactId>jetty-servlets</artifactId>
-      <version>${jetty-version}</version>
-    </dependency>
-    <dependency>
-      <groupId>org.eclipse.jetty</groupId>
-      <artifactId>jetty-client</artifactId>
-    </dependency>
-
-    <!-- testing -->
-    <dependency>
-      <groupId>org.apache.camel</groupId>
-      <artifactId>camel-test</artifactId>      
-      <scope>test</scope>
-    </dependency>    
-    <dependency>
-      <groupId>org.apache.camel</groupId>
-      <artifactId>camel-spring</artifactId>
-      <scope>test</scope>
-    </dependency>
-    <dependency>
-      <groupId>org.apache.httpcomponents</groupId>
-      <artifactId>httpmime</artifactId>
-      <version>${httpclient4-version}</version>
-      <scope>test</scope>
-    </dependency>
-    <dependency>
-      <groupId>org.apache.httpcomponents</groupId>
-      <artifactId>httpclient</artifactId>
-      <version>${httpclient4-version}</version>
-      <classifier>tests</classifier>
-      <scope>test</scope>
-    </dependency>
-    <!-- to allow Spring annotations (jmx) to be tested -->
-    <dependency>
-      <groupId>org.springframework</groupId>
-      <artifactId>spring-context</artifactId>
-      <optional>true</optional>
-      <scope>test</scope>
-    </dependency>
-    <dependency>
-      <groupId>org.springframework</groupId>
-      <artifactId>spring-aop</artifactId>
-      <optional>true</optional>
-      <scope>test</scope>
-    </dependency>
-    <dependency>
-      <groupId>org.springframework</groupId>
-      <artifactId>spring-test</artifactId>
-      <optional>true</optional>
-      <scope>test</scope>
-    </dependency>
-
-    <dependency>
-      <groupId>junit</groupId>
-      <artifactId>junit</artifactId>
-      <scope>test</scope>
-    </dependency>
-    <dependency>
-      <groupId>log4j</groupId>
-      <artifactId>log4j</artifactId>
-      <scope>test</scope>
-    </dependency>
-  </dependencies>
-  
-  <build>
-    <plugins>
-      <plugin>
-        <groupId>org.apache.maven.plugins</groupId>
-        <artifactId>maven-surefire-plugin</artifactId>
-        <configuration>
-          <forkMode>pertest</forkMode>
-          <childDelegation>false</childDelegation>
-          <useFile>true</useFile>
-          <failIfNoTests>false</failIfNoTests>
-          <includes>
-            <include>**/*Test.java</include>
-          </includes>
-        </configuration>
-      </plugin>
-    </plugins>
-  </build>
 </project>
\ No newline at end of file

Modified: camel/trunk/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyHttpComponent.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyHttpComponent.java?rev=925759&r1=925758&r2=925759&view=diff
==============================================================================
--- camel/trunk/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyHttpComponent.java (original)
+++ camel/trunk/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyHttpComponent.java Sun Mar 21 12:28:45 2010
@@ -25,6 +25,7 @@ import org.apache.camel.CamelContext;
 import org.apache.camel.Endpoint;
 import org.apache.camel.RuntimeCamelException;
 import org.apache.camel.component.http.CamelServlet;
+import org.apache.camel.component.http.HttpBinding;
 import org.apache.camel.component.http.HttpComponent;
 import org.apache.camel.component.http.HttpConsumer;
 import org.apache.camel.component.http.HttpEndpoint;
@@ -103,37 +104,60 @@ public class JettyHttpComponent extends 
     protected Endpoint createEndpoint(String uri, String remaining, Map<String, Object> parameters) throws Exception {
         uri = uri.startsWith("jetty:") ? remaining : uri;
 
+        // must extract well known parameters before we create the endpoint
         List<Handler> handlerList = resolveAndRemoveReferenceListParameter(parameters, "handlers", Handler.class);
-        
-        // configure regular parameters
-        configureParameters(parameters);
-
-        JettyHttpEndpoint result = new JettyHttpEndpoint(this, uri, null);
-        if (httpBinding != null) {
-            result.setBinding(httpBinding);
-        }
-        setEndpointHeaderFilterStrategy(result);
-        if (handlerList.size() > 0) {
-            result.setHandlers(handlerList);
-        }
-        setProperties(result, parameters);
+        HttpBinding binding = resolveAndRemoveReferenceParameter(parameters, "httpBindingRef", HttpBinding.class);
+        Boolean throwExceptionOnFailure = getAndRemoveParameter(parameters, "throwExceptionOnFailure", Boolean.class);
+        Boolean bridgeEndpoint = getAndRemoveParameter(parameters, "bridgeEndpoint", Boolean.class);
+        Boolean matchOnUriPrefix = getAndRemoveParameter(parameters, "matchOnUriPrefix", Boolean.class);
 
         // configure http client if we have url configuration for it
+        // http client is only used for jetty http producer (hence not very commonly used)
+        HttpClient client = null;
         if (IntrospectionSupport.hasProperties(parameters, "httpClient.")) {
-            // configure Jetty http client
-            result.setClient(getHttpClient());
             // set additional parameters on http client
-            IntrospectionSupport.setProperties(getHttpClient(), parameters, "httpClient.");
+            // only create client when needed
+            client = getHttpClient();
+            IntrospectionSupport.setProperties(client, parameters, "httpClient.");
             // validate that we could resolve all httpClient. parameters as this component is lenient
             validateParameters(uri, parameters, "httpClient.");
         }
 
-        // create the http uri after we have configured all the parameters on the camel objects
-        URI httpUri = URISupport.createRemainingURI(new URI(UnsafeUriCharactersEncoder.encode(uri)), 
-                CastUtils.cast(parameters));
-        result.setHttpUri(httpUri);
+        // restructure uri to be based on the parameters left as we dont want to include the Camel internal options
+        URI httpUri = URISupport.createRemainingURI(new URI(uri), CastUtils.cast(parameters));
+        uri = httpUri.toString();
+
+        // create endpoint after all known parameters have been extracted from parameters
+        JettyHttpEndpoint endpoint = new JettyHttpEndpoint(this, uri, httpUri);
+        setEndpointHeaderFilterStrategy(endpoint);
+
+        if (client != null) {
+            endpoint.setClient(client);
+        }
+        if (handlerList.size() > 0) {
+            endpoint.setHandlers(handlerList);
+        }
+        // prefer to use endpoint configured over component configured
+        if (binding == null) {
+            // fallback to component configured
+            binding = getHttpBinding();
+        }
+        if (binding != null) {
+            endpoint.setBinding(binding);
+        }
+        // should we use an exception for failed error codes?
+        if (throwExceptionOnFailure != null) {
+            endpoint.setThrowExceptionOnFailure(throwExceptionOnFailure);
+        }
+        if (bridgeEndpoint != null) {
+            endpoint.setBridgeEndpoint(bridgeEndpoint);
+        }
+        if (matchOnUriPrefix != null) {
+            endpoint.setMatchOnUriPrefix(matchOnUriPrefix);
+        }
 
-        return result;
+        setProperties(endpoint, parameters);
+        return endpoint;
     }
 
     /**

Copied: camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpTwoServerPortsTest.java (from r925107, camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpTwoEndpointTest.java)
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpTwoServerPortsTest.java?p2=camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpTwoServerPortsTest.java&p1=camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpTwoEndpointTest.java&r1=925107&r2=925759&rev=925759&view=diff
==============================================================================
--- camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpTwoEndpointTest.java (original)
+++ camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpTwoServerPortsTest.java Sun Mar 21 12:28:45 2010
@@ -25,23 +25,21 @@ import org.junit.Test;
 /**
  * @version $Revision$
  */
-public class HttpTwoEndpointTest extends CamelTestSupport {
+public class HttpTwoServerPortsTest extends CamelTestSupport {
 
     @Test
-    public void testTwoEndpoints() throws Exception {
-        Exchange a = template.request("direct:a", null);
-        assertNotNull(a);
+    public void testTwoServerPorts() throws Exception {
+        String reply = template.requestBody("direct:a", "World", String.class);
+        assertEquals("Bye World", reply);
 
-        Exchange b = template.request("direct:b", null);
-        assertNotNull(b);
+        reply = template.requestBody("direct:b", "Camel", String.class);
+        assertEquals("Hi Camel", reply);
 
-        assertEquals("Bye cheese", a.getOut().getBody(String.class));
-        assertEquals(246, a.getOut().getHeader("foo", Integer.class).intValue());
+        reply = template.requestBody("direct:a", "Earth", String.class);
+        assertEquals("Bye Earth", reply);
 
-        assertEquals("Bye cake", b.getOut().getBody(String.class));
-        assertEquals(912, b.getOut().getHeader("foo", Integer.class).intValue());
-
-        assertEquals(5, context.getEndpoints().size());
+        reply = template.requestBody("direct:b", "Moon", String.class);
+        assertEquals("Hi Moon", reply);
     }
 
     @Override
@@ -49,20 +47,24 @@ public class HttpTwoEndpointTest extends
         return new RouteBuilder() {
             @Override
             public void configure() throws Exception {
-                from("direct:a").to("http://localhost:9888/myapp?foo=123&bar=cheese");
+                from("direct:a").to("http://localhost:9777/myapp");
 
-                from("direct:b").to("http://localhost:9888/myapp?foo=456&bar=cake");
+                from("direct:b").to("http://localhost:9888/myotherapp");
 
-                from("jetty://http://localhost:9888/myapp").process(new Processor() {
+                from("jetty://http://localhost:9777/myapp").process(new Processor() {
                     public void process(Exchange exchange) throws Exception {
-                        int foo = exchange.getIn().getHeader("foo", Integer.class);
-                        String bar = exchange.getIn().getHeader("bar", String.class);
+                        String in = exchange.getIn().getBody(String.class);
+                        exchange.getOut().setBody("Bye " + in);
+                    }
+                });
 
-                        exchange.getOut().setHeader("foo", foo * 2);
-                        exchange.getOut().setBody("Bye " + bar);
+                from("jetty://http://localhost:9888/myotherapp").process(new Processor() {
+                    public void process(Exchange exchange) throws Exception {
+                        String in = exchange.getIn().getBody(String.class);
+                        exchange.getOut().setBody("Hi " + in);
                     }
                 });
             }
         };
     }
-}
+}
\ No newline at end of file

Modified: camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/SpringHttpsRouteTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/SpringHttpsRouteTest.java?rev=925759&r1=925758&r2=925759&view=diff
==============================================================================
--- camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/SpringHttpsRouteTest.java (original)
+++ camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/SpringHttpsRouteTest.java Sun Mar 21 12:28:45 2010
@@ -78,7 +78,7 @@ public class SpringHttpsRouteTest {
 
     private void restoreSystemProperties() {
         for (Object key : originalValues.keySet()) {
-            Object value = (String) originalValues.get(key);
+            Object value = originalValues.get(key);
             if (NULL_VALUE_MARKER.equals(value)) {
                 System.getProperties().remove(key);
             } else {

Modified: camel/trunk/components/camel-servlet/src/main/java/org/apache/camel/component/servlet/ServletComponent.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-servlet/src/main/java/org/apache/camel/component/servlet/ServletComponent.java?rev=925759&r1=925758&r2=925759&view=diff
==============================================================================
--- camel/trunk/components/camel-servlet/src/main/java/org/apache/camel/component/servlet/ServletComponent.java (original)
+++ camel/trunk/components/camel-servlet/src/main/java/org/apache/camel/component/servlet/ServletComponent.java Sun Mar 21 12:28:45 2010
@@ -21,6 +21,7 @@ import java.util.Map;
 
 import org.apache.camel.Endpoint;
 import org.apache.camel.component.http.CamelServlet;
+import org.apache.camel.component.http.HttpBinding;
 import org.apache.camel.component.http.HttpClientConfigurer;
 import org.apache.camel.component.http.HttpComponent;
 import org.apache.camel.component.http.HttpConsumer;
@@ -59,21 +60,31 @@ public class ServletComponent extends Ht
 
         HttpParams clientParams = configureHttpParams(parameters);
 
-        // configure regular parameters
-        configureParameters(parameters);
+        // must extract well known parameters before we create the endpoint
+        HttpBinding binding = resolveAndRemoveReferenceParameter(parameters, "httpBindingRef", HttpBinding.class);
+        Boolean matchOnUriPrefix = getAndRemoveParameter(parameters, "matchOnUriPrefix", Boolean.class);
 
         // restructure uri to be based on the parameters left as we dont want to include the Camel internal options
-        URI httpUri = URISupport.createRemainingURI(new URI(UnsafeUriCharactersEncoder.encode(uri)), 
-                CastUtils.cast(parameters));
+        URI httpUri = URISupport.createRemainingURI(new URI(UnsafeUriCharactersEncoder.encode(uri)), CastUtils.cast(parameters));
         uri = httpUri.toString();
 
-        ServletEndpoint result = createServletEndpoint(uri, this, httpUri, clientParams, getClientConnectionManager(), httpClientConfigurer);
-        if (httpBinding != null) {
-            result.setBinding(httpBinding);
+        ServletEndpoint endpoint = createServletEndpoint(uri, this, httpUri, clientParams, getClientConnectionManager(), httpClientConfigurer);
+        setEndpointHeaderFilterStrategy(endpoint);
+
+        // prefer to use endpoint configured over component configured
+        if (binding == null) {
+            // fallback to component configured
+            binding = getHttpBinding();
+        }
+        if (binding != null) {
+            endpoint.setBinding(binding);
         }
-        setEndpointHeaderFilterStrategy(result);        
-        setProperties(result, parameters);
-        return result;
+        if (matchOnUriPrefix != null) {
+            endpoint.setMatchOnUriPrefix(matchOnUriPrefix);
+        }
+
+        setProperties(endpoint, parameters);
+        return endpoint;
     }
 
     protected ServletEndpoint createServletEndpoint(String endpointUri,