Author: ivol37 at gmail.com
Date: Mon Feb 14 10:15:17 2011
New Revision: 779

Log:
[AMDATU-288] Refactored tenant resolvers to read Tenant from Request attribute 
instead of doing its own resolving. Increased service ranking of hostname 
tenant resolver to ensure that this filter is invoked first.

Modified:
   trunk/amdatu-opensocial/profile/pom.xml
   
trunk/amdatu-opensocial/profile/src/main/java/org/amdatu/opensocial/profile/osgi/Activator.java
   
trunk/amdatu-opensocial/profile/src/main/java/org/amdatu/opensocial/profile/service/TenantHostnameDispatchExtenderFilter.java
   trunk/amdatu-opensocial/shindig/pom.xml
   
trunk/amdatu-opensocial/shindig/src/main/java/org/amdatu/opensocial/shindig/osgi/Activator.java
   
trunk/amdatu-opensocial/shindig/src/main/java/org/amdatu/opensocial/shindig/service/ShindigRegistrationServiceImpl.java
   
trunk/amdatu-opensocial/shindig/src/main/java/org/amdatu/opensocial/shindig/service/TenantHostnameDispatchExtenderFilter.java
   
trunk/amdatu-web/tenantresolver-hostname/src/main/java/org/amdatu/web/tenantresolver/hostname/osgi/HostnameTenantResolverActivator.java

Modified: trunk/amdatu-opensocial/profile/pom.xml
==============================================================================
--- trunk/amdatu-opensocial/profile/pom.xml     (original)
+++ trunk/amdatu-opensocial/profile/pom.xml     Mon Feb 14 10:15:17 2011
@@ -46,6 +46,13 @@
       <scope>provided</scope>
       <type>bundle</type>
     </dependency>
+    <dependency>
+      <groupId>org.amdatu.web</groupId>
+      <artifactId>tenantresolver-hostname</artifactId>
+      <version>${platform.version}</version>
+      <scope>provided</scope>
+      <type>bundle</type>
+    </dependency>
   </dependencies>
 
   <build>

Modified: 
trunk/amdatu-opensocial/profile/src/main/java/org/amdatu/opensocial/profile/osgi/Activator.java
==============================================================================
--- 
trunk/amdatu-opensocial/profile/src/main/java/org/amdatu/opensocial/profile/osgi/Activator.java
     (original)
+++ 
trunk/amdatu-opensocial/profile/src/main/java/org/amdatu/opensocial/profile/osgi/Activator.java
     Mon Feb 14 10:15:17 2011
@@ -21,7 +21,6 @@
 
 import org.amdatu.cassandra.listener.ColumnFamilyAvailable;
 import org.amdatu.cassandra.listener.ColumnFamilyProvider;
-import org.amdatu.core.tenant.TenantManagementService;
 import org.amdatu.opensocial.profile.PersonService;
 import org.amdatu.opensocial.profile.service.FriendColumnFamilyProvider;
 import org.amdatu.opensocial.profile.service.PersonServiceImpl;
@@ -39,32 +38,31 @@
     public void init(BundleContext context, DependencyManager manager) throws 
Exception {
         // Create and register the FirendColumnFamilyProvider service.
         manager.add(
-                createComponent()
-                .setInterface(ColumnFamilyProvider.class.getName(), null)
-                .setImplementation(FriendColumnFamilyProvider.class));
-                
+            createComponent()
+            .setInterface(ColumnFamilyProvider.class.getName(), null)
+            .setImplementation(FriendColumnFamilyProvider.class));
+
         // Register the person service with tenant aware service adapter. As a 
result a PersonService
         // will be instantiated by the Felix dependency manager for each 
available tenant.
         String filter = "(" + ColumnFamilyAvailable.FILTER_NAME + "=" + 
FriendColumnFamilyProvider.CF_FRIEND + ")";
         manager.add(
-                createComponent()
-                .setImplementation(PersonServiceImpl.class)
-                .setInterface(new String[]{PersonService.class.getName(), 
org.apache.shindig.social.opensocial.spi.PersonService.class.getName()}, null)
-                
.add(createServiceDependency().setService(LogService.class).setRequired(true))
-                
.add(createServiceDependency().setService(ColumnFamilyAvailable.class, 
filter).setRequired(true)));
-        
+            createComponent()
+            .setImplementation(PersonServiceImpl.class)
+            .setInterface(new String[]{PersonService.class.getName(), 
org.apache.shindig.social.opensocial.spi.PersonService.class.getName()}, null)
+            
.add(createServiceDependency().setService(LogService.class).setRequired(true))
+            
.add(createServiceDependency().setService(ColumnFamilyAvailable.class, 
filter).setRequired(true)));
+
         // Register the dispatch extender filter, used to resolve tenants
         Dictionary<String, Object> properties = new Hashtable<String, 
