Author: [email protected]
Date: Thu Mar 10 10:04:19 2011
New Revision: 865
Log:
Added:
sandbox/ivol/amdatu-webapp/run.bat
sandbox/ivol/amdatu-webapp/src/main/java/org/amdatu/webapp/FrameworkService.java
sandbox/ivol/amdatu-webapp/src/main/java/org/amdatu/webapp/ProvisionActivator.java
sandbox/ivol/amdatu-webapp/src/main/java/org/amdatu/webapp/StartupListener.java
Removed:
sandbox/ivol/amdatu-webapp/src/main/java/org/amdatu/webapp/ProxyServlet.java
sandbox/ivol/amdatu-webapp/src/main/java/org/apache/felix/http/samples/bridge/FrameworkService.java
sandbox/ivol/amdatu-webapp/src/main/java/org/apache/felix/http/samples/bridge/ProvisionActivator.java
sandbox/ivol/amdatu-webapp/src/main/java/org/apache/felix/http/samples/bridge/StartupListener.java
sandbox/ivol/amdatu-webapp/src/main/webapp/index.jsp
Modified:
sandbox/ivol/amdatu-webapp/pom.xml
sandbox/ivol/amdatu-webapp/src/main/webapp/WEB-INF/web.xml
Modified: sandbox/ivol/amdatu-webapp/pom.xml
==============================================================================
--- sandbox/ivol/amdatu-webapp/pom.xml (original)
+++ sandbox/ivol/amdatu-webapp/pom.xml Thu Mar 10 10:04:19 2011
@@ -6,12 +6,16 @@
<artifactId>amdatu</artifactId>
<version>0.2.0-SNAPSHOT</version>
</parent>
- <groupId>org.amdatu.webapp</groupId>
- <artifactId>amdatu</artifactId>
+ <groupId>org.amdatu</groupId>
+ <artifactId>amdatu-webapp</artifactId>
<name>Amdatu Webapp</name>
<description>Amdatu Webapp</description>
<packaging>war</packaging>
+ <properties>
+ <war.filename>${groupId}.${articactId}-${version}</war.filename>
+ </properties>
+
<dependencies>
<dependency>
<groupId>junit</groupId>
@@ -86,7 +90,7 @@
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
- <id>copy-bundles</id>
+ <id>copy-system-bundles</id>
<goals>
<goal>copy-dependencies</goal>
</goals>
@@ -95,9 +99,7 @@
org.apache.felix.http.bridge,org.apache.felix.webconsole
</includeArtifactIds>
<stripVersion>true</stripVersion>
- <outputDirectory>
- ${project.build.directory}/bundles
- </outputDirectory>
+
<outputDirectory>${project.build.directory}/amdatu-system</outputDirectory>
</configuration>
</execution>
</executions>
@@ -108,10 +110,8 @@
<configuration>
<webResources>
<resource>
- <directory>
- ${project.build.directory}/bundles
- </directory>
- <targetPath>WEB-INF/bundles</targetPath>
+ <directory>${project.build.directory}/amdatu-system</directory>
+ <targetPath>WEB-INF/bundles/amdatu-system</targetPath>
</resource>
<resource>
<directory>.</directory>
Added: sandbox/ivol/amdatu-webapp/run.bat
==============================================================================
--- (empty file)
+++ sandbox/ivol/amdatu-webapp/run.bat Thu Mar 10 10:04:19 2011
@@ -0,0 +1,2 @@
+call mvn clean install
+call mvn jetty:run-war
\ No newline at end of file
Added:
sandbox/ivol/amdatu-webapp/src/main/java/org/amdatu/webapp/FrameworkService.java
==============================================================================
--- (empty file)
+++
sandbox/ivol/amdatu-webapp/src/main/java/org/amdatu/webapp/FrameworkService.java
Thu Mar 10 10:04:19 2011
@@ -0,0 +1,83 @@
+/*
+ Copyright (C) 2010 Amdatu.org
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+package org.amdatu.webapp;
+
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Properties;
+
+import javax.servlet.ServletContext;
+
+import org.apache.felix.framework.Felix;
+import org.apache.felix.framework.util.FelixConstants;
+
+public final class FrameworkService
+{
+ private final ServletContext m_servletContext;
+ private Felix m_felix;
+
+ public FrameworkService(ServletContext context) {
+ m_servletContext = context;
+ }
+
+ public void start() {
+ try {
+ doStart();
+ } catch (Exception e) {
+ log("Failed to start framework", e);
+ }
+ }
+
+ public void stop() {
+ try {
+ doStop();
+ } catch (Exception e) {
+ log("Error stopping framework", e);
+ }
+ }
+
+ private void doStart() throws Exception {
+ Felix tmp = new Felix(createConfig());
+ tmp.start();
+ m_felix = tmp;
+ log("OSGi framework started", null);
+ }
+
+ private void doStop() throws Exception {
+ if (m_felix != null) {
+ m_felix.stop();
+ }
+
+ log("OSGi framework stopped", null);
+ }
+
+ private Map<String, Object> createConfig() throws Exception {
+ Properties props = new Properties();
+
props.load(this.m_servletContext.getResourceAsStream("/WEB-INF/framework.properties"));
+ HashMap<String, Object> map = new HashMap<String, Object>();
+ for (Object key : props.keySet()) {
+ map.put(key.toString(), props.get(key));
+ }
+ map.put(FelixConstants.SYSTEMBUNDLE_ACTIVATORS_PROP, Arrays.asList(new
ProvisionActivator(this.m_servletContext)));
+ return map;
+ }
+
+ private void log(String message, Throwable cause) {
+ m_servletContext.log(message, cause);
+ }
+}
Added:
sandbox/ivol/amdatu-webapp/src/main/java/org/amdatu/webapp/ProvisionActivator.java
==============================================================================
--- (empty file)
+++
sandbox/ivol/amdatu-webapp/src/main/java/org/amdatu/webapp/ProvisionActivator.java
Thu Mar 10 10:04:19 2011
@@ -0,0 +1,68 @@
+/*
+ Copyright (C) 2010 Amdatu.org
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+package org.amdatu.webapp;
+
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.servlet.ServletContext;
+
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+
+public final class ProvisionActivator implements BundleActivator {
+ private final ServletContext m_servletContext;
+
+ public ProvisionActivator(ServletContext servletContext) {
+ m_servletContext = servletContext;
+ }
+
+ public void start(BundleContext context) throws Exception {
+ m_servletContext.setAttribute(BundleContext.class.getName(), context);
+ ArrayList<Bundle> installed = new ArrayList<Bundle>();
+ for (URL url : findBundles()) {
+ this.m_servletContext.log("Installing bundle [" + url + "]");
+ System.out.println("Installing bundle [" + url + "]");
+ Bundle bundle = context.installBundle(url.toExternalForm());
+ installed.add(bundle);
+ }
+
+ for (Bundle bundle : installed) {
+ bundle.start();
+ }
+ }
+
+ public void stop(BundleContext context) throws Exception{
+ }
+
+ private List<URL> findBundles() throws Exception {
+ ArrayList<URL> list = new ArrayList<URL>();
+ for (Object o :
this.m_servletContext.getResourcePaths("/WEB-INF/bundles/")) {
+ String name = (String) o;
+ System.out.println("!!!"+name);
+ if (name.endsWith(".jar")) {
+ URL url = this.m_servletContext.getResource(name);
+ if (url != null) {
+ list.add(url);
+ }
+ }
+ }
+ return list;
+ }
+}
Added:
sandbox/ivol/amdatu-webapp/src/main/java/org/amdatu/webapp/StartupListener.java
==============================================================================
--- (empty file)
+++
sandbox/ivol/amdatu-webapp/src/main/java/org/amdatu/webapp/StartupListener.java
Thu Mar 10 10:04:19 2011
@@ -0,0 +1,34 @@
+/*
+ Copyright (C) 2010 Amdatu.org
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+package org.amdatu.webapp;
+
+import javax.servlet.ServletContextEvent;
+import javax.servlet.ServletContextListener;
+
+public final class StartupListener implements ServletContextListener {
+ private FrameworkService m_frameworkService;
+
+ public void contextInitialized(ServletContextEvent event) {
+ System.out.println("Starting felix!!!");
+ m_frameworkService = new FrameworkService(event.getServletContext());
+ m_frameworkService.start();
+ }
+
+ public void contextDestroyed(ServletContextEvent event) {
+ m_frameworkService.stop();
+ }
+}
Modified: sandbox/ivol/amdatu-webapp/src/main/webapp/WEB-INF/web.xml
==============================================================================
--- sandbox/ivol/amdatu-webapp/src/main/webapp/WEB-INF/web.xml (original)
+++ sandbox/ivol/amdatu-webapp/src/main/webapp/WEB-INF/web.xml Thu Mar 10
10:04:19 2011
@@ -4,7 +4,7 @@
<web-app>
<listener>
-
<listener-class>org.apache.felix.http.samples.bridge.StartupListener</listener-class>
+ <listener-class>org.amdatu.webapp.StartupListener</listener-class>
</listener>
<listener>
_______________________________________________
Amdatu-commits mailing list
[email protected]
http://lists.amdatu.org/mailman/listinfo/amdatu-commits