Author: [email protected]
Date: Mon Dec  5 17:10:45 2011
New Revision: 1821

Log:
[sandbox] Simple test application for multitenancy setup (AMDATU-468)

Added:
   sandbox/bdekruijff/amdatu-test/
   sandbox/bdekruijff/amdatu-test/pom.xml
   sandbox/bdekruijff/amdatu-test/src/
   sandbox/bdekruijff/amdatu-test/src/main/
   sandbox/bdekruijff/amdatu-test/src/main/java/
   sandbox/bdekruijff/amdatu-test/src/main/java/org/
   sandbox/bdekruijff/amdatu-test/src/main/java/org/amdatu/
   sandbox/bdekruijff/amdatu-test/src/main/java/org/amdatu/web/
   sandbox/bdekruijff/amdatu-test/src/main/java/org/amdatu/web/test/
   sandbox/bdekruijff/amdatu-test/src/main/java/org/amdatu/web/test/osgi/
   
sandbox/bdekruijff/amdatu-test/src/main/java/org/amdatu/web/test/osgi/Activator.java
   sandbox/bdekruijff/amdatu-test/src/main/java/org/amdatu/web/test/service/
   
sandbox/bdekruijff/amdatu-test/src/main/java/org/amdatu/web/test/service/ConfigurationTestServlet.java
   
sandbox/bdekruijff/amdatu-test/src/main/java/org/amdatu/web/test/service/FaviconResourceProviderImpl.java
   sandbox/bdekruijff/amdatu-test/src/main/resources/
   sandbox/bdekruijff/amdatu-test/src/main/resources/OSGI-INF/
   sandbox/bdekruijff/amdatu-test/src/main/resources/OSGI-INF/metatype/
   
sandbox/bdekruijff/amdatu-test/src/main/resources/OSGI-INF/metatype/metatype.xml
   sandbox/bdekruijff/amdatu-test/src/main/resources/favicon.ico

Added: sandbox/bdekruijff/amdatu-test/pom.xml
==============================================================================
--- (empty file)
+++ sandbox/bdekruijff/amdatu-test/pom.xml      Mon Dec  5 17:10:45 2011
@@ -0,0 +1,61 @@
+<?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";>
+  <modelVersion>4.0.0</modelVersion>
+  <parent>
+    <groupId>org.amdatu.web</groupId>
+    <artifactId>org.amdatu.web</artifactId>
+    <version>0.3.0-SNAPSHOT</version>
+  </parent>
+  <artifactId>org.amdatu.web.test</artifactId>
+  <packaging>bundle</packaging>
+  <name>Amdatu Web - Bramk test</name>
+  <description>${pom.name}</description>
+
+  <dependencies>
+    <dependency>
+      <groupId>org.amdatu.web</groupId>
+      <artifactId>org.amdatu.web.dispatcher</artifactId>
+      <version>${project.version}</version>
+      <scope>provided</scope>
+      <type>bundle</type>
+    </dependency>
+    <dependency>
+      <groupId>org.amdatu.web</groupId>
+      <artifactId>org.amdatu.web.httpcontext</artifactId>
+      <version>${project.version}</version>
+      <scope>provided</scope>
+      <type>bundle</type>
+    </dependency>
+    <dependency>
+      <groupId>org.amdatu.web</groupId>
+      <artifactId>org.amdatu.web.resource</artifactId>
+      <version>${project.version}</version>
+      <scope>provided</scope>
+      <type>bundle</type>
+    </dependency>
+  </dependencies>
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.felix</groupId>
+        <artifactId>maven-bundle-plugin</artifactId>
+        <configuration>
+          <instructions>
+            
<MultiTenant-Bundle-Activator>org.amdatu.web.test.osgi.Activator</MultiTenant-Bundle-Activator>
+            <!-- 
+            <MultiTenant-Scope>platform,tenant</MultiTenant-Scope>
+             -->
+            
<Bundle-Activator>org.amdatu.core.tenant.MultiTenantBundleActivator</Bundle-Activator>
+            <Bundle-SymbolicName>org.amdatu.web.test</Bundle-SymbolicName>
+            <Private-Package>org.amdatu.web.test.osgi</Private-Package>
+            <Import-Package>
+              org.amdatu.core.tenant;version="[1.0,2)",
+              *
+            </Import-Package>
+          </instructions>
+        </configuration>
+      </plugin>
+    </plugins>
+  </build>
+</project>

Added: 
sandbox/bdekruijff/amdatu-test/src/main/java/org/amdatu/web/test/osgi/Activator.java
==============================================================================
--- (empty file)
+++ 
sandbox/bdekruijff/amdatu-test/src/main/java/org/amdatu/web/test/osgi/Activator.java
        Mon Dec  5 17:10:45 2011
