Author: [email protected]
Date: Wed May  9 11:38:09 2012
New Revision: 2327

Log:
[AMDATUOPENSOCIAL-209] Multi tenant fixes

Modified:
   
trunk/amdatu-opensocial/opensocial-shindig/src/main/java/org/amdatu/opensocial/shindig/service/MultiTenantContainerConfig.java
   
trunk/amdatu-opensocial/opensocial-shindig/src/main/java/org/amdatu/opensocial/shindig/service/ShindigDispatchExtenderFilter.java
   
trunk/amdatu-opensocial/test-performance/test-bundle/src/main/java/org/amdatu/opensocial/test/performance/osgi/Activator.java

Modified: 
trunk/amdatu-opensocial/opensocial-shindig/src/main/java/org/amdatu/opensocial/shindig/service/MultiTenantContainerConfig.java
==============================================================================
--- 
trunk/amdatu-opensocial/opensocial-shindig/src/main/java/org/amdatu/opensocial/shindig/service/MultiTenantContainerConfig.java
      (original)
+++ 
trunk/amdatu-opensocial/opensocial-shindig/src/main/java/org/amdatu/opensocial/shindig/service/MultiTenantContainerConfig.java
      Wed May  9 11:38:09 2012
@@ -54,11 +54,11 @@
         Object value = super.getProperty(container, property);
 
         if (value instanceof String && ((String) 
value).indexOf("%tenant_host%") != -1) {
-            Tenant tenant = ShindigDispatchExtenderFilter.getTenant();
+            // NB: the host of the tenant is just the current hostname
+            String hostname = ShindigDispatchExtenderFilter.getHostname();
             String replacement;
-            if (tenant != null) {
-                // FIXME: how can we retrieve the hostname associated with a 
tenant?
-                replacement = "localhost";
+            if (hostname != null) {
+                replacement = hostname;
             }
             else {
                 replacement = m_host;

Modified: 
trunk/amdatu-opensocial/opensocial-shindig/src/main/java/org/amdatu/opensocial/shindig/service/ShindigDispatchExtenderFilter.java
==============================================================================
--- 
trunk/amdatu-opensocial/opensocial-shindig/src/main/java/org/amdatu/opensocial/shindig/service/ShindigDispatchExtenderFilter.java
   (original)
+++ 
trunk/amdatu-opensocial/opensocial-shindig/src/main/java/org/amdatu/opensocial/shindig/service/ShindigDispatchExtenderFilter.java
   Wed May  9 11:38:09 2012
@@ -54,11 +54,13 @@
 
     // Tenant context information is bound to a ThreadLocal variable.
     private ThreadLocal<Tenant> m_tenant = null;
+    private ThreadLocal<String> m_hostname = null;
     private ThreadLocal<String> m_user = null;
 
     public void init(final FilterConfig filterConfig) throws ServletException {
         // Create the thread local
         m_tenant = new ThreadLocal<Tenant>();
+        m_hostname = new ThreadLocal<String>();
         m_user = new ThreadLocal<String>();
         INSTANCE = this;
     }
@@ -70,6 +72,9 @@
     public void doFilter(final ServletRequest request, final ServletResponse 
response, final FilterChain chain)
         throws IOException, ServletException {
         try {
+            // Set the hostname of the Thread local
+            m_hostname.set(request.getServerName());
+
             Object tenant = 
request.getAttribute(org.amdatu.web.dispatcher.Constants.TENANT_REQUESTCONTEXT_KEY);
             if (tenant != null && tenant instanceof Tenant) {
                 m_tenant.set((Tenant) tenant);
@@ -92,8 +97,10 @@
         }
         finally {
 
-            // Set the tenant to null
+            // Reset all
             m_tenant.set(null);
+            m_hostname.set(null);
+            m_user.set(null);
         }
     }
 
@@ -134,6 +141,10 @@
         return m_tenant;
     }
 
+    private ThreadLocal<String> internalGetHostname() {
+        return m_hostname;
+    }
+
     private ThreadLocal<String> internalGetUser() {
         return m_user;
     }
@@ -176,6 +187,18 @@
     }
 
     /**
+     * Returns the hostname of the ThreadLocal.
+     * 
+     * @return the current hostname
+     */
+    public static String getHostname() {
+        if (getInstance() != null) {
+            return getInstance().internalGetHostname().get();
+        }
+        return null;
+    }
+
+    /**
      * Returns the UserAdmin service that is associated with the current 
tenant.
      * 
      * @return the UserAdmin service that is associated with the current 
tenant.

Modified: 
trunk/amdatu-opensocial/test-performance/test-bundle/src/main/java/org/amdatu/opensocial/test/performance/osgi/Activator.java
==============================================================================
--- 
trunk/amdatu-opensocial/test-performance/test-bundle/src/main/java/org/amdatu/opensocial/test/performance/osgi/Activator.java
       (original)
+++ 
trunk/amdatu-opensocial/test-performance/test-bundle/src/main/java/org/amdatu/opensocial/test/performance/osgi/Activator.java
       Wed May  9 11:38:09 2012
@@ -15,7 +15,7 @@
  */
 package org.amdatu.opensocial.test.performance.osgi;
 
-import org.amdatu.libraries.utilities.osgi.ServiceDependentActivator;
+import org.amdatu.libraries.osgi.ServiceDependentActivator;
 import org.amdatu.opensocial.test.performance.service.RESTPerformanceTest;
 import org.amdatu.web.httpcontext.ResourceProvider;
 import org.amdatu.web.rest.jaxrs.JaxRsSpi;
_______________________________________________
Amdatu-commits mailing list
[email protected]
http://lists.amdatu.org/mailman/listinfo/amdatu-commits

Reply via email to