You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ni...@apache.org on 2009/07/15 13:54:08 UTC

svn commit: r794238 - in /camel/trunk: components/camel-servlet/ tests/camel-itest-osgi/ tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/servlet/ tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/servlet/support/ tests/c...

Author: ningjiang
Date: Wed Jul 15 11:54:08 2009
New Revision: 794238

URL: http://svn.apache.org/viewvc?rev=794238&view=rev
Log:
CAMEL-1831 Added an integration test to show how use camel-servlet component in OSGi environment

Added:
    camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/servlet/
    camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/servlet/ServletComponentTest.java   (with props)
    camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/servlet/ServletProcessor.java   (with props)
    camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/servlet/support/
    camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/servlet/support/ServletActivator.java   (with props)
    camel/trunk/tests/camel-itest-osgi/src/test/resources/org/apache/camel/itest/osgi/servlet/
    camel/trunk/tests/camel-itest-osgi/src/test/resources/org/apache/camel/itest/osgi/servlet/CamelServletContext.xml   (with props)
Modified:
    camel/trunk/components/camel-servlet/pom.xml
    camel/trunk/tests/camel-itest-osgi/pom.xml

Modified: camel/trunk/components/camel-servlet/pom.xml
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-servlet/pom.xml?rev=794238&r1=794237&r2=794238&view=diff
==============================================================================
--- camel/trunk/components/camel-servlet/pom.xml (original)
+++ camel/trunk/components/camel-servlet/pom.xml Wed Jul 15 11:54:08 2009
@@ -16,7 +16,7 @@
   <description>Camel servlet transport support</description>
   
   <properties>
-        <camel.osgi.export.pkg>org.apache.camel.component.servelt.*</camel.osgi.export.pkg>
+      <camel.osgi.export.pkg>org.apache.camel.component.servlet.*</camel.osgi.export.pkg>
   </properties>
     
   <dependencies>

Modified: camel/trunk/tests/camel-itest-osgi/pom.xml
URL: http://svn.apache.org/viewvc/camel/trunk/tests/camel-itest-osgi/pom.xml?rev=794238&r1=794237&r2=794238&view=diff
==============================================================================
--- camel/trunk/tests/camel-itest-osgi/pom.xml (original)
+++ camel/trunk/tests/camel-itest-osgi/pom.xml Wed Jul 15 11:54:08 2009
@@ -32,7 +32,8 @@
   <description>Performs OSGi compliance integration tests</description>
 
   <properties>
-    <pax-exam-version>0.5.0</pax-exam-version>    
+    <pax-exam-version>0.6.0</pax-exam-version>
+    <pax-tiny-bundle-version>1.0.0</pax-tiny-bundle-version>  
   </properties>
 
   <repositories>
@@ -50,6 +51,10 @@
         <enabled>true</enabled>
       </snapshots>
     </repository>
+    <repository>
+      <id>aqute.biz</id>
+      <url>http://www.aqute.biz/repo</url>
+    </repository>
   </repositories>
 
   <pluginRepositories>
@@ -87,7 +92,19 @@
       <version>${pax-exam-version}</version>
       <scope>test</scope>
     </dependency>
-
+	<dependency>
+		<groupId>org.ops4j.pax.swissbox</groupId>
+		<artifactId>pax-swissbox-tinybundles</artifactId>
+		<version>1.0.0</version>
+		<scope>test</scope>
+	</dependency>
+	<dependency>
+		<groupId>org.osgi</groupId>
+		<artifactId>org.osgi.compendium</artifactId>
+		<version>4.0.1</version>
+		<scope>compile</scope>
+		<optional>true</optional>
+	</dependency> 
     <dependency>
       <groupId>org.osgi</groupId>
       <artifactId>org.osgi.core</artifactId>
@@ -104,13 +121,16 @@
     <dependency>
       <groupId>org.apache.camel</groupId>
       <artifactId>camel-osgi</artifactId>
-      <version>${version}</version>
       <scope>test</scope>
     </dependency>
-     <dependency>
+    <dependency>
+      <groupId>org.apache.camel</groupId>
+      <artifactId>camel-servlet</artifactId>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
       <groupId>org.apache.camel</groupId>
-      <artifactId>camel-test</artifactId>
-      <version>${version}</version>
+      <artifactId>camel-test</artifactId>      
       <scope>test</scope>
     </dependency>
     <dependency>

Added: camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/servlet/ServletComponentTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/servlet/ServletComponentTest.java?rev=794238&view=auto
==============================================================================
--- camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/servlet/ServletComponentTest.java (added)
+++ camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/servlet/ServletComponentTest.java Wed Jul 15 11:54:08 2009
@@ -0,0 +1,92 @@
+/**
+ * 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.itest.osgi.servlet;
+
+import org.apache.camel.itest.osgi.OSGiIntegrationSpringTestSupport;
+import org.apache.camel.itest.osgi.OSGiIntegrationTestSupport;
+import org.apache.camel.itest.osgi.servlet.support.ServletActivator;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.ops4j.pax.exam.Option;
+import org.ops4j.pax.exam.junit.Configuration;
+import org.ops4j.pax.exam.junit.JUnit4TestRunner;
+import org.ops4j.pax.exam.options.SystemPropertyOption;
+import org.ops4j.pax.swissbox.tinybundles.dp.Constants;
+import org.springframework.osgi.context.support.OsgiBundleXmlApplicationContext;
+
+import static org.ops4j.pax.exam.CoreOptions.bundle;
+import static org.ops4j.pax.exam.CoreOptions.felix;
+import static org.ops4j.pax.exam.CoreOptions.mavenBundle;
+import static org.ops4j.pax.exam.CoreOptions.options;
+import static org.ops4j.pax.exam.container.def.PaxRunnerOptions.logProfile;
+import static org.ops4j.pax.exam.container.def.PaxRunnerOptions.profile;
+import static org.ops4j.pax.exam.container.def.PaxRunnerOptions.scanFeatures;
+import static org.ops4j.pax.swissbox.tinybundles.core.TinyBundles.asURL;
+import static org.ops4j.pax.swissbox.tinybundles.core.TinyBundles.newBundle;
+import static org.ops4j.pax.swissbox.tinybundles.core.TinyBundles.withBnd;
+
+@RunWith(JUnit4TestRunner.class)
+public class ServletComponentTest extends OSGiIntegrationSpringTestSupport {
+    
+    @Test
+    public void testSendMessage() {
+        String endpointURI = "http://localhost:9080/camel/services";
+        String response = template.requestBody(endpointURI, "Hello World", String.class);
+        assertEquals("response is " , "Echo Hello World", response);
+    }
+    
+    @Configuration
+    public static Option[] configure() {
+        Option[] options = options(
+            // install log service using pax runners profile abstraction (there are more profiles, like DS)
+            logProfile().version("1.3.0"),
+            // install the spring dm profile            
+            profile("spring.dm").version("1.2.0"),
+            // set the system property for pax web
+            org.ops4j.pax.exam.CoreOptions.systemProperty("org.osgi.service.http.port").value("9080"),
+            
+            // install the profile for OSGi web
+            mavenBundle().groupId("org.ops4j.pax.web").artifactId("pax-web-service").version("0.6.0"),
+            
+            // this is how you set the default log level when using pax logging (logProfile)
+            org.ops4j.pax.exam.CoreOptions.systemProperty("org.ops4j.pax.logging.DefaultServiceLog.level").value("INFO"),
+            
+            // using the features to install the camel components             
+            scanFeatures(mavenBundle().groupId("org.apache.camel.karaf").
+                         artifactId("features").versionAsInProject().type("xml/features"),                         
+                          "camel-core", "camel-osgi", "camel-spring", "camel-test", "camel-http", "camel-servlet"),
+            
+            // create a customer bundle start up the CamelHttpTransportServlet
+            bundle(newBundle().addClass(ServletActivator.class)
+                .prepare(withBnd().set(Constants.BUNDLE_SYMBOLICNAME, "CamelServletTinyBundle")
+                                  .set(Constants.BUNDLE_ACTIVATOR, ServletActivator.class.getName())).build(asURL()).toString()),
+            felix());
+        
+        return options;
+    }
+    
+    @Override
+    protected OsgiBundleXmlApplicationContext createApplicationContext() {
+        return new OsgiBundleXmlApplicationContext(new String[]{"org/apache/camel/itest/osgi/servlet/CamelServletContext.xml"});
+    }
+   
+
+
+}

Propchange: camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/servlet/ServletComponentTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/servlet/ServletComponentTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/servlet/ServletProcessor.java
URL: http://svn.apache.org/viewvc/camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/servlet/ServletProcessor.java?rev=794238&view=auto
==============================================================================
--- camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/servlet/ServletProcessor.java (added)
+++ camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/servlet/ServletProcessor.java Wed Jul 15 11:54:08 2009
@@ -0,0 +1,33 @@
+/**
+ * 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.itest.osgi.servlet;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+public class ServletProcessor implements Processor {
+    private static final transient Log LOG = LogFactory.getLog(ServletProcessor.class);
+
+    public void process(Exchange exchange) throws Exception {
+        String request = exchange.getIn().getBody(String.class);
+        LOG.info("*** get the request is " + request);
+        exchange.getOut().setBody("Echo " + request);
+    }
+
+}

Propchange: camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/servlet/ServletProcessor.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/servlet/ServletProcessor.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/servlet/support/ServletActivator.java
URL: http://svn.apache.org/viewvc/camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/servlet/support/ServletActivator.java?rev=794238&view=auto
==============================================================================
--- camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/servlet/support/ServletActivator.java (added)
+++ camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/servlet/support/ServletActivator.java Wed Jul 15 11:54:08 2009
@@ -0,0 +1,73 @@
+/**
+ * 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.itest.osgi.servlet.support;
+
+import java.util.Dictionary;
+import java.util.Hashtable;
+
+import javax.servlet.Servlet;
+
+import org.apache.camel.component.servlet.CamelHttpTransportServlet;
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceReference;
+import org.osgi.service.http.HttpContext;
+import org.osgi.service.http.HttpService;
+
+public final class ServletActivator implements BundleActivator {
+    
+    /**
+     * HttpService reference.
+     */
+    private ServiceReference httpServiceRef;
+
+    /**
+     * Called when the OSGi framework starts our bundle
+     */
+    @SuppressWarnings("unchecked")
+    public void start(BundleContext bc) throws Exception {
+        httpServiceRef = bc.getServiceReference(HttpService.class.getName());
+        if (httpServiceRef != null) {
+            final HttpService httpService = (HttpService)bc.getService(httpServiceRef);
+            if (httpService != null) {
+                // create a default context to share between registrations
+                final HttpContext httpContext = httpService.createDefaultHttpContext();
+                // register the hello world servlet
+                final Dictionary initParams = new Hashtable();
+                initParams.put("matchOnUriPrefix", "false");
+                initParams.put("servlet-name", "camelServlet");
+                httpService.registerServlet("/camel", // alias
+                    (Servlet)new CamelHttpTransportServlet(), // register servlet
+                    initParams, // init params
+                    httpContext // http context
+                );
+
+            }
+        }
+    }
+
+    /**
+     * Called when the OSGi framework stops our bundle
+     */
+    public void stop(BundleContext bc) throws Exception {
+        if (httpServiceRef != null) {
+            bc.ungetService(httpServiceRef);
+            httpServiceRef = null;
+        }
+    }
+
+}

Propchange: camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/servlet/support/ServletActivator.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/servlet/support/ServletActivator.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: camel/trunk/tests/camel-itest-osgi/src/test/resources/org/apache/camel/itest/osgi/servlet/CamelServletContext.xml
URL: http://svn.apache.org/viewvc/camel/trunk/tests/camel-itest-osgi/src/test/resources/org/apache/camel/itest/osgi/servlet/CamelServletContext.xml?rev=794238&view=auto
==============================================================================
--- camel/trunk/tests/camel-itest-osgi/src/test/resources/org/apache/camel/itest/osgi/servlet/CamelServletContext.xml (added)
+++ camel/trunk/tests/camel-itest-osgi/src/test/resources/org/apache/camel/itest/osgi/servlet/CamelServletContext.xml Wed Jul 15 11:54:08 2009
@@ -0,0 +1,38 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+    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.
+-->
+
+<beans xmlns="http://www.springframework.org/schema/beans"
+       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+       xmlns:camel="http://camel.apache.org/schema/spring"
+       xmlns:osgi="http://www.springframework.org/schema/osgi"
+       xsi:schemaLocation="
+       http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
+       http://www.springframework.org/schema/osgi  http://www.springframework.org/schema/osgi/spring-osgi.xsd
+       http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd">
+  
+
+   <bean id="servletProcessor" class="org.apache.camel.itest.osgi.servlet.ServletProcessor" />
+  
+   <camelContext xmlns="http://camel.apache.org/schema/spring">
+     <camel:route>
+       <camel:from uri="servlet:///services"/>
+       <camel:process ref="servletProcessor"/>
+     </camel:route>
+   </camelContext>
+
+</beans>

Propchange: camel/trunk/tests/camel-itest-osgi/src/test/resources/org/apache/camel/itest/osgi/servlet/CamelServletContext.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/tests/camel-itest-osgi/src/test/resources/org/apache/camel/itest/osgi/servlet/CamelServletContext.xml
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Propchange: camel/trunk/tests/camel-itest-osgi/src/test/resources/org/apache/camel/itest/osgi/servlet/CamelServletContext.xml
------------------------------------------------------------------------------
    svn:mime-type = text/xml