[karaf] Add the web demo back

git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@805333 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/karaf/demos/web/README.txt b/karaf/demos/web/README.txt
new file mode 100644
index 0000000..a41aad9
--- /dev/null
+++ b/karaf/demos/web/README.txt
@@ -0,0 +1,28 @@
+################################################################################
+#
+#    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.
+#
+################################################################################
+
+This is an example showing how to embed ServiceMix Kernel in a web application.
+You can either:
+  * build the web app using "mvn package" and deploy the web application to your favorite web container
+  * run the web app from the command line using the "mvn package jetty:run" command
+  
+Once the web application is started, you can use the Apache ServiceMix Kernel client to connect to the running server:
+  cd [smx-kernel-install-dir]
+  java -jar lib/servicemix-client.jar
+  
diff --git a/karaf/demos/web/pom.xml b/karaf/demos/web/pom.xml
new file mode 100644
index 0000000..f997265
--- /dev/null
+++ b/karaf/demos/web/pom.xml
@@ -0,0 +1,158 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<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">
+
+<!--
+
+    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.
+-->
+
+  <modelVersion>4.0.0</modelVersion>
+
+  <parent>
+    <groupId>org.apache.felix.karaf.demos</groupId>
+    <artifactId>demos</artifactId>
+    <version>1.2.0-SNAPSHOT</version>
+  </parent>
+
+  <groupId>org.apache.felix.karaf.demos</groupId>
+  <artifactId>web</artifactId>
+  <packaging>war</packaging>
+  <name>Apache Felix Karaf :: Demos :: web</name>
+  
+  <properties>
+    <jetty.port>8080</jetty.port>
+    <jetty.version>6.1.12rc1</jetty.version>
+    <geronimo.servlet.version>1.1.2</geronimo.servlet.version>
+  </properties>
+
+  <dependencies>
+    <dependency>
+      <groupId>org.apache.felix.karaf</groupId>
+      <artifactId>org.apache.felix.karaf.main</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.felix.karaf.jaas</groupId>
+      <artifactId>org.apache.felix.karaf.jaas.boot</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.felix.karaf</groupId>
+      <artifactId>apache-felix-karaf</artifactId>
+      <type>zip</type>
+      <scope>provided</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.geronimo.specs</groupId>
+      <artifactId>geronimo-servlet_2.5_spec</artifactId>
+      <scope>provided</scope>
+    </dependency>
+  </dependencies>
+
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-compiler-plugin</artifactId>
+        <configuration>
+          <source>1.5</source>
+          <target>1.5</target>
+        </configuration>
+      </plugin>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-war-plugin</artifactId>
+        <version>2.1-beta-1</version>
+        <configuration>
+          <warSourceDirectory>src/main/webapp/</warSourceDirectory>
+          <webResources>
+            <resource>
+              <directory>target/karaf</directory>
+            </resource>
+          </webResources>
+        </configuration>
+      </plugin>
+      <plugin>
+        <groupId>org.mortbay.jetty</groupId>
+        <artifactId>maven-jetty-plugin</artifactId>
+        <version>${jetty.version}</version>
+        <configuration>
+          <connectors>
+            <connector implementation="org.mortbay.jetty.nio.SelectChannelConnector">
+              <port>${jetty.port}</port>
+              <maxIdleTime>60000</maxIdleTime>
+            </connector>
+          </connectors>
+          <systemProperties>
+            <!-- enable easy connection to JConsole -->
+            <systemProperty>
+              <name>com.sun.management.jmxremote</name>
+              <value></value>
+            </systemProperty>
+          </systemProperties>
+          <scanIntervalSeconds>10</scanIntervalSeconds>
+          <webAppSourceDirectory>${project.build.directory}/${project.build.finalName}</webAppSourceDirectory>
+        </configuration>
+      </plugin>
+      <plugin>
+          <groupId>org.apache.maven.plugins</groupId>
+          <artifactId>maven-dependency-plugin</artifactId>
+          <version>2.0</version>
+          <executions>
+              <execution>
+                  <id>unpack-unix</id>
+                  <phase>generate-resources</phase>
+                  <goals>
+                      <goal>unpack</goal>
+                  </goals>
+                  <configuration>
+                      <artifactItems>
+                          <artifactItem>
+                              <groupId>org.apache.felix.karaf</groupId>
+                              <artifactId>apache-felix-karaf</artifactId>
+                              <type>zip</type>
+                              <overWrite>true</overWrite>
+                              <outputDirectory>${project.build.directory}/karaf/WEB-INF</outputDirectory>
+                              <excludes>**/lib/*,**/*.txt,**/bin/*,**/demos/**,**/lib,**/bin,**/demos</excludes>
+                          </artifactItem>
+                      </artifactItems>
+                  </configuration>
+              </execution>
+        </executions>
+      </plugin>
+      <plugin>
+          <groupId>org.apache.maven.plugins</groupId>
+          <artifactId>maven-antrun-plugin</artifactId>
+          <version>1.3</version>
+          <executions>
+              <execution>
+                  <id>copy-karaf</id>
+                  <phase>process-resources</phase>
+                  <goals>
+                      <goal>run</goal>
+                  </goals>
+                  <configuration>
+                      <tasks>
+                          <move todir="${project.build.directory}/karaf/WEB-INF/karaf">
+                              <fileset dir="${project.build.directory}/karaf/WEB-INF/apache-felix-karaf-${pom.version}"/>
+                          </move>
+                      </tasks>
+                  </configuration>
+              </execution>
+          </executions>
+      </plugin>
+    </plugins>
+  </build>
+
+</project>
diff --git a/karaf/demos/web/src/main/java/org/apache/felix/karaf/web/WebAppListener.java b/karaf/demos/web/src/main/java/org/apache/felix/karaf/web/WebAppListener.java
new file mode 100644
index 0000000..8db85b1
--- /dev/null
+++ b/karaf/demos/web/src/main/java/org/apache/felix/karaf/web/WebAppListener.java
@@ -0,0 +1,58 @@
+/*
+ * 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.felix.karaf.web;
+
+import java.io.File;
+
+import javax.servlet.ServletContextEvent;
+import javax.servlet.ServletContextListener;
+
+import org.apache.felix.karaf.main.Main;
+import org.apache.felix.karaf.main.Bootstrap;
+
+public class WebAppListener implements ServletContextListener {
+	
+	private Main main;
+	
+	public void contextInitialized(ServletContextEvent sce) {
+		try {
+			System.err.println("contextInitialized");
+			String root = new File(sce.getServletContext().getRealPath("/") + "WEB-INF/karaf").getAbsolutePath();
+			System.err.println("Root: " + root);
+			System.setProperty("karaf.home", root);
+			System.setProperty("karaf.base", root);
+			System.setProperty("karaf.startLocalConsole", "false");
+			System.setProperty("karaf.startRemoteShell", "true");
+			main = Bootstrap.launch(new String[0]);
+		} catch (Exception e) {
+			main = null;
+			e.printStackTrace();
+		}
+	}
+
+	public void contextDestroyed(ServletContextEvent sce) {
+		try {
+			System.err.println("contextDestroyed");
+			if (main != null) {
+				main.destroy(false);
+			}
+		} catch (Exception e) {
+			e.printStackTrace();
+		}
+	}
+
+}
diff --git a/karaf/demos/web/src/main/webapp/WEB-INF/web.xml b/karaf/demos/web/src/main/webapp/WEB-INF/web.xml
new file mode 100644
index 0000000..4e2471b
--- /dev/null
+++ b/karaf/demos/web/src/main/webapp/WEB-INF/web.xml
@@ -0,0 +1,36 @@
+<?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.
+-->
+
+<web-app version="2.4"
+         xmlns="http://java.sun.com/xml/ns/j2ee"
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
+                             http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
+
+  <description>Karaf Embedded Example</description>
+  <display-name>Karaf Embedded Example</display-name>
+
+  <listener>
+    <listener-class>org.apache.felix.karaf.web.WebAppListener</listener-class>
+  </listener>
+
+  <welcome-file-list>
+    <welcome-file>index.jsp</welcome-file>
+  </welcome-file-list>
+		
+</web-app>
diff --git a/karaf/demos/web/src/main/webapp/index.jsp b/karaf/demos/web/src/main/webapp/index.jsp
new file mode 100644
index 0000000..ab13f33
--- /dev/null
+++ b/karaf/demos/web/src/main/webapp/index.jsp
@@ -0,0 +1,34 @@
+<%--
+    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.
+--%>
+<html>
+<head>
+<title>Apache Felix Karaf</title>
+</head>
+<body>
+
+<h2>Welcome!</h2>
+
+<p>
+Welcome to Apache Karaf web application demo
+</p>
+
+<p>
+You can find more information about Karaf on the <a href="http://felix.apache.org/site/apache-felix-karaf.html">Apache Karaf Site</a>
+</p>
+</body>
+</html>
+