[gatein-commits] gatein SVN: r7931 - in epp/portal/branches/EPP_5_2_Branch: web/portal/src/main/webapp/groovy/portal/webui/application and 2 other directories.

do-not-reply at jboss.org do-not-reply at jboss.org
Wed Nov 2 09:41:48 EDT 2011


Author: theute
Date: 2011-11-02 09:41:46 -0400 (Wed, 02 Nov 2011)
New Revision: 7931

Modified:
   epp/portal/branches/EPP_5_2_Branch/portlet/dashboard/src/main/webapp/groovy/gadget/webui/component/UIGadgetViewMode.gtmpl
   epp/portal/branches/EPP_5_2_Branch/web/portal/src/main/webapp/groovy/portal/webui/application/UIGadget.gtmpl
   epp/portal/branches/EPP_5_2_Branch/webui/portal/src/main/java/org/exoplatform/portal/webui/application/GadgetUtil.java
   epp/portal/branches/EPP_5_2_Branch/webui/portal/src/main/java/org/exoplatform/portal/webui/login/UIForgetPassword.java
Log:
JBEPP-1331: Problem with gadgets when the host name includes the word "portal"

Modified: epp/portal/branches/EPP_5_2_Branch/portlet/dashboard/src/main/webapp/groovy/gadget/webui/component/UIGadgetViewMode.gtmpl
===================================================================
--- epp/portal/branches/EPP_5_2_Branch/portlet/dashboard/src/main/webapp/groovy/gadget/webui/component/UIGadgetViewMode.gtmpl	2011-11-02 13:05:00 UTC (rev 7930)
+++ epp/portal/branches/EPP_5_2_Branch/portlet/dashboard/src/main/webapp/groovy/gadget/webui/component/UIGadgetViewMode.gtmpl	2011-11-02 13:41:46 UTC (rev 7931)
@@ -4,7 +4,7 @@
 	import org.exoplatform.portal.webui.application.GadgetUtil;
 	import org.exoplatform.webui.application.portlet.PortletRequestContext;
 	
-	def hostName = GadgetUtil.getRelGadgetServerUrl();
+	def hostName = GadgetUtil.getGadgetServerUrl();
 	def rcontext = _ctx.getRequestContext() ;
 	def windowId = rcontext.getWindowId();
 	def id = uicomponent.getId() + "-" + windowId ;

Modified: epp/portal/branches/EPP_5_2_Branch/web/portal/src/main/webapp/groovy/portal/webui/application/UIGadget.gtmpl
===================================================================
--- epp/portal/branches/EPP_5_2_Branch/web/portal/src/main/webapp/groovy/portal/webui/application/UIGadget.gtmpl	2011-11-02 13:05:00 UTC (rev 7930)
+++ epp/portal/branches/EPP_5_2_Branch/web/portal/src/main/webapp/groovy/portal/webui/application/UIGadget.gtmpl	2011-11-02 13:41:46 UTC (rev 7931)
@@ -4,7 +4,7 @@
 	
     def rcontext = _ctx.getRequestContext();
     JavascriptManager jsmanager = rcontext.getJavascriptManager();
-    def hostName = GadgetUtil.getRelGadgetServerUrl();
+    def hostName = GadgetUtil.getGadgetServerUrl();
     def url = null;
     def metadata = "";
     def posX = uicomponent.getProperties().getIntValue("locationX") + "px";

Modified: epp/portal/branches/EPP_5_2_Branch/webui/portal/src/main/java/org/exoplatform/portal/webui/application/GadgetUtil.java
===================================================================
--- epp/portal/branches/EPP_5_2_Branch/webui/portal/src/main/java/org/exoplatform/portal/webui/application/GadgetUtil.java	2011-11-02 13:05:00 UTC (rev 7930)
+++ epp/portal/branches/EPP_5_2_Branch/webui/portal/src/main/java/org/exoplatform/portal/webui/application/GadgetUtil.java	2011-11-02 13:41:46 UTC (rev 7931)
@@ -40,6 +40,8 @@
 import java.util.Iterator;
 import java.util.Map;
 
+import javax.servlet.http.HttpServletRequest;
+
 /**
  * Created by The eXo Platform SAS Author : Pham Thanh Tung
  * thanhtungty at gmail.com Oct 2, 2008
@@ -200,84 +202,46 @@
       return getLocalHostBase() + "/" + PortalContainer.getCurrentRestContextName() + "/private/" + uri;
    }
 
-   //  TODO: TanPham:Replace by getGadgetServerUrl to make server url
-   //  static private String getHostBase() {
-   //    String hostName = getHostName();
-   //    URL url = null;
-   //    try {
-   //       url = new URL(hostName);
-   //    } catch (Exception e) {}
-   //    if(url == null) return hostName ;
-   //    int index = hostName.indexOf(url.getPath()) ;
-   //    if(index < 1) return hostName ;
-   //    return hostName.substring(0, index) ;
-   //  }
+   /**
+    * Make full URL of gadget server
+    * @return URL String
+    */
    public static String getGadgetServerUrl()
    {
-      String hostName = getHostName();
+      String uriString = getGadgetServerURI();
       try
       {
-         new URL(hostName);
+         new URL(uriString);
       }
       catch (Exception e)
       {
-         try
-         {
-            String newHostName = getLocalHostName() + "/" + hostName;
-            new URL(newHostName);
-            hostName = newHostName;
-         }
-         catch (Exception e2)
-         {
-         }
+         return getLocalHostBase() + (uriString.startsWith("/") ? uriString : ("/" + uriString));
       }
-      return hostName;
+      return uriString;
    }
 
-   //  TODO: Using in gtmpl templates
+   /**
+    * See getGadgetServerUrl()
+    * @return URL String
+    */
+   @Deprecated
    public static String getRelGadgetServerUrl()
    {
-      String url = getGadgetServerUrl();
-      String localHostBase = getLocalHostBase();
-      int index = url.indexOf(localHostBase);
-      if (index >= 0)
-         return url.substring(index + localHostBase.length());
-      return url;
+      return getGadgetServerUrl();
    }
 
-   static private String getLocalHostBase()
+   static private String getGadgetServerURI()
    {
-      String hostName = getLocalHostName();
-      URL url = null;
-      try
-      {
-         url = new URL(hostName);
-      }
-      catch (Exception e)
-      {
-      }
-      if (url == null)
-         return hostName;
-      int index = hostName.indexOf(url.getPath());
-      if (index < 1)
-         return hostName;
-      return hostName.substring(0, index);
-   }
-
-   static private String getHostName()
-   {
       ExoContainer container = ExoContainerContext.getCurrentContainer();
       GadgetRegistryService gadgetService =
          (GadgetRegistryService)container.getComponentInstanceOfType(GadgetRegistryService.class);
       return gadgetService.getHostName();
    }
 
-   static private String getLocalHostName()
+   static private String getLocalHostBase()
    {
-      PortalRequestContext pContext = Util.getPortalRequestContext();
-      StringBuffer requestUrl = pContext.getRequest().getRequestURL();
-      int index = requestUrl.indexOf(pContext.getRequestContextPath());
-      return requestUrl.substring(0, index);
+      HttpServletRequest request = Util.getPortalRequestContext().getRequest();
+      return request.getScheme() + "://" + request.getServerName() + ((request.getServerPort() != 80) ? ":" + request.getServerPort() : "");
    }
 
 }

Modified: epp/portal/branches/EPP_5_2_Branch/webui/portal/src/main/java/org/exoplatform/portal/webui/login/UIForgetPassword.java
===================================================================
--- epp/portal/branches/EPP_5_2_Branch/webui/portal/src/main/java/org/exoplatform/portal/webui/login/UIForgetPassword.java	2011-11-02 13:05:00 UTC (rev 7930)
+++ epp/portal/branches/EPP_5_2_Branch/webui/portal/src/main/java/org/exoplatform/portal/webui/login/UIForgetPassword.java	2011-11-02 13:41:46 UTC (rev 7931)
@@ -45,6 +45,8 @@
 import java.util.MissingResourceException;
 import java.util.ResourceBundle;
 
+import javax.servlet.http.HttpServletRequest;
+
 /**
  * Created by The eXo Platform SARL
  * Author : dang.tung
@@ -75,7 +77,6 @@
          UILogin uilogin = uiForm.getParent();
          WebuiRequestContext requestContext = event.getRequestContext();
          PortalRequestContext portalContext = PortalRequestContext.getCurrentInstance();
-         String url = portalContext.getRequest().getRequestURL().toString();
          MailService mailSrc = uiForm.getApplicationComponent(MailService.class);
          OrganizationService orgSrc = uiForm.getApplicationComponent(OrganizationService.class);
          String userName = uiForm.getUIStringInput(Username).getValue();
@@ -141,7 +142,8 @@
          {
             e.printStackTrace();
          }
-         String host = url.substring(0, url.indexOf(requestContext.getRequestContextPath()));
+         HttpServletRequest request = portalContext.getRequest();
+         String host = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort();
          String activeLink = host + requestContext.getRequestContextPath() + "/public/" + portalName
         	 		+ "?portal:componentId=UIPortal&portal:action=RecoveryPasswordAndUsername&tokenId=" 
         	 		+ tokenId;



More information about the gatein-commits mailing list