@@ -0,0 +1,65 @@
+/*
+    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.web.test.osgi;
+
+import java.util.Dictionary;
+import java.util.Hashtable;
+
+import javax.servlet.Servlet;
+
+import org.amdatu.web.dispatcher.DispatcherService;
+import org.amdatu.web.httpcontext.ResourceProvider;
+import org.amdatu.web.resource.ResourceSupport;
+import org.amdatu.web.test.service.ConfigurationTestServlet;
+import org.amdatu.web.test.service.FaviconResourceProviderImpl;
+import org.apache.felix.dm.DependencyActivatorBase;
+import org.apache.felix.dm.DependencyManager;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.Constants;
+import org.osgi.service.cm.ManagedService;
+
+public class Activator extends DependencyActivatorBase {
+
+    public final static String CONTEXTID = "amdatu-test";
+    public final static String FAVICON_ALIAS = "/favicon.ico";
+    public final static String SERVLET_ALIAS = "/test";
+    public final static String SERVLET_PID = "org.amdatu.web.test";
+
+    @Override
+    public void init(BundleContext context, DependencyManager manager) throws 
Exception {
+
+        Dictionary<String, Object> props1 = new Hashtable<String, Object>();
+        props1.put(DispatcherService.CONTEXT_ID_KEY, CONTEXTID);
+        props1.put(ResourceSupport.RESOURCE_ALIAS_KEY, FAVICON_ALIAS);
+
+        
manager.add(createComponent().setInterface(ResourceProvider.class.getName(), 
props1)
+            .setImplementation(new FaviconResourceProviderImpl()));
+
+        Dictionary<String, Object> props2 = new Hashtable<String, Object>();
+        props2.put(DispatcherService.CONTEXT_ID_KEY, CONTEXTID);
+        props2.put(DispatcherService.ALIAS_KEY, SERVLET_ALIAS);
+        props2.put(Constants.SERVICE_PID, SERVLET_PID);
+
+        manager.add(createComponent().setInterface(
+            new String[] { Servlet.class.getName(), 
ManagedService.class.getName() }, props2)
+            .setImplementation(new ConfigurationTestServlet()));
+    }
+
+    @Override
+    public void destroy(BundleContext arg0, DependencyManager arg1) throws 
Exception {
+    }
+}

Added: 
sandbox/bdekruijff/amdatu-test/src/main/java/org/amdatu/web/test/service/ConfigurationTestServlet.java
==============================================================================
--- (empty file)
+++ 
sandbox/bdekruijff/amdatu-test/src/main/java/org/amdatu/web/test/service/ConfigurationTestServlet.java
      Mon Dec  5 17:10:45 2011
@@ -0,0 +1,37 @@
+package org.amdatu.web.test.service;
+
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.util.Dictionary;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.osgi.service.cm.ConfigurationException;
+import org.osgi.service.cm.ManagedService;
+
+public class ConfigurationTestServlet extends HttpServlet implements 
ManagedService {
+
+    private String m_message = "???";
+
+    @Override
+    protected void doGet(HttpServletRequest req, HttpServletResponse resp) 
throws ServletException, IOException {
+
+        PrintWriter p = resp.getWriter();
+        p.append("Message: ");
+        p.append(m_message);
+        p.close();
+    }
+
+    public void updated(Dictionary properties) throws ConfigurationException {
+
+        if (properties != null) {
+            String message = (String) 
properties.get("org.amdatu.web.test.HelloMessage");
+            if (message != null) {
+                m_message = message;
+            }
+        }
+    }
+}

Added: 
sandbox/bdekruijff/amdatu-test/src/main/java/org/amdatu/web/test/service/FaviconResourceProviderImpl.java
==============================================================================
--- (empty file)
+++ 
sandbox/bdekruijff/amdatu-test/src/main/java/org/amdatu/web/test/service/FaviconResourceProviderImpl.java
   Mon Dec  5 17:10:45 2011
@@ -0,0 +1,35 @@
+/*
+    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.web.test.service;
+
+import java.net.URL;
+
+import org.amdatu.web.httpcontext.ResourceProvider;
+import org.amdatu.web.test.osgi.Activator;
+import org.osgi.framework.BundleContext;
+
+public class FaviconResourceProviderImpl implements ResourceProvider {
+
+    private volatile BundleContext m_bundleContext;
+
+    public URL getResource(String name) {
+        if (name != null && name.startsWith(Activator.FAVICON_ALIAS)) {
+            return m_bundleContext.getBundle().getResource("favicon.ico");
+        }
+        return null;
+    }
+}

Added: 
sandbox/bdekruijff/amdatu-test/src/main/resources/OSGI-INF/metatype/metatype.xml
==============================================================================
--- (empty file)
+++ 
sandbox/bdekruijff/amdatu-test/src/main/resources/OSGI-INF/metatype/metatype.xml
    Mon Dec  5 17:10:45 2011
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<MetaData xmlns="http://www.osgi.org/xmlns/metatype/v1.1.0"; 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
+  xsi:schemaLocation="http://www.osgi.org/xmlns/metatype/v1.1.0 
http://www.osgi.org/xmlns/metatype/v1.1.0";>
+  <OCD id="org.amdatu.web.test" name="Amdatu Test config OCD">
+    <AD id="org.amdatu.web.test.HelloMessage" name="HelloMessage" 
type="String" cardinality="0" default="Hello World!"
+      required="false" description="" />
+  </OCD>
+  <Designate pid="org.amdatu.web.test">
+    <Object ocdref="org.amdatu.web.test">
+    </Object>
+  </Designate>
+</MetaData>
\ No newline at end of file

Added: sandbox/bdekruijff/amdatu-test/src/main/resources/favicon.ico
==============================================================================
Binary files (empty file) and 
sandbox/bdekruijff/amdatu-test/src/main/resources/favicon.ico     Mon Dec  5 
17:10:45 2011 differ
_______________________________________________
Amdatu-commits mailing list
[email protected]
http://lists.amdatu.org/mailman/listinfo/amdatu-commits

Reply via email to