You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by ch...@apache.org on 2007/05/14 17:28:56 UTC

svn commit: r537879 - in /activemq/camel/trunk: camel-core/src/main/java/org/apache/camel/builder/ camel-core/src/main/java/org/apache/camel/impl/ camel-core/src/test/java/org/apache/camel/impl/ camel-http/src/main/java/org/apache/camel/component/http/...

Author: chirino
Date: Mon May 14 08:28:54 2007
New Revision: 537879

URL: http://svn.apache.org/viewvc?view=rev&rev=537879
Log:
- Made DefaultComponent abstract so that base cases are forced to implment required methods.
- Implemented a Jetty Based http component so that you can consume on dynamic http endpoints.

Added:
    activemq/camel/trunk/camel-http/src/main/java/org/apache/camel/component/http/HttpConsumer.java
    activemq/camel/trunk/camel-http/src/main/java/org/apache/camel/component/http/JettyHttpComponent.java
    activemq/camel/trunk/camel-http/src/test/java/org/apache/camel/component/http/HttpRouteTest.java
Modified:
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/RouteBuilder.java
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultComponent.java
    activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/impl/ProducerTest.java
    activemq/camel/trunk/camel-http/src/main/java/org/apache/camel/component/http/CamelServlet.java
    activemq/camel/trunk/camel-http/src/main/java/org/apache/camel/component/http/HttpComponent.java
    activemq/camel/trunk/camel-http/src/main/java/org/apache/camel/component/http/HttpEndpoint.java

Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/RouteBuilder.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/RouteBuilder.java?view=diff&rev=537879&r1=537878&r2=537879
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/RouteBuilder.java (original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/RouteBuilder.java Mon May 14 08:28:54 2007
@@ -53,7 +53,14 @@
 
     @Fluent
     public FromBuilder from( @FluentArg("uri") String uri) {
-        return from(endpoint(uri));
+    	if( uri == null ) {
+    		throw new IllegalArgumentException("uri parameter cannot be null");
+    	}
+    	Endpoint endpoint = endpoint(uri);
+    	if( endpoint == null ) {
+    		throw new IllegalArgumentException("uri '"+uri+"' could not be resolved.");
+    	}
+        return from(endpoint);
     }
 
     @Fluent

Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java?view=diff&rev=537879&r1=537878&r2=537879
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java (original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java Mon May 14 08:28:54 2007
@@ -311,7 +311,8 @@
         if (routeList != null) {
             for (Route<Exchange> route : routeList) {
                 Processor processor = route.getProcessor();
-                Consumer<Exchange> consumer = route.getEndpoint().createConsumer(processor);
+                Endpoint<Exchange> endpoint = route.getEndpoint();
+                Consumer<Exchange> consumer = endpoint.createConsumer(processor);
                 if (consumer != null) {
                     consumer.start();
                     servicesToClose.add(consumer);

Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultComponent.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultComponent.java?view=diff&rev=537879&r1=537878&r2=537879
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultComponent.java (original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultComponent.java Mon May 14 08:28:54 2007
@@ -34,7 +34,7 @@
 /**
  * @version $Revision$
  */
-public class DefaultComponent<E extends Exchange> extends ServiceSupport implements Component<E> {
+public abstract  class DefaultComponent<E extends Exchange> extends ServiceSupport implements Component<E> {
 
 	private int defaultThreadPoolSize = 5;
     private CamelContext camelContext;
@@ -124,7 +124,5 @@
      * @param parameters the optional parameters passed in
      * @return a newly created endpoint or null if the endpoint cannot be created based on the inputs
      */
-    protected Endpoint<E> createEndpoint(String uri, String remaining, Map parameters) throws Exception {
-        return null;
-    }
+    abstract protected Endpoint<E> createEndpoint(String uri, String remaining, Map parameters) throws Exception;
 }

Modified: activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/impl/ProducerTest.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/impl/ProducerTest.java?view=diff&rev=537879&r1=537878&r2=537879
==============================================================================
--- activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/impl/ProducerTest.java (original)
+++ activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/impl/ProducerTest.java Mon May 14 08:28:54 2007
@@ -17,14 +17,15 @@
  */
 package org.apache.camel.impl;
 
-import junit.framework.TestCase;
-import org.apache.camel.TestSupport;
-import org.apache.camel.Endpoint;
+import java.util.Map;
+
+import org.apache.camel.CamelContext;
 import org.apache.camel.Consumer;
+import org.apache.camel.Endpoint;
+import org.apache.camel.Exchange;
 import org.apache.camel.Processor;
 import org.apache.camel.Producer;
-import org.apache.camel.Exchange;
-import org.apache.camel.CamelContext;
+import org.apache.camel.TestSupport;
 
 /**
  * @version $Revision: 1.1 $
@@ -33,7 +34,13 @@
     private CamelContext context = new DefaultCamelContext();
 
     public void testUsingADerivedExchange() throws Exception {
-        DefaultEndpoint<MyExchange> endpoint = new DefaultEndpoint<MyExchange>("foo", new DefaultComponent()) {
+        DefaultEndpoint<MyExchange> endpoint = new DefaultEndpoint<MyExchange>("foo", new DefaultComponent(){
+			@Override
+			protected Endpoint createEndpoint(String uri, String remaining, Map parameters) throws Exception {
+				return null;
+			}
+        	
+        } ) {
             public Consumer<MyExchange> createConsumer(Processor processor) throws Exception {
                 return null;
             }
@@ -41,7 +48,7 @@
             public MyExchange createExchange() {
                 return new MyExchange(getContext());
             }
-
+ 
             public Producer<MyExchange> createProducer() throws Exception {
                 return null;
             }
@@ -49,6 +56,7 @@
             public boolean isSingleton() {
                 return false;
             }
+            
         };
 
         DefaultProducer producer = new DefaultProducer(endpoint) {

Modified: activemq/camel/trunk/camel-http/src/main/java/org/apache/camel/component/http/CamelServlet.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-http/src/main/java/org/apache/camel/component/http/CamelServlet.java?view=diff&rev=537879&r1=537878&r2=537879
==============================================================================
--- activemq/camel/trunk/camel-http/src/main/java/org/apache/camel/component/http/CamelServlet.java (original)
+++ activemq/camel/trunk/camel-http/src/main/java/org/apache/camel/component/http/CamelServlet.java Mon May 14 08:28:54 2007
@@ -18,52 +18,60 @@
 package org.apache.camel.component.http;
 
 import java.io.IOException;
+import java.util.concurrent.ConcurrentHashMap;
 
 import javax.servlet.ServletException;
 import javax.servlet.http.HttpServlet;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 
-import org.apache.camel.util.ProducerCache;
-
 /**
  * @version $Revision$
  */
 public class CamelServlet extends HttpServlet {
-    private HttpEndpoint endpoint;
-    private ProducerCache<HttpExchange> producerCache = new ProducerCache<HttpExchange>();
 
-    public CamelServlet() {
-    }
+    private ConcurrentHashMap<String, HttpConsumer> consumers=new ConcurrentHashMap<String, HttpConsumer>();
 
-    public CamelServlet(HttpEndpoint endpoint) {
-        this.endpoint = endpoint;
+	public CamelServlet() {
     }
 
     @Override
     protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
-        HttpEndpoint endpoint = resolveEndpoint(request, response);
-        if (endpoint == null) {
-            throw new ServletException("No endpoint found for request: " + request.getRequestURI());
-        }
-
         try {
+        	        	
+        	// Is there a consumer registered for the request.
+        	HttpConsumer consumer = resolve(request);
+        	if( consumer == null ) {
+        		response.sendError(HttpServletResponse.SC_NOT_FOUND);
+        		return;
+        	}
         	
-			HttpExchange exchange = endpoint.createExchange(request, response);
-			producerCache.send(endpoint, exchange);
+        	// Have the camel process the HTTP exchange.
+			HttpExchange exchange =  new HttpExchange(consumer.getEndpoint().getContext(), request, response);			
+			consumer.getProcessor().process(exchange);
 
-			// HC: The getBinding() interesting because it illustrates the impedance miss-match between
+			// HC: The getBinding() is interesting because it illustrates the impedance miss-match between
 			// HTTP's stream oriented protocol, and Camels more message oriented protocol exchanges.
 
 			// now lets output to the response
-			endpoint.getBinding().writeResponse(exchange);
+			consumer.getBinding().writeResponse(exchange);
 			
 		} catch (Exception e) {
 			throw new ServletException(e);
 		}
     }
 
-    protected HttpEndpoint resolveEndpoint(HttpServletRequest request, HttpServletResponse response) {
-        return endpoint;
-    }
+	protected HttpConsumer resolve(HttpServletRequest request) {
+		String path = request.getPathInfo();
+		return consumers.get(path);
+	}
+
+	public void connect(HttpConsumer consumer) {
+		consumers.put(consumer.getPath(), consumer);
+	}
+
+	public void disconnect(HttpConsumer consumer) {
+		consumers.remove(consumer.getPath());
+	}
+
 }

Modified: activemq/camel/trunk/camel-http/src/main/java/org/apache/camel/component/http/HttpComponent.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-http/src/main/java/org/apache/camel/component/http/HttpComponent.java?view=diff&rev=537879&r1=537878&r2=537879
==============================================================================
--- activemq/camel/trunk/camel-http/src/main/java/org/apache/camel/component/http/HttpComponent.java (original)
+++ activemq/camel/trunk/camel-http/src/main/java/org/apache/camel/component/http/HttpComponent.java Mon May 14 08:28:54 2007
@@ -17,10 +17,51 @@
  */
 package org.apache.camel.component.http;
 
+import java.util.Map;
+
+import org.apache.camel.Endpoint;
 import org.apache.camel.impl.DefaultComponent;
 
 /**
  * @version $Revision$
  */
 public class HttpComponent extends DefaultComponent<HttpExchange> {
+	
+	CamelServlet camelServlet;
+	
+	/** 
+	 * Connects the URL specified on the endpoint to the specified processor.
+	 *  
+	 * @param endpoint
+	 * @param processor
+	 * @throws Exception 
+	 */
+	public void connect(HttpConsumer consumer) throws Exception {
+		camelServlet.connect(consumer);
+	}
+
+	/**
+	 * Disconnects the URL specified on the endpoint from the specified processor.
+	 * 
+	 * @param endpoint
+	 * @param processor
+	 * @throws Exception 
+	 */
+	public void disconnect(HttpConsumer consumer) throws Exception {
+		camelServlet.disconnect(consumer);
+	}
+
+	public CamelServlet getCamelServlet() {
+		return camelServlet;
+	}
+
+	public void setCamelServlet(CamelServlet camelServlet) {
+		this.camelServlet = camelServlet;
+	}
+
+	@Override
+	protected Endpoint<HttpExchange> createEndpoint(String uri, String remaining, Map parameters) throws Exception {
+		return new HttpEndpoint(uri, this);
+	}
+
 }

Added: activemq/camel/trunk/camel-http/src/main/java/org/apache/camel/component/http/HttpConsumer.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-http/src/main/java/org/apache/camel/component/http/HttpConsumer.java?view=auto&rev=537879
==============================================================================
--- activemq/camel/trunk/camel-http/src/main/java/org/apache/camel/component/http/HttpConsumer.java (added)
+++ activemq/camel/trunk/camel-http/src/main/java/org/apache/camel/component/http/HttpConsumer.java Mon May 14 08:28:54 2007
@@ -0,0 +1,56 @@
+/**
+ *
+ * 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.camel.Processor;
+import org.apache.camel.impl.DefaultConsumer;
+
+/**
+ * @version $Revision: 534063 $
+ */
+public class HttpConsumer extends DefaultConsumer<HttpExchange> {
+
+	private final HttpEndpoint endpoint;
+
+	public HttpConsumer(HttpEndpoint endpoint, Processor processor) {
+		super(endpoint, processor);
+		this.endpoint = endpoint;
+	}
+	
+	@Override
+	protected void doStart() throws Exception {
+		super.doStart();
+		endpoint.connect(this);		
+	}
+	
+	@Override
+	protected void doStop() throws Exception {
+		endpoint.disconnect(this);
+		super.doStop();
+	}
+
+	public HttpBinding getBinding() {
+		return endpoint.getBinding();
+	}
+
+	public String getPath() {
+		return endpoint.getPath();
+	}
+	
+	
+}

Modified: activemq/camel/trunk/camel-http/src/main/java/org/apache/camel/component/http/HttpEndpoint.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-http/src/main/java/org/apache/camel/component/http/HttpEndpoint.java?view=diff&rev=537879&r1=537878&r2=537879
==============================================================================
--- activemq/camel/trunk/camel-http/src/main/java/org/apache/camel/component/http/HttpEndpoint.java (original)
+++ activemq/camel/trunk/camel-http/src/main/java/org/apache/camel/component/http/HttpEndpoint.java Mon May 14 08:28:54 2007
@@ -17,17 +17,18 @@
  */
 package org.apache.camel.component.http;
 
-import org.apache.camel.impl.DefaultEndpoint;
-import org.apache.camel.impl.DefaultProducer;
-import org.apache.camel.impl.DefaultConsumer;
-import org.apache.camel.Processor;
-import org.apache.camel.Producer;
-import org.apache.camel.Consumer;
-import org.apache.camel.Exchange;
+import java.net.URI;
+import java.net.URISyntaxException;
 
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 
+import org.apache.camel.Consumer;
+import org.apache.camel.Processor;
+import org.apache.camel.Producer;
+import org.apache.camel.RuntimeCamelException;
+import org.apache.camel.impl.DefaultEndpoint;
+
 /**
  * Represents a HTTP based Endpoint
  *
@@ -36,22 +37,21 @@
 public class HttpEndpoint extends DefaultEndpoint<HttpExchange> {
 
     private HttpBinding binding;
-
-    protected HttpEndpoint(String uri, HttpComponent component) {
+	private HttpComponent component;
+	private URI httpUri;
+	
+    protected HttpEndpoint(String uri, HttpComponent component) throws URISyntaxException {
         super(uri, component);
+		this.component = component;
+		this.httpUri = new URI(uri);
     }
 
     public Producer<HttpExchange> createProducer() throws Exception {
-        return new DefaultProducer(this) {
-            public void process(Exchange exchange) {
-                /** TODO */
-            }
-        };
+    	throw new RuntimeCamelException("Not implemented.");
     }
 
     public Consumer<HttpExchange> createConsumer(Processor processor) throws Exception {
-        // TODO
-        return new DefaultConsumer<HttpExchange>(this, processor) {};
+        return new HttpConsumer(this, processor);
     }
 
     public HttpExchange createExchange() {
@@ -77,4 +77,30 @@
 		return true;
 	}
 
+	public void connect(HttpConsumer consumer) throws Exception {
+		component.connect(consumer);
+	}
+
+	public void disconnect(HttpConsumer consumer) throws Exception {
+		component.disconnect(consumer);
+	}
+
+	public String getPath() {
+		return httpUri.getPath();
+	}
+
+	public int getPort() {
+		if( httpUri.getPort() == -1 ) {
+			if( "https".equals(getProtocol() ) ) {
+				return 443;
+			} else {
+				return 80;
+			}
+		}
+		return httpUri.getPort();
+	}
+
+	public String getProtocol() {
+		return httpUri.getScheme(); 
+	}
 }

Added: activemq/camel/trunk/camel-http/src/main/java/org/apache/camel/component/http/JettyHttpComponent.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-http/src/main/java/org/apache/camel/component/http/JettyHttpComponent.java?view=auto&rev=537879
==============================================================================
--- activemq/camel/trunk/camel-http/src/main/java/org/apache/camel/component/http/JettyHttpComponent.java (added)
+++ activemq/camel/trunk/camel-http/src/main/java/org/apache/camel/component/http/JettyHttpComponent.java Mon May 14 08:28:54 2007
@@ -0,0 +1,140 @@
+/**
+ *
+ * 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 java.util.HashMap;
+
+import org.mortbay.jetty.Connector;
+import org.mortbay.jetty.Server;
+import org.mortbay.jetty.nio.SelectChannelConnector;
+import org.mortbay.jetty.security.SslSocketConnector;
+import org.mortbay.jetty.servlet.Context;
+import org.mortbay.jetty.servlet.ServletHolder;
+
+/**
+ * An HttpComponent which starts an embedded Jetty for to handle consuming from
+ * http endpoints.
+ * 
+ * @version $Revision: 525142 $
+ */
+public class JettyHttpComponent extends HttpComponent {
+	
+	Server server;
+	
+	class ConnectorRef {
+		Connector connector;
+		int refCount = 0;
+		public ConnectorRef(Connector connector) {
+			this.connector=connector;
+			increment();
+		}
+		public int increment() {
+			return ++refCount;
+		}
+		public int decrement() {
+			return --refCount;
+		}
+	}
+	
+	final HashMap<String, ConnectorRef> connectors = new HashMap<String, ConnectorRef>();
+	
+	
+	
+	
+	@Override
+	protected void doStart() throws Exception {
+		server = createServer();
+		super.doStart();
+	}
+
+	private Server createServer() throws Exception {
+		setCamelServlet(new CamelServlet());
+		
+		Server server = new Server();
+		Context context = new Context(Context.NO_SECURITY|Context.NO_SESSIONS);
+		        
+		context.setContextPath("/");
+		ServletHolder holder = new ServletHolder();
+		holder.setServlet(getCamelServlet());
+		context.addServlet(holder, "/*");		
+		server.setHandler(context);
+			
+		server.start();
+		return server;
+	}
+
+	@Override
+	protected void doStop() throws Exception {
+		for (ConnectorRef connectorRef : connectors.values()) {
+			connectorRef.connector.stop();
+		}
+		connectors.clear();
+		
+		server.stop();
+		super.doStop();
+	}
+
+	@Override
+	public void connect(HttpConsumer consumer) throws Exception {
+		
+		// Make sure that there is a connector for the requested endpoint.
+		HttpEndpoint endpoint = (HttpEndpoint) consumer.getEndpoint();
+		String connectorKey = endpoint.getProtocol()+":"+endpoint.getPort();
+		
+		synchronized(connectors) {
+			ConnectorRef connectorRef = connectors.get(connectorKey);
+			if( connectorRef == null ) {
+				Connector connector;
+				if( "https".equals(endpoint.getProtocol()) ) {
+					connector = new SslSocketConnector();
+				} else {
+					connector = new SelectChannelConnector();
+				}
+				connector.setPort(endpoint.getPort());
+				server.addConnector(connector);
+				connector.start();
+				connectorRef = new ConnectorRef(connector);
+			} else {
+				// ref track the connector
+				connectorRef.increment();
+			}
+		}
+		
+		super.connect(consumer);
+	}
+	
+	@Override
+	public void disconnect(HttpConsumer consumer) throws Exception {
+		super.disconnect(consumer);
+		
+		// If the connector is not needed anymore.. then stop it.
+		HttpEndpoint endpoint = (HttpEndpoint) consumer.getEndpoint();
+		String connectorKey = endpoint.getProtocol()+":"+endpoint.getPort();
+		
+		synchronized(connectors) {
+			ConnectorRef connectorRef = connectors.get(connectorKey);
+			if( connectorRef != null ) {
+				if( connectorRef.decrement() == 0 ) {
+					server.removeConnector(connectorRef.connector);
+					connectorRef.connector.stop();
+					connectors.remove(connectorKey);
+				}
+			}
+		}
+	}
+}

Added: activemq/camel/trunk/camel-http/src/test/java/org/apache/camel/component/http/HttpRouteTest.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-http/src/test/java/org/apache/camel/component/http/HttpRouteTest.java?view=auto&rev=537879
==============================================================================
--- activemq/camel/trunk/camel-http/src/test/java/org/apache/camel/component/http/HttpRouteTest.java (added)
+++ activemq/camel/trunk/camel-http/src/test/java/org/apache/camel/component/http/HttpRouteTest.java Mon May 14 08:28:54 2007
@@ -0,0 +1,67 @@
+/**
+ *
+ * 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 java.io.InputStream;
+import java.net.URL;
+
+import junit.framework.TestCase;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.impl.DefaultCamelContext;
+
+/**
+ * @version $Revision: 520220 $
+ */
+public class HttpRouteTest extends TestCase {
+	
+    public void testPojoRoutes() throws Exception {    	
+        CamelContext camelContext = new DefaultCamelContext();
+        
+        // START SNIPPET: register
+        JettyHttpComponent component = new JettyHttpComponent();
+        camelContext.addComponent("http", component);
+        // END SNIPPET: register
+        
+        // START SNIPPET: route
+        // lets add simple route
+        camelContext.addRoutes(new RouteBuilder() {
+            public void configure() {
+                from("http://0.0.0.0:8080/test").to("mock:a");
+            }
+        });
+        // END SNIPPET: route
+
+        MockEndpoint mockA = (MockEndpoint) camelContext.getEndpoint("mock:a");
+        mockA.expectedMessageCount(1);
+        
+        camelContext.start();
+        
+        // START SNIPPET: invoke
+        URL url = new URL("http://localhost:8080/test");
+        InputStream is = url.openConnection().getInputStream();
+        System.out.println("Content: "+is);
+        // END SNIPPET: invoke
+        
+        mockA.assertIsSatisfied();
+        
+        camelContext.stop();
+    }
+}