camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ningji...@apache.org
Subject svn commit: r730936 - in /activemq/camel/trunk/components: camel-http/src/main/java/org/apache/camel/component/http/ camel-jetty/ camel-jetty/src/main/java/org/apache/camel/component/jetty/ camel-jetty/src/test/java/org/apache/camel/component/jetty/
Date Sat, 03 Jan 2009 08:24:31 GMT
Author: ningjiang
Date: Sat Jan  3 00:24:31 2009
New Revision: 730936

URL: http://svn.apache.org/viewvc?rev=730936&view=rev
Log:
CAMEL-1217  Get the Jetty component's 'httpClient.' options to be set into the indeed apache
http client; also some refactoring of camel-http component

Modified:
    activemq/camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/BasicAuthenticationHttpClientConfigurer.java
    activemq/camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/HttpComponent.java
    activemq/camel/trunk/components/camel-jetty/pom.xml
    activemq/camel/trunk/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyHttpComponent.java
    activemq/camel/trunk/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyHttpEndpoint.java
    activemq/camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/JettyHttpClientOptionsTest.java

Modified: activemq/camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/BasicAuthenticationHttpClientConfigurer.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/BasicAuthenticationHttpClientConfigurer.java?rev=730936&r1=730935&r2=730936&view=diff
==============================================================================
--- activemq/camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/BasicAuthenticationHttpClientConfigurer.java
(original)
+++ activemq/camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/BasicAuthenticationHttpClientConfigurer.java
Sat Jan  3 00:24:31 2009
@@ -1,3 +1,19 @@
+/**
+ * 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.commons.httpclient.Credentials;

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=730936&r1=730935&r2=730936&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
Sat Jan  3 00:24:31 2009
@@ -65,14 +65,15 @@
     public void disconnect(HttpConsumer consumer) throws Exception {
     }
 
-    @Override
-    protected Endpoint createEndpoint(String uri, String remaining, Map parameters)
-        throws Exception {
-
-        // http client can be configured from URI options
-        HttpClientParams params = new HttpClientParams();
-        IntrospectionSupport.setProperties(params, parameters, "httpClient.");
-
+    /** 
+     * Setting http binding and http client configurer according to the parameters
+     * Also setting the BasicAuthenticationHttpClientConfigurer if the username 
+     * and password option are not null.
+     * 
+     * @param parameters the map of parameters 
+     * 
+     */
+    protected void configureParameters(Map parameters) {
         // lookup http binding in registry if provided
         String ref = getAndRemoveParameter(parameters, "httpBindingRef", String.class);
         if (ref != null) {
@@ -91,6 +92,17 @@
         if (ref != null) {
             httpClientConfigurer = CamelContextHelper.mandatoryLookup(getCamelContext(),
ref, HttpClientConfigurer.class);
         }
+    }
+    
+    @Override
+    protected Endpoint createEndpoint(String uri, String remaining, Map parameters)
+        throws Exception {
+
+        // http client can be configured from URI options
+        HttpClientParams params = new HttpClientParams();
+        IntrospectionSupport.setProperties(params, parameters, "httpClient.");        
+        
+        configureParameters(parameters);
 
         // 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), parameters);

Modified: activemq/camel/trunk/components/camel-jetty/pom.xml
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-jetty/pom.xml?rev=730936&r1=730935&r2=730936&view=diff
==============================================================================
--- activemq/camel/trunk/components/camel-jetty/pom.xml (original)
+++ activemq/camel/trunk/components/camel-jetty/pom.xml Sat Jan  3 00:24:31 2009
@@ -51,11 +51,7 @@
       <groupId>org.mortbay.jetty</groupId>
       <artifactId>jetty</artifactId>
     </dependency>
-    <dependency>
-      <groupId>org.mortbay.jetty</groupId>
-      <artifactId>jetty-client</artifactId>
-    </dependency>
-
+    
     <!-- testing -->
     <dependency>
       <groupId>org.apache.camel</groupId>

Modified: activemq/camel/trunk/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyHttpComponent.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyHttpComponent.java?rev=730936&r1=730935&r2=730936&view=diff
==============================================================================
--- activemq/camel/trunk/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyHttpComponent.java
(original)
+++ activemq/camel/trunk/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyHttpComponent.java
Sat Jan  3 00:24:31 2009
@@ -22,18 +22,16 @@
 
 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.HttpComponent;
 import org.apache.camel.component.http.HttpConsumer;
 import org.apache.camel.component.http.HttpEndpoint;
-import org.apache.camel.util.CamelContextHelper;
 import org.apache.camel.util.IntrospectionSupport;
 import org.apache.camel.util.URISupport;
+import org.apache.commons.httpclient.params.HttpClientParams;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.mortbay.jetty.Connector;
 import org.mortbay.jetty.Server;
-import org.mortbay.jetty.client.HttpClient;
 import org.mortbay.jetty.handler.ContextHandlerCollection;
 import org.mortbay.jetty.nio.SelectChannelConnector;
 import org.mortbay.jetty.security.SslSocketConnector;
@@ -72,8 +70,7 @@
     private static final transient Log LOG = LogFactory.getLog(JettyHttpComponent.class);
     
     protected Server server;
-    protected HashMap<String, ConnectorRef> connectors = new HashMap<String, ConnectorRef>();
-    protected HttpClient httpClient;
+    protected HashMap<String, ConnectorRef> connectors = new HashMap<String, ConnectorRef>();
   
     protected String sslKeyPassword;
     protected String sslPassword;
     protected String sslKeystore;
@@ -83,23 +80,16 @@
     protected Endpoint createEndpoint(String uri, String remaining, Map parameters) throws
Exception {
         uri = uri.startsWith("jetty:") ? remaining : uri;
 
-        // http client can be configured from URI options
-        if (httpClient == null) {
-            httpClient = createHttpClient();
-        }
-        IntrospectionSupport.setProperties(httpClient, parameters, "httpClient.");
-
-        // lookup http binding in registry if provided
-        String ref = getAndRemoveParameter(parameters, "httpBindingRef", String.class);
-        if (ref != null) {
-            httpBinding = CamelContextHelper.mandatoryLookup(getCamelContext(), ref, HttpBinding.class);
-        }
+        HttpClientParams params = new HttpClientParams();
+        IntrospectionSupport.setProperties(params, parameters, "httpClient.");   
+
+        configureParameters(parameters);
 
         // 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), parameters);
         uri = httpUri.toString();
 
-        JettyHttpEndpoint result = new JettyHttpEndpoint(this, uri, httpUri, getHttpConnectionManager());
+        JettyHttpEndpoint result = new JettyHttpEndpoint(this, uri, httpUri, params, getHttpConnectionManager(),
httpClientConfigurer);
         if (httpBinding != null) {
             result.setBinding(httpBinding);
         }
@@ -283,31 +273,8 @@
         if (server != null) {
             server.stop();
         }
-        httpClient.stop();
+        
         super.doStop();
     }
-
-    @Override
-    protected void doStart() throws Exception {
-        super.doStart();
-        if (httpClient == null) {
-            httpClient = createHttpClient();
-        }
-        httpClient.start();
-    }
-
-    protected HttpClient createHttpClient() throws Exception {
-        HttpClient httpClient = new HttpClient();
-        httpClient.setConnectorType(HttpClient.CONNECTOR_SELECT_CHANNEL);
-        httpClient.setMaxConnectionsPerAddress(2);
-        return httpClient;
-    }
-
-    public HttpClient getHttpClient() {
-        return httpClient;
-    }
-
-    public void setHttpClient(HttpClient httpClient) {
-        this.httpClient = httpClient;
-    }
+   
 }

Modified: activemq/camel/trunk/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyHttpEndpoint.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyHttpEndpoint.java?rev=730936&r1=730935&r2=730936&view=diff
==============================================================================
--- activemq/camel/trunk/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyHttpEndpoint.java
(original)
+++ activemq/camel/trunk/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyHttpEndpoint.java
Sat Jan  3 00:24:31 2009
@@ -24,10 +24,12 @@
 import org.apache.camel.PollingConsumer;
 import org.apache.camel.Processor;
 import org.apache.camel.Producer;
+import org.apache.camel.component.http.HttpClientConfigurer;
 import org.apache.camel.component.http.HttpConsumer;
 import org.apache.camel.component.http.HttpEndpoint;
 import org.apache.camel.component.http.HttpPollingConsumer;
 import org.apache.commons.httpclient.HttpConnectionManager;
+import org.apache.commons.httpclient.params.HttpClientParams;
 
 /**
  * @version $Revision$
@@ -36,8 +38,9 @@
     private JettyHttpComponent component;
     private boolean sessionSupport;
 
-    public JettyHttpEndpoint(JettyHttpComponent component, String uri, URI httpURL, HttpConnectionManager
httpConnectionManager) throws URISyntaxException {
-        super(uri, component, httpURL, httpConnectionManager);
+    public JettyHttpEndpoint(JettyHttpComponent component, String uri, URI httpURL, HttpClientParams
clientParams,
+                             HttpConnectionManager httpConnectionManager, HttpClientConfigurer
clientConfigurer) throws URISyntaxException {
+        super(uri, component, httpURL, clientParams, httpConnectionManager, clientConfigurer);
         this.component = component;
     }
 

Modified: activemq/camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/JettyHttpClientOptionsTest.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/JettyHttpClientOptionsTest.java?rev=730936&r1=730935&r2=730936&view=diff
==============================================================================
--- activemq/camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/JettyHttpClientOptionsTest.java
(original)
+++ activemq/camel/trunk/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/JettyHttpClientOptionsTest.java
Sat Jan  3 00:24:31 2009
@@ -17,7 +17,9 @@
 package org.apache.camel.component.jetty;
 
 import org.apache.camel.ContextTestSupport;
+import org.apache.camel.Endpoint;
 import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.http.HttpProducer;
 
 /**
  * Unit test for http client options.
@@ -26,9 +28,10 @@
 
     public void testCustomHttpBinding() throws Exception {
         // assert jetty was configured with our timeout
-        JettyHttpComponent jetty = context.getComponent("jetty", JettyHttpComponent.class);
-        assertNotNull(jetty);
-        assertEquals(5555, jetty.getHttpClient().getIdleTimeout());
+        JettyHttpEndpoint jettyEndpoint = (JettyHttpEndpoint) context.getEndpoint("jetty:http://localhost:8080/myapp/myservice?httpClient.soTimeout=5555");
+        assertNotNull("Jetty endpoint should not be null ", jettyEndpoint);
+        HttpProducer producer = (HttpProducer)jettyEndpoint.createProducer();
+        assertEquals("Get the wrong http client parameter", 5555, producer.getHttpClient().getParams().getSoTimeout());
 
         // send and receive
         Object out = template.requestBody("http://localhost:8080/myapp/myservice", "Hello
World");
@@ -40,7 +43,7 @@
         return new RouteBuilder() {
             @Override
             public void configure() throws Exception {
-                from("jetty:http://localhost:8080/myapp/myservice?httpClient.idleTimeout=5555").transform().constant("Bye
World");
+                from("jetty:http://localhost:8080/myapp/myservice?httpClient.soTimeout=5555").transform().constant("Bye
World");
             }
         };
     }



Mime
View raw message