Object>();
         properties.put(Constants.SERVICE_RANKING, 0);
         properties.put(DispatcherService.PATTERN_KEY, ".*");
         manager.add(
-                createComponent()
-                    .setInterface(DispatchExtenderFilter.class.getName(), 
properties)
-                    
.setImplementation(TenantHostnameDispatchExtenderFilter.class)
-                    
.add(createServiceDependency().setService(TenantManagementService.class).setRequired(true)));
        
+            createComponent()
+            .setInterface(DispatchExtenderFilter.class.getName(), properties)
+            .setImplementation(TenantHostnameDispatchExtenderFilter.class));
     }
-    
+
     @Override
-    public void destroy(BundleContext context, DependencyManager manager) 
throws Exception {   
+    public void destroy(BundleContext context, DependencyManager manager) 
throws Exception {
     }
 }

Modified: 
trunk/amdatu-opensocial/profile/src/main/java/org/amdatu/opensocial/profile/service/TenantHostnameDispatchExtenderFilter.java
==============================================================================
--- 
trunk/amdatu-opensocial/profile/src/main/java/org/amdatu/opensocial/profile/service/TenantHostnameDispatchExtenderFilter.java
       (original)
+++ 
trunk/amdatu-opensocial/profile/src/main/java/org/amdatu/opensocial/profile/service/TenantHostnameDispatchExtenderFilter.java
       Mon Feb 14 10:15:17 2011
@@ -17,20 +17,16 @@
 package org.amdatu.opensocial.profile.service;
 
 import java.io.IOException;
-import java.util.List;
 
 import javax.servlet.FilterChain;
 import javax.servlet.FilterConfig;
 import javax.servlet.ServletException;
 import javax.servlet.ServletRequest;
 import javax.servlet.ServletResponse;
-import javax.servlet.http.HttpServletRequest;
 
 import org.amdatu.core.tenant.Tenant;
-import org.amdatu.core.tenant.TenantEntity;
-import org.amdatu.core.tenant.TenantException;
-import org.amdatu.core.tenant.TenantManagementService;
 import org.amdatu.web.dispatcher.DispatchExtenderFilter;
+import 
org.amdatu.web.tenantresolver.hostname.service.HostnameTenantResolverExtenderFilter;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.InvalidSyntaxException;
 import org.osgi.framework.ServiceReference;
@@ -38,74 +34,62 @@
 
 /**
  * This tenant dispatch extender filter is registered on .* and captures all 
HTTP requests to resolve the
- * tenant from the hostname of the request. It stores the tenant for the 
lifetime of that request on a 
- * ThreadLocal so that the PersonServiceImpl can retrieve the tenant from this 
ThreadLocal. Note that 
+ * tenant from the hostname of the request. It stores the tenant for the 
lifetime of that request on a
+ * ThreadLocal so that the PersonServiceImpl can retrieve the tenant from this 
ThreadLocal. Note that
  * the PersonServiceImpl is not tenant aware, nor does it have access to the 
HTTP request.
  * 
  * @author ivol
  */
 public class TenantHostnameDispatchExtenderFilter implements 
DispatchExtenderFilter {
-       // Service dependencies, injected by the framework
-       private volatile TenantManagementService m_tenantManagementService;
-       private static volatile BundleContext m_bundleContext;
-
-       // Tenant context information is bound to a ThreadLocal variable.
-       private static ThreadLocal<Tenant> m_properties = null;
-
-       public void init(FilterConfig filterConfig) throws ServletException {
-               // Create the threadlocal
-               m_properties = new ThreadLocal<Tenant>();
-       }
-
-       public void doFilter(ServletRequest request, ServletResponse response, 
FilterChain chain) throws IOException, ServletException {
-               HttpServletRequest httpServletRequest = (HttpServletRequest) 
request;
-               String serverName = httpServletRequest.getServerName();
-               if (serverName != null) {
-                       try {
-                               List<TenantEntity> tenants = 
m_tenantManagementService.getTenants();
-                               for (TenantEntity tenant : tenants) {
-                                       if 
(serverName.equals(tenant.getProperties().get(Tenant.HOSTNAME_PROPERTY))) {
-                                               // The servername of the 
request matches the hostname of this tenant so
-                                               // set the tenant on the 
threadlocal variable
-                                               m_properties.set(tenant);
-                                       }       
-                               }
-                       }
-                       catch (TenantException e) {}
-               }
-
-               chain.doFilter(request, response);
-
-               // Set the tenant to null
-               m_properties.set(null);
-       }
-
-       public void destroy() {
-               // Destroy the threadlocal
-               m_properties = null;
-       }
-
-       /**
-        * Returns the tenant on the ThreadLocal.
-        * @return the current tenant
-        */
-       public static Tenant getTenant() {
-               return m_properties.get();
-       }
-
-       /**
-        * Returns the UserAdmin service that is associated with the current 
tenant.
-        * @return the UserAdmin service that is associated with the current 
tenant.
-        * @throws InvalidSyntaxException In case the UserAdmin service 
references could not be retrieved.
-        */
-       public static UserAdmin getUserAdmin() throws InvalidSyntaxException {
-               Tenant tenant = getTenant();
-               ServiceReference[] refs = 
m_bundleContext.getAllServiceReferences(UserAdmin.class.getName(), null);
-               for (ServiceReference ref : refs) {
-                       if 
(tenant.getId().equals(ref.getProperty(Tenant.TENANT_ID_SERVICEPROPERTY))) {
-                               return (UserAdmin) 
m_bundleContext.getService(ref);
-                       }
-               }
-               return null;
-       }
+    // Service dependencies, injected by the framework
+    private static volatile BundleContext m_bundleContext;
+
+    // Tenant context information is bound to a ThreadLocal variable.
+    private static ThreadLocal<Tenant> m_properties = null;
+
+    public void init(FilterConfig filterConfig) throws ServletException {
+        // Create the threadlocal
+        m_properties = new ThreadLocal<Tenant>();
+    }
+
+    public void doFilter(ServletRequest request, ServletResponse response, 
FilterChain chain) throws IOException, ServletException {
+        Object tenant = 
request.getAttribute(HostnameTenantResolverExtenderFilter.TENANT_REQUESTCONTEXT_KEY);
+        if (tenant != null && tenant instanceof Tenant) {
+            m_properties.set((Tenant) tenant);
+        }
+
+        chain.doFilter(request, response);
+
+        // Set the tenant to null
+        m_properties.set(null);
+    }
+
+    public void destroy() {
+        // Destroy the threadlocal
+        m_properties = null;
+    }
+
+    /**
+     * Returns the tenant on the ThreadLocal.
+     * @return the current tenant
+     */
+    public static Tenant getTenant() {
+        return m_properties.get();
+    }
+
+    /**
+     * Returns the UserAdmin service that is associated with the current 
tenant.
+     * @return the UserAdmin service that is associated with the current 
tenant.
+     * @throws InvalidSyntaxException In case the UserAdmin service references 
could not be retrieved.
+     */
+    public static UserAdmin getUserAdmin() throws InvalidSyntaxException {
+        Tenant tenant = getTenant();
+        ServiceReference[] refs = 
m_bundleContext.getAllServiceReferences(UserAdmin.class.getName(), null);
+        for (ServiceReference ref : refs) {
+            if 
(tenant.getId().equals(ref.getProperty(Tenant.TENANT_ID_SERVICEPROPERTY))) {
+                return (UserAdmin) m_bundleContext.getService(ref);
+            }
+        }
+        return null;
+    }
 }

Modified: trunk/amdatu-opensocial/shindig/pom.xml
==============================================================================
--- trunk/amdatu-opensocial/shindig/pom.xml     (original)
+++ trunk/amdatu-opensocial/shindig/pom.xml     Mon Feb 14 10:15:17 2011
@@ -153,6 +153,13 @@
       <scope>provided</scope>
       <type>bundle</type>
     </dependency>
+    <dependency>
+      <groupId>org.amdatu.web</groupId>
+      <artifactId>tenantresolver-hostname</artifactId>
+      <version>${platform.version}</version>
+      <scope>provided</scope>
+      <type>bundle</type>
+    </dependency>
   </dependencies>
 
   <build>

Modified: 
trunk/amdatu-opensocial/shindig/src/main/java/org/amdatu/opensocial/shindig/osgi/Activator.java
==============================================================================
--- 
trunk/amdatu-opensocial/shindig/src/main/java/org/amdatu/opensocial/shindig/osgi/Activator.java
     (original)
+++ 
trunk/amdatu-opensocial/shindig/src/main/java/org/amdatu/opensocial/shindig/osgi/Activator.java
     Mon Feb 14 10:15:17 2011
@@ -19,12 +19,9 @@
 import java.util.Dictionary;
 import java.util.Hashtable;
 
-import javax.servlet.Filter;
-
 import org.amdatu.cassandra.listener.ColumnFamilyAvailable;
 import org.amdatu.cassandra.listener.ColumnFamilyProvider;
 import org.amdatu.cassandra.persistencemanager.CassandraPersistenceManager;
-import org.amdatu.core.tenant.TenantManagementService;
 import org.amdatu.opensocial.shindig.GadgetStore;
 import org.amdatu.opensocial.shindig.OAuthModule;
 import org.amdatu.opensocial.shindig.ShindigService;
@@ -41,7 +38,6 @@
 import org.amdatu.opensocial.shindig.service.ShindigRegistrationServiceImpl;
 import 
org.amdatu.opensocial.shindig.service.TenantHostnameDispatchExtenderFilter;
 import org.amdatu.web.dispatcher.DispatchExtenderFilter;
-import org.amdatu.web.dispatcher.DispatcherService;
 import org.amdatu.web.httpcontext.HttpContextServiceFactory;
 import org.amdatu.web.httpcontext.ResourceProvider;
 import org.apache.felix.dm.DependencyActivatorBase;
@@ -61,100 +57,99 @@
     // The resource identifier for this bundle. Resources are only considered 
to be 'ours' when
     // it is prefixed with this id. Do not not append "/" at the beginning or 
end of the identifier.
     public final static String RESOURCE_ID = "gadgets";
-        
+
     @Override
     public void init(BundleContext context, DependencyManager manager) throws 
Exception {
         // First define a service that provides the Gadget ColumnFamily we need
         manager.add(createComponent()
-                .setInterface(new 
String[]{ColumnFamilyProvider.class.getName()}, null)
-                .setImplementation(GadgetColumnFamilyProvider.class));
-        
+            .setInterface(new String[]{ColumnFamilyProvider.class.getName()}, 
null)
+            .setImplementation(GadgetColumnFamilyProvider.class));
+
         // Create and register the AppData service store
-        manager.add( 
-                createComponent()
-                .setImplementation(CassandraAppDataServiceStore.class)
-                .setInterface(AppDataService.class.getName(), null)
-                
.add(createServiceDependency().setService(LogService.class).setRequired(true)));
-        
+        manager.add(
+            createComponent()
+            .setImplementation(CassandraAppDataServiceStore.class)
+            .setInterface(AppDataService.class.getName(), null)
+            
.add(createServiceDependency().setService(LogService.class).setRequired(true)));
+
         // Create and register the Gadget store
-        String gadgetKeyspaceFilter = "(" + 
CassandraPersistenceManager.KEYSPACE_AWARE_KEY + "=" + 
CassandraPersistenceManager.DEFAULT_KEYSPACE + ")"; 
+        String gadgetKeyspaceFilter = "(" + 
CassandraPersistenceManager.KEYSPACE_AWARE_KEY + "=" + 
CassandraPersistenceManager.DEFAULT_KEYSPACE + ")";
         String gadgetCFAvailableFilter = "(&(" + 
ColumnFamilyAvailable.FILTER_NAME + "=" + GadgetStore.CF_GADGET + ")" + 
gadgetKeyspaceFilter + ")";
-        manager.add( 
-                createComponent()
-                .setImplementation(GadgetStoreImpl.class)
-                .setInterface(GadgetStore.class.getName(), null)
-                
.add(createServiceDependency().setService(LogService.class).setRequired(true))
-                
.add(createServiceDependency().setService(CassandraPersistenceManager.class, 
gadgetKeyspaceFilter).setRequired(true))
-                
.add(createServiceDependency().setService(ColumnFamilyAvailable.class, 
gadgetCFAvailableFilter).setRequired(true)));
-        
+        manager.add(
+            createComponent()
+            .setImplementation(GadgetStoreImpl.class)
+            .setInterface(GadgetStore.class.getName(), null)
+            
.add(createServiceDependency().setService(LogService.class).setRequired(true))
+            
.add(createServiceDependency().setService(CassandraPersistenceManager.class, 
gadgetKeyspaceFilter).setRequired(true))
+            
.add(createServiceDependency().setService(ColumnFamilyAvailable.class, 
gadgetCFAvailableFilter).setRequired(true)));
+
         // Create and register the oAuth store
-        manager.add( 
-                createComponent()
-                .setImplementation(CassandraOAuthStore.class)
-                .setInterface(OAuthStore.class.getName(), null)
-                
.add(createServiceDependency().setService(LogService.class).setRequired(true))
-                
.add(createServiceDependency().setService(GadgetStore.class).setRequired(true))
-                
.add(createServiceDependency().setService(ColumnFamilyAvailable.class, 
gadgetCFAvailableFilter).setRequired(true)));  
+        manager.add(
+            createComponent()
+            .setImplementation(CassandraOAuthStore.class)
+            .setInterface(OAuthStore.class.getName(), null)
+            
.add(createServiceDependency().setService(LogService.class).setRequired(true))
+            
.add(createServiceDependency().setService(GadgetStore.class).setRequired(true))
+            
.add(createServiceDependency().setService(ColumnFamilyAvailable.class, 
gadgetCFAvailableFilter).setRequired(true)));
 
         // Create and register the Social API module
-        manager.add( 
-                createComponent()
-                .setImplementation(SocialApiModuleImpl.class)
-                .setInterface(SocialApiModule.class.getName(), null)
-                
.add(createServiceDependency().setService(LogService.class).setRequired(true))
-                
.add(createServiceDependency().setService(AppDataService.class).setRequired(true)));
-                
+        manager.add(
+            createComponent()
+            .setImplementation(SocialApiModuleImpl.class)
+            .setInterface(SocialApiModule.class.getName(), null)
+            
.add(createServiceDependency().setService(LogService.class).setRequired(true))
+            
.add(createServiceDependency().setService(AppDataService.class).setRequired(true)));
+
         // Create and register the oAuth module
-        manager.add( 
-                createComponent()
-                .setImplementation(OAuthModuleImpl.class)
-                .setInterface(OAuthModule.class.getName(), null)
-                
.add(createServiceDependency().setService(LogService.class).setRequired(true))
-                
.add(createServiceDependency().setService(OAuthStore.class).setRequired(true)));
+        manager.add(
+            createComponent()
+            .setImplementation(OAuthModuleImpl.class)
+            .setInterface(OAuthModule.class.getName(), null)
+            
.add(createServiceDependency().setService(LogService.class).setRequired(true))
+            
.add(createServiceDependency().setService(OAuthStore.class).setRequired(true)));
 
         // Create the configuration module
         manager.add(
-                createComponent()
-                .setInterface(ConfigurationAdminGuiceModule.class.getName(), 
null)
-                .setImplementation(ConfigurationAdminGuiceModule.class)
-                
.add(createConfigurationDependency().setPid(ShindigService.SHINDIG_CONFIG_PID).setPropagate(true)));
-        
+            createComponent()
+            .setInterface(ConfigurationAdminGuiceModule.class.getName(), null)
+            .setImplementation(ConfigurationAdminGuiceModule.class)
+            
.add(createConfigurationDependency().setPid(ShindigService.SHINDIG_CONFIG_PID).setPropagate(true)));
+
         // Create the Guice injector servlet
         manager.add(
-                createComponent()
-                .setInterface(GuiceInjectorService.class.getName(), null)
-                .setImplementation(GuiceInjectorServiceImpl.class)
-                .setCallbacks("_init", "start", "stop", "_destroy")
-                
.add(createServiceDependency().setService(LogService.class).setRequired(true))
-                
.add(createServiceDependency().setService(SocialApiModule.class).setRequired(true))
-                
.add(createServiceDependency().setService(OAuthModule.class).setRequired(true))
-                
.add(createServiceDependency().setService(ConfigurationAdminGuiceModule.class, 
"("+ Constants.SERVICE_PID + "=" + ShindigService.SHINDIG_CONFIG_PID + ")")
-                        .setRequired(true)));
-        
+            createComponent()
+            .setInterface(GuiceInjectorService.class.getName(), null)
+            .setImplementation(GuiceInjectorServiceImpl.class)
+            .setCallbacks("_init", "start", "stop", "_destroy")
+            
.add(createServiceDependency().setService(LogService.class).setRequired(true))
+            
.add(createServiceDependency().setService(SocialApiModule.class).setRequired(true))
+            
.add(createServiceDependency().setService(OAuthModule.class).setRequired(true))
+            
.add(createServiceDependency().setService(ConfigurationAdminGuiceModule.class, 
"("+ Constants.SERVICE_PID + "=" + ShindigService.SHINDIG_CONFIG_PID + ")")
+                .setRequired(true)));
+
         // Register the Shindig registration service
-        manager.add( 
-                createComponent()
-                .setImplementation(ShindigRegistrationServiceImpl.class)
-                .setInterface(new String[]{ResourceProvider.class.getName(), 
ShindigService.class.getName()}, null)
-                
.add(createServiceDependency().setService(LogService.class).setRequired(true))
-                
.add(createServiceDependency().setService(GuiceInjectorService.class).setRequired(true))
-                
.add(createServiceDependency().setService(SocialApiModule.class).setRequired(true))
-                
.add(createServiceDependency().setService(OAuthModule.class).setRequired(true))
-                .add(createServiceDependency()
-                        .setService(ConfigurationAdminGuiceModule.class, "("+ 
Constants.SERVICE_PID + "=" + ShindigService.SHINDIG_CONFIG_PID + ")")
-                        .setRequired(true))
+        manager.add(
+            createComponent()
+            .setImplementation(ShindigRegistrationServiceImpl.class)
+            .setInterface(new String[]{ResourceProvider.class.getName(), 
ShindigService.class.getName()}, null)
+            
.add(createServiceDependency().setService(LogService.class).setRequired(true))
+            
.add(createServiceDependency().setService(GuiceInjectorService.class).setRequired(true))
+            
.add(createServiceDependency().setService(SocialApiModule.class).setRequired(true))
+            
.add(createServiceDependency().setService(OAuthModule.class).setRequired(true))
+            .add(createServiceDependency()
+                .setService(ConfigurationAdminGuiceModule.class, "("+ 
Constants.SERVICE_PID + "=" + ShindigService.SHINDIG_CONFIG_PID + ")")
+                .setRequired(true))
                 
.add(createServiceDependency().setService(HttpContextServiceFactory.class).setRequired(true))
                 
.add(createServiceDependency().setService(HttpService.class).setRequired(true)));
-        
+
         // Create the configuration module
         Dictionary<String, Object> properties = new Hashtable<String, 
Object>();
-        properties.put("pattern", ".*");
+        properties.put("pattern", ShindigRegistrationServiceImpl.GADGETS_BASE+ 
 "/.*");
         properties.put(Constants.SERVICE_RANKING, 0);
         manager.add(
-                createComponent()
-                .setInterface(DispatchExtenderFilter.class.getName(), 
properties)
-                .setImplementation(TenantHostnameDispatchExtenderFilter.class)
-                
.add(createServiceDependency().setService(TenantManagementService.class).setRequired(true)));
        
+            createComponent()
+            .setInterface(DispatchExtenderFilter.class.getName(), properties)
+            .setImplementation(TenantHostnameDispatchExtenderFilter.class));
     }
 
     @Override

Modified: 
trunk/amdatu-opensocial/shindig/src/main/java/org/amdatu/opensocial/shindig/service/ShindigRegistrationServiceImpl.java
==============================================================================
--- 
trunk/amdatu-opensocial/shindig/src/main/java/org/amdatu/opensocial/shindig/service/ShindigRegistrationServiceImpl.java
     (original)
+++ 
trunk/amdatu-opensocial/shindig/src/main/java/org/amdatu/opensocial/shindig/service/ShindigRegistrationServiceImpl.java
     Mon Feb 14 10:15:17 2011
@@ -63,7 +63,7 @@
 public class ShindigRegistrationServiceImpl implements ShindigService, 
ResourceProvider {
 
     // Base URLs for filters, servlets and static resources
-    private static final String GADGETS_BASE = "/gadgets";
+    public static final String GADGETS_BASE = "/gadgets";
     private static final String GADGET_SERVLET_BASE = GADGETS_BASE + "/ifr";
     private static final String PROXY_BASE = GADGETS_BASE + "/proxy";
     private static final String MAKEREQUEST_BASE = GADGETS_BASE + 
"/makeRequest";

Modified: 
trunk/amdatu-opensocial/shindig/src/main/java/org/amdatu/opensocial/shindig/service/TenantHostnameDispatchExtenderFilter.java
==============================================================================
--- 
trunk/amdatu-opensocial/shindig/src/main/java/org/amdatu/opensocial/shindig/service/TenantHostnameDispatchExtenderFilter.java
       (original)
+++ 
trunk/amdatu-opensocial/shindig/src/main/java/org/amdatu/opensocial/shindig/service/TenantHostnameDispatchExtenderFilter.java
       Mon Feb 14 10:15:17 2011
@@ -1,20 +1,16 @@
 package org.amdatu.opensocial.shindig.service;
 
 import java.io.IOException;
-import java.util.List;
 
 import javax.servlet.FilterChain;
 import javax.servlet.FilterConfig;
 import javax.servlet.ServletException;
 import javax.servlet.ServletRequest;
 import javax.servlet.ServletResponse;
-import javax.servlet.http.HttpServletRequest;
 
 import org.amdatu.core.tenant.Tenant;
-import org.amdatu.core.tenant.TenantEntity;
-import org.amdatu.core.tenant.TenantException;
-import org.amdatu.core.tenant.TenantManagementService;
 import org.amdatu.web.dispatcher.DispatchExtenderFilter;
+import 
org.amdatu.web.tenantresolver.hostname.service.HostnameTenantResolverExtenderFilter;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.InvalidSyntaxException;
 import org.osgi.framework.ServiceReference;
@@ -22,74 +18,62 @@
 
 /**
  * This tenant dispatch extender filter is registered on .* and captures all 
HTTP requests to resolve the
- * tenant from the hostname of the request. It stores the tenant for the 
lifetime of that request on a 
- * ThreadLocal so that the PersonServiceImpl can retrieve the tenant from this 
ThreadLocal. Note that 
+ * tenant from the hostname of the request. It stores the tenant for the 
lifetime of that request on a
+ * ThreadLocal so that the PersonServiceImpl can retrieve the tenant from this 
ThreadLocal. Note that
  * the CassandraAppDataServiceStore is not tenant aware, nor does it have 
access to the HTTP request.
  * 
  * @author ivol
  */
 public class TenantHostnameDispatchExtenderFilter implements 
DispatchExtenderFilter {
-       // Service dependencies, injected by the framework
-       private volatile TenantManagementService m_tenantManagementService;
-       private static volatile BundleContext m_bundleContext;
-
-       // Tenant context information is bound to a ThreadLocal variable.
-       private static ThreadLocal<Tenant> m_properties = null;
-
-       public void init(FilterConfig filterConfig) throws ServletException {
-               // Create the threadlocal
-               m_properties = new ThreadLocal<Tenant>();
-       }
-
-       public void doFilter(ServletRequest request, ServletResponse response, 
FilterChain chain) throws IOException, ServletException {
-               HttpServletRequest httpServletRequest = (HttpServletRequest) 
request;
-               String serverName = httpServletRequest.getServerName();
-               if (serverName != null) {
-                       try {
-                               List<TenantEntity> tenants = 
m_tenantManagementService.getTenants();
-                               for (TenantEntity tenant : tenants) {
-                                       if 
(serverName.equals(tenant.getProperties().get(Tenant.HOSTNAME_PROPERTY))) {
-                                               // The servername of the 
request matches the hostname of this tenant so
-                                               // set the tenant on the 
threadlocal variable
-                                               m_properties.set(tenant);
-                                       }       
-                               }
-                       }
-                       catch (TenantException e) {}
-               }
-
-               chain.doFilter(request, response);
-
-               // Set the tenant to null
-               m_properties.set(null);
-       }
-
-       public void destroy() {
-               // Destroy the threadlocal
-               m_properties = null;
-       }
-
-       /**
-        * Returns the tenant on the ThreadLocal.
-        * @return the current tenant
-        */
-       public static Tenant getTenant() {
-               return m_properties.get();
-       }
-
-       /**
-        * Returns the UserAdmin service that is associated with the current 
tenant.
-        * @return the UserAdmin service that is associated with the current 
tenant.
-        * @throws InvalidSyntaxException In case the UserAdmin service 
references could not be retrieved.
-        */
-       public static UserAdmin getUserAdmin() throws InvalidSyntaxException {
-               Tenant tenant = getTenant();
-               ServiceReference[] refs = 
m_bundleContext.getAllServiceReferences(UserAdmin.class.getName(), null);
-               for (ServiceReference ref : refs) {
-                       if 
(tenant.getId().equals(ref.getProperty(Tenant.TENANT_ID_SERVICEPROPERTY))) {
-                               return (UserAdmin) 
m_bundleContext.getService(ref);
-                       }
-               }
-               return null;
-       }
+    // Service dependencies, injected by the framework
+    private static volatile BundleContext m_bundleContext;
+
+    // Tenant context information is bound to a ThreadLocal variable.
+    private static ThreadLocal<Tenant> m_properties = null;
+
+    public void init(FilterConfig filterConfig) throws ServletException {
+        // Create the threadlocal
+        m_properties = new ThreadLocal<Tenant>();
+    }
+
+    public void doFilter(ServletRequest request, ServletResponse response, 
FilterChain chain) throws IOException, ServletException {
+        Object tenant = 
request.getAttribute(HostnameTenantResolverExtenderFilter.TENANT_REQUESTCONTEXT_KEY);
+        if (tenant != null && tenant instanceof Tenant) {
+            m_properties.set((Tenant) tenant);
+        }
+
+        chain.doFilter(request, response);
+
+        // Set the tenant to null
+        m_properties.set(null);
+    }
+
+    public void destroy() {
+        // Destroy the threadlocal
+        m_properties = null;
+    }
+
+    /**
+     * Returns the tenant on the ThreadLocal.
+     * @return the current tenant
+     */
+    public static Tenant getTenant() {
+        return m_properties.get();
+    }
+
+    /**
+     * Returns the UserAdmin service that is associated with the current 
tenant.
+     * @return the UserAdmin service that is associated with the current 
tenant.
+     * @throws InvalidSyntaxException In case the UserAdmin service references 
could not be retrieved.
+     */
+    public static UserAdmin getUserAdmin() throws InvalidSyntaxException {
+        Tenant tenant = getTenant();
+        ServiceReference[] refs = 
m_bundleContext.getAllServiceReferences(UserAdmin.class.getName(), null);
+        for (ServiceReference ref : refs) {
+            if 
(tenant.getId().equals(ref.getProperty(Tenant.TENANT_ID_SERVICEPROPERTY))) {
+                return (UserAdmin) m_bundleContext.getService(ref);
+            }
+        }
+        return null;
+    }
 }

Modified: 
trunk/amdatu-web/tenantresolver-hostname/src/main/java/org/amdatu/web/tenantresolver/hostname/osgi/HostnameTenantResolverActivator.java
==============================================================================
--- 
trunk/amdatu-web/tenantresolver-hostname/src/main/java/org/amdatu/web/tenantresolver/hostname/osgi/HostnameTenantResolverActivator.java
     (original)
+++ 
trunk/amdatu-web/tenantresolver-hostname/src/main/java/org/amdatu/web/tenantresolver/hostname/osgi/HostnameTenantResolverActivator.java
     Mon Feb 14 10:15:17 2011
@@ -35,16 +35,16 @@
     public void init(BundleContext context, DependencyManager manager) throws 
Exception {
 
         Dictionary<String, Object> thProperties = new Hashtable<String, 
Object>();
-        thProperties.put(Constants.SERVICE_RANKING, 0);
+        thProperties.put(Constants.SERVICE_RANKING, 1000);
         thProperties.put(DispatcherService.PATTERN_KEY, ".*");
         manager.add(
-                createComponent()
-                    .setInterface(DispatchExtenderFilter.class.getName(), 
thProperties)
-                    
.setImplementation(HostnameTenantResolverExtenderFilter.class)
-                    // Guards filter lifecycle
-                    
.add(createServiceDependency().setService(DispatcherService.class).setRequired(true))
-                    
.add(createServiceDependency().setService(TenantManagementService.class).setRequired(true))
-                    
.add(createServiceDependency().setService(LogService.class).setRequired(true)));
+            createComponent()
+            .setInterface(DispatchExtenderFilter.class.getName(), thProperties)
+            .setImplementation(HostnameTenantResolverExtenderFilter.class)
+            // Guards filter lifecycle
+            
.add(createServiceDependency().setService(DispatcherService.class).setRequired(true))
+            
.add(createServiceDependency().setService(TenantManagementService.class).setRequired(true))
+            
.add(createServiceDependency().setService(LogService.class).setRequired(true)));
     }
 
     @Override

Reply via email to