Author: [email protected]
Date: Tue Dec 13 17:37:44 2011
New Revision: 1850

Log:
AMDATU-479 Made Jsp/Resource support tenant aware. They now propagate tenant id 
if present

Modified:
   trunk/amdatu-web/jsp/pom.xml
   
trunk/amdatu-web/jsp/src/main/java/org/amdatu/web/jsp/service/ResourceProviderListener.java
   trunk/amdatu-web/resource/pom.xml
   
trunk/amdatu-web/resource/src/main/java/org/amdatu/web/resource/service/ResourceProviderListener.java

Modified: trunk/amdatu-web/jsp/pom.xml
==============================================================================
--- trunk/amdatu-web/jsp/pom.xml        (original)
+++ trunk/amdatu-web/jsp/pom.xml        Tue Dec 13 17:37:44 2011
@@ -29,6 +29,20 @@
 
   <dependencies>
     <dependency>
+      <groupId>org.amdatu.core</groupId>
+      <artifactId>org.amdatu.core.tenant</artifactId>
+      <version>${project.version}</version>
+      <scope>provided</scope>
+      <type>bundle</type>
+    </dependency>
+    <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>
       <scope>provided</scope>
@@ -84,6 +98,7 @@
               org.amdatu.web.jsp;version=1.0.0
             </Export-Package>
             <Import-Package>
+              !org.amdatu.core.tenant,
               !javax.mail.*,
               !javax.management.*,
               !org.apache.coyote.*,

Modified: 
trunk/amdatu-web/jsp/src/main/java/org/amdatu/web/jsp/service/ResourceProviderListener.java
==============================================================================
--- 
trunk/amdatu-web/jsp/src/main/java/org/amdatu/web/jsp/service/ResourceProviderListener.java
 (original)
+++ 
trunk/amdatu-web/jsp/src/main/java/org/amdatu/web/jsp/service/ResourceProviderListener.java
 Tue Dec 13 17:37:44 2011
@@ -15,21 +15,24 @@
  */
 package org.amdatu.web.jsp.service;
 
-import java.util.Dictionary;
-import java.util.Hashtable;
-import java.util.concurrent.ConcurrentHashMap;
-
-import javax.servlet.Servlet;
-
-import org.amdatu.web.httpcontext.HttpContextManagerService;
-import org.amdatu.web.httpcontext.ResourceProvider;
-import org.amdatu.web.jsp.JspSupport;
-import org.apache.felix.dm.Component;
-import org.apache.felix.dm.DependencyManager;
-import org.osgi.framework.Bundle;
-import org.osgi.framework.Constants;
-import org.osgi.framework.ServiceReference;
-import org.osgi.service.log.LogService;
+import static org.amdatu.core.tenant.Tenant.TENANT_ID_SERVICEPROPERTY;
+
+import java.util.Dictionary;
+import java.util.Hashtable;
+import java.util.concurrent.ConcurrentHashMap;
+
+import javax.servlet.Servlet;
+
+import org.amdatu.web.dispatcher.DispatcherService;
+import org.amdatu.web.httpcontext.HttpContextManagerService;
+import org.amdatu.web.httpcontext.ResourceProvider;
+import org.amdatu.web.jsp.JspSupport;
+import org.apache.felix.dm.Component;
+import org.apache.felix.dm.DependencyManager;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.Constants;
+import org.osgi.framework.ServiceReference;
+import org.osgi.service.log.LogService;
 
 /**
  * This class is responsible for registration of JSP Servlets for each 
ResourceProvider that
@@ -54,8 +57,21 @@
     public void resourceProviderAdded(ServiceReference serviceReference) {
 
         final long serviceId = getLongProperty(serviceReference, 
Constants.SERVICE_ID);
-        final String contextId = getStringProperty(serviceReference, 
HttpContextManagerService.CONTEXT_ID_KEY);
-        final String jspAlias = getStringProperty(serviceReference, 
JSP_ALIAS_KEY);
+        
+        final String contextId = getStringProperty(serviceReference, 
HttpContextManagerService.CONTEXT_ID_KEY);
+        if (contextId == null || "".equals(contextId)) {
+            m_logService.log(LogService.LOG_WARNING, "ResourceProvider(" + 
serviceId
+                + ") does not specify a contextId. Ignoring..");
+            return;
+        }
+
+        final String jspAlias = getStringProperty(serviceReference, 
JSP_ALIAS_KEY);
+        if (jspAlias == null || "".equals(jspAlias)) {
+            m_logService.log(LogService.LOG_WARNING, "ResourceProvider(" + 
serviceId
+                + ") does not specify a jspAlias. Ignoring..");
+            return;
+        }
+
         final Bundle jspBundle = serviceReference.getBundle();
 
         if (jspAlias == null || "".equals(jspAlias)) {
@@ -64,7 +80,7 @@
             return;
         }
 
-        final Component jspServletComponent = 
createJspServletComponent(contextId, jspAlias, jspBundle);
+        final Component jspServletComponent = 
createJspServletComponent(serviceReference, jspBundle);
         if (m_components.putIfAbsent(serviceReference, jspServletComponent) != 
null) {
             m_logService.log(LogService.LOG_WARNING, "ResourceProvider(" + 
serviceId
                 + ") specifies already registered jspalias. Ignoring..");
@@ -91,14 +107,23 @@
                 + serviceId + ").");
     }
 
-    private Component createJspServletComponent(final String contextId, final 
String jspAlias, final Bundle jspBundle) {
-
+    private Component createJspServletComponent(final ServiceReference 
serviceReference, final Bundle jspBundle) {
+
         Dictionary<String, Object> properties = new Hashtable<String, 
Object>();
-        properties.put("alias", jspAlias);
+
+        final String jspAlias = getStringProperty(serviceReference, 
JSP_ALIAS_KEY);
+        properties.put(DispatcherService.ALIAS_KEY, jspAlias);
+        
+        final String contextId = getStringProperty(serviceReference, 
HttpContextManagerService.CONTEXT_ID_KEY);
         if (contextId != null && !"".equals(contextId)) {
-            properties.put("contextId", contextId);
+            properties.put(HttpContextManagerService.CONTEXT_ID_KEY, 
contextId);
         }
 
+        //AMDATU-479 - this is tricky
+        final String tenantId = getStringProperty(serviceReference, 
TENANT_ID_SERVICEPROPERTY);
+        if(tenantId != null)
+            properties.put(TENANT_ID_SERVICEPROPERTY, tenantId);
+
         ResourceProviderJspServlet jspServlet = new 
ResourceProviderJspServlet(jspBundle);
         Component component = m_dependencyManager.createComponent()
                         .setInterface(Servlet.class.getName(), properties)

Modified: trunk/amdatu-web/resource/pom.xml
==============================================================================
--- trunk/amdatu-web/resource/pom.xml   (original)
+++ trunk/amdatu-web/resource/pom.xml   Tue Dec 13 17:37:44 2011
@@ -29,6 +29,20 @@
   
   <dependencies>
     <dependency>
+      <groupId>org.amdatu.core</groupId>
+      <artifactId>org.amdatu.core.tenant</artifactId>
+      <version>${project.version}</version>
+      <scope>provided</scope>
+      <type>bundle</type>
+    </dependency>
+    <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>
@@ -48,7 +62,10 @@
             <Bundle-SymbolicName>org.amdatu.web.resource</Bundle-SymbolicName> 
       
             <Embed-Dependency>*;scope=compile</Embed-Dependency>
             <Embed-Transitive>true</Embed-Transitive>
-            <Export-Package />
+            <Import-Package>
+              !org.amdatu.core.tenant,
+              *
+            </Import-Package>
           </instructions>
         </configuration>
       </plugin>   

Modified: 
trunk/amdatu-web/resource/src/main/java/org/amdatu/web/resource/service/ResourceProviderListener.java
==============================================================================
--- 
trunk/amdatu-web/resource/src/main/java/org/amdatu/web/resource/service/ResourceProviderListener.java
       (original)
+++ 
trunk/amdatu-web/resource/src/main/java/org/amdatu/web/resource/service/ResourceProviderListener.java
       Tue Dec 13 17:37:44 2011
@@ -15,20 +15,23 @@
  */
 package org.amdatu.web.resource.service;
 
-import java.util.Dictionary;
-import java.util.Hashtable;
-import java.util.concurrent.ConcurrentHashMap;
-
-import javax.servlet.Servlet;
-
-import org.amdatu.web.httpcontext.HttpContextManagerService;
-import org.amdatu.web.httpcontext.ResourceProvider;
-import org.amdatu.web.resource.ResourceSupport;
-import org.apache.felix.dm.Component;
-import org.apache.felix.dm.DependencyManager;
-import org.osgi.framework.Constants;
-import org.osgi.framework.ServiceReference;
-import org.osgi.service.log.LogService;
+import static org.amdatu.core.tenant.Tenant.TENANT_ID_SERVICEPROPERTY;
+
+import java.util.Dictionary;
+import java.util.Hashtable;
+import java.util.concurrent.ConcurrentHashMap;
+
+import javax.servlet.Servlet;
+
+import org.amdatu.web.dispatcher.DispatcherService;
+import org.amdatu.web.httpcontext.HttpContextManagerService;
+import org.amdatu.web.httpcontext.ResourceProvider;
+import org.amdatu.web.resource.ResourceSupport;
+import org.apache.felix.dm.Component;
+import org.apache.felix.dm.DependencyManager;
+import org.osgi.framework.Constants;
+import org.osgi.framework.ServiceReference;
+import org.osgi.service.log.LogService;
 
 /**
  * This class is responsible for registration of Resource Servlets for each
@@ -52,16 +55,22 @@
     public void resourceProviderAdded(ServiceReference serviceReference, 
ResourceProvider resourceProvider) {
 
         final long serviceId = getLongProperty(serviceReference, 
Constants.SERVICE_ID);
-        final String contextId = getStringProperty(serviceReference, 
HttpContextManagerService.CONTEXT_ID_KEY);
-        final String resourceAlias = getStringProperty(serviceReference, 
RESOURCE_ALIAS_KEY);
 
-        if (resourceAlias == null || "".equals(resourceAlias)) {
-            m_logService.log(LogService.LOG_DEBUG, "ResourceProvider(" + 
serviceId
-                + ") does not specify a resourceAlias. Ignoring..");
-            return;
-        }
-
-        final Component resourceServletComponent = 
createResourceServletComponent(contextId, resourceAlias);
+        final String contextId = getStringProperty(serviceReference, 
HttpContextManagerService.CONTEXT_ID_KEY);
+        if (contextId == null || "".equals(contextId)) {
+            m_logService.log(LogService.LOG_WARNING, "ResourceProvider(" + 
serviceId
+                + ") does not specify a contextId. Ignoring..");
+            return;
+        }
+
+        final String resourceAlias = getStringProperty(serviceReference, 
RESOURCE_ALIAS_KEY);
+        if (resourceAlias == null || "".equals(resourceAlias)) {
+            m_logService.log(LogService.LOG_WARNING, "ResourceProvider(" + 
serviceId
+                + ") does not specify a resourceAlias. Ignoring..");
+            return;
+        }
+
+        final Component resourceServletComponent = 
createResourceServletComponent(serviceReference);
         if (m_components.putIfAbsent(serviceReference, 
resourceServletComponent) != null) {
             m_logService.log(LogService.LOG_WARNING, "ResourceProvider(" + 
serviceId
                 + ") specifies already registered resourceAlias. Ignoring..");
@@ -89,11 +98,21 @@
                 + serviceId + ").");
     }
 
-    private Component createResourceServletComponent(final String contextId, 
final String resourceAlias) {
-        Dictionary<String, Object> properties = new Hashtable<String, 
Object>();
-        properties.put("alias", resourceAlias);
+    private Component createResourceServletComponent(final ServiceReference 
serviceReference) {
+
+        Dictionary<String, Object> properties = new Hashtable<String, 
Object>();
+        
+        final String resourceAlias = getStringProperty(serviceReference, 
RESOURCE_ALIAS_KEY);
+        properties.put(DispatcherService.ALIAS_KEY, resourceAlias);
+        
+        final String contextId = getStringProperty(serviceReference, 
HttpContextManagerService.CONTEXT_ID_KEY);
         if (properties != null)
-            properties.put("contextId", contextId);
+            properties.put(HttpContextManagerService.CONTEXT_ID_KEY, 
contextId);
+        
+        //AMDATU-479 - this is tricky
+        final String tenantId = getStringProperty(serviceReference, 
TENANT_ID_SERVICEPROPERTY);
+        if(tenantId != null)
+            properties.put(TENANT_ID_SERVICEPROPERTY, tenantId);
 
         Component servletComponent = m_dependencyManager.createComponent();
         servletComponent.setInterface(Servlet.class.getName(), properties);
_______________________________________________
Amdatu-commits mailing list
[email protected]
http://lists.amdatu.org/mailman/listinfo/amdatu-commits

Reply via email to