camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cmoulli...@apache.org
Subject svn commit: r918097 - in /camel/trunk/components/camel-cometd/src: main/java/org/apache/camel/component/cometd/ test/java/org/apache/camel/component/cometd/
Date Tue, 02 Mar 2010 16:06:19 GMT
Author: cmoulliard
Date: Tue Mar  2 16:06:18 2010
New Revision: 918097

URL: http://svn.apache.org/viewvc?rev=918097&view=rev
Log:
CAMEL-2516 : Adapt the camel-cometd component to allow to find resources in classpath or file
system.

Modified:
    camel/trunk/components/camel-cometd/src/main/java/org/apache/camel/component/cometd/CometdComponent.java
    camel/trunk/components/camel-cometd/src/main/java/org/apache/camel/component/cometd/CometdEndpoint.java
    camel/trunk/components/camel-cometd/src/test/java/org/apache/camel/component/cometd/CometdProducerConsumerInteractiveMain.java
    camel/trunk/components/camel-cometd/src/test/java/org/apache/camel/component/cometd/CometdProducerConsumerTest.java
    camel/trunk/components/camel-cometd/src/test/java/org/apache/camel/component/cometd/SslCometdProducerConsumerTest.java

Modified: camel/trunk/components/camel-cometd/src/main/java/org/apache/camel/component/cometd/CometdComponent.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-cometd/src/main/java/org/apache/camel/component/cometd/CometdComponent.java?rev=918097&r1=918096&r2=918097&view=diff
==============================================================================
--- camel/trunk/components/camel-cometd/src/main/java/org/apache/camel/component/cometd/CometdComponent.java
(original)
+++ camel/trunk/components/camel-cometd/src/main/java/org/apache/camel/component/cometd/CometdComponent.java
Tue Mar  2 16:06:18 2010
@@ -16,6 +16,10 @@
  */
 package org.apache.camel.component.cometd;
 
+import java.io.IOException;
+import java.net.URL;
+import java.net.URLConnection;
+import java.net.URLStreamHandler;
 import java.util.HashMap;
 import java.util.Map;
 
@@ -32,6 +36,9 @@
 import org.mortbay.jetty.security.SslSocketConnector;
 import org.mortbay.jetty.servlet.Context;
 import org.mortbay.jetty.servlet.ServletHolder;
+import org.mortbay.resource.FileResource;
+import org.mortbay.resource.Resource;
+import org.mortbay.resource.URLResource;
 
 /**
  * Component for Jetty Cometd
@@ -147,7 +154,28 @@
 
         ServletHolder holder = new ServletHolder();
         holder.setServlet(servlet);
-        context.setResourceBase(endpoint.getResourceBase());
+        
+        // Use baseResource to pass as a parameter the url
+        // pointing to by example classpath:webapp
+        if (endpoint.getBaseResource() != null) {
+
+            String[] resources = endpoint.getBaseResource().split(":");
+            LOG.debug(">>> Protocol found :" + resources[0] + ", and resource :
" + resources[1]);
+            
+            if (resources[0].equals("file")) {
+                context.setBaseResource(Resource.newResource(resources[1]));
+                
+            } else if (resources[0].equals("classpath")) {
+                
+                // Create a URL handler using classpath protocol
+                URL url = this.getCamelContext().getClassResolver().loadResourceAsURL(resources[1]);

+                context.setBaseResource(Resource.newResource(url));
+                
+            } 
+
+        }
+        
+        
         context.addServlet(holder, "/cometd/*");
         context.addServlet("org.mortbay.jetty.servlet.DefaultServlet", "/");
 
@@ -240,5 +268,5 @@
     protected void doStart() throws Exception {
         super.doStart();
     }
-
+    
 }

Modified: camel/trunk/components/camel-cometd/src/main/java/org/apache/camel/component/cometd/CometdEndpoint.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-cometd/src/main/java/org/apache/camel/component/cometd/CometdEndpoint.java?rev=918097&r1=918096&r2=918097&view=diff
==============================================================================
--- camel/trunk/components/camel-cometd/src/main/java/org/apache/camel/component/cometd/CometdEndpoint.java
(original)
+++ camel/trunk/components/camel-cometd/src/main/java/org/apache/camel/component/cometd/CometdEndpoint.java
Tue Mar  2 16:06:18 2010
@@ -33,7 +33,7 @@
  */
 public class CometdEndpoint extends DefaultEndpoint {
    
-    private String resourceBase;
+    private String baseResource;
     private int timeout = 240000;
     private int interval;
     private int maxInterval = 30000;
@@ -104,12 +104,12 @@
         return uri;
     }
 
-    public String getResourceBase() {
-        return resourceBase;
+    public String getBaseResource() {
+        return baseResource;
     }
 
-    public void setResourceBase(String resourceBase) {
-        this.resourceBase = resourceBase;
+    public void setBaseResource(String baseResource) {
+        this.baseResource = baseResource;
     }
    
     public int getTimeout() {

Modified: camel/trunk/components/camel-cometd/src/test/java/org/apache/camel/component/cometd/CometdProducerConsumerInteractiveMain.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-cometd/src/test/java/org/apache/camel/component/cometd/CometdProducerConsumerInteractiveMain.java?rev=918097&r1=918096&r2=918097&view=diff
==============================================================================
--- camel/trunk/components/camel-cometd/src/test/java/org/apache/camel/component/cometd/CometdProducerConsumerInteractiveMain.java
(original)
+++ camel/trunk/components/camel-cometd/src/test/java/org/apache/camel/component/cometd/CometdProducerConsumerInteractiveMain.java
Tue Mar  2 16:06:18 2010
@@ -25,10 +25,10 @@
 
 public class CometdProducerConsumerInteractiveMain {
 
-    private static final String URI = "cometd://127.0.0.1:9091/service/test?resourceBase=./src/test/resources/webapp&"
+    private static final String URI = "cometd://127.0.0.1:9091/service/test?baseResource=file:./src/test/resources/webapp&"
             + "timeout=240000&interval=0&maxInterval=30000&multiFrameInterval=1500&jsonCommented=true&logLevel=2";
 
-    private static final String URIS = "cometds://127.0.0.1:9443/service/test?resourceBase=./src/test/resources/webapp&"
+    private static final String URIS = "cometds://127.0.0.1:9443/service/test?baseResource=file:./src/test/resources/webapp&"
         + "timeout=240000&interval=0&maxInterval=30000&multiFrameInterval=1500&jsonCommented=true&logLevel=2";
 
     private CamelContext context;

Modified: camel/trunk/components/camel-cometd/src/test/java/org/apache/camel/component/cometd/CometdProducerConsumerTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-cometd/src/test/java/org/apache/camel/component/cometd/CometdProducerConsumerTest.java?rev=918097&r1=918096&r2=918097&view=diff
==============================================================================
--- camel/trunk/components/camel-cometd/src/test/java/org/apache/camel/component/cometd/CometdProducerConsumerTest.java
(original)
+++ camel/trunk/components/camel-cometd/src/test/java/org/apache/camel/component/cometd/CometdProducerConsumerTest.java
Tue Mar  2 16:06:18 2010
@@ -30,7 +30,7 @@
  */
 public class CometdProducerConsumerTest extends CamelTestSupport {
 
-    private static final String URI = "cometd://127.0.0.1:9080/service/test?resourceBase=./target/test-classes/webapp&"
+    private static final String URI = "cometd://127.0.0.1:9080/service/test?baseResource=file:./target/test-classes/webapp&"
             + "timeout=240000&interval=0&maxInterval=30000&multiFrameInterval=1500&jsonCommented=true&logLevel=2";
 
     @Test

Modified: camel/trunk/components/camel-cometd/src/test/java/org/apache/camel/component/cometd/SslCometdProducerConsumerTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-cometd/src/test/java/org/apache/camel/component/cometd/SslCometdProducerConsumerTest.java?rev=918097&r1=918096&r2=918097&view=diff
==============================================================================
--- camel/trunk/components/camel-cometd/src/test/java/org/apache/camel/component/cometd/SslCometdProducerConsumerTest.java
(original)
+++ camel/trunk/components/camel-cometd/src/test/java/org/apache/camel/component/cometd/SslCometdProducerConsumerTest.java
Tue Mar  2 16:06:18 2010
@@ -31,7 +31,7 @@
  */
 public class SslCometdProducerConsumerTest extends CamelTestSupport {
 
-    private static final String URI = "cometds://127.0.0.1:9080/service/test?resourceBase=./target/test-classes/webapp&"
+    private static final String URI = "cometds://127.0.0.1:9080/service/test?baseResource=file:./target/test-classes/webapp&"
             + "timeout=240000&interval=0&maxInterval=30000&multiFrameInterval=1500&jsonCommented=true&logLevel=2";
 
     protected String pwd = "changeit";



Mime
View raw message