You are viewing a plain text version of this content. The canonical link for it is here.
Posted to portalapps-dev@portals.apache.org by wo...@apache.org on 2009/09/29 16:14:01 UTC

svn commit: r819959 - in /portals/applications/webcontent/trunk: webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/portlet/ webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/proxy/ webcontent-jar/src/main/jav...

Author: woonsan
Date: Tue Sep 29 14:14:00 2009
New Revision: 819959

URL: http://svn.apache.org/viewvc?rev=819959&view=rev
Log:
APA-17: Adds variable expanding feature, allowing ${serverName}, ${serverPort} and ${contextPath} for SRC, PROXYREMOTEURL, PROXYLOCALPATH preference values, in order to make it easy to set local server paths.
Also, changes the argument type of siteURI from URI to String.

Modified:
    portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/portlet/IFrameGenericPortlet.java
    portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/proxy/SSOSiteCredentialsProvider.java
    portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/proxy/impl/RewritableHttpReverseProxyServiceImpl.java
    portals/applications/webcontent/trunk/webcontent-war/src/main/webapp/WEB-INF/conf/reverseproxy.properties
    portals/applications/webcontent/trunk/webcontent-war/src/main/webapp/WEB-INF/portlet.xml

Modified: portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/portlet/IFrameGenericPortlet.java
URL: http://svn.apache.org/viewvc/portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/portlet/IFrameGenericPortlet.java?rev=819959&r1=819958&r2=819959&view=diff
==============================================================================
--- portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/portlet/IFrameGenericPortlet.java (original)
+++ portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/portlet/IFrameGenericPortlet.java Tue Sep 29 14:14:00 2009
@@ -55,6 +55,8 @@
     
     public static final String IFRAME_SRC_URL = "org.apache.portals.applications.webcontent.portlet.iframe.src";
     
+    public static final String [] SRC_REPLACE_KEYS = { "${serverName}", "${serverPort}", "${contextPath}" };
+    
     private Map<String, String> attributes = new HashMap<String, String>();
 
     private Map<String, String> maxAttributes = new HashMap<String, String>();
@@ -305,34 +307,25 @@
 
     public String getURLSource(RenderRequest request, RenderResponse response, PortletPreferences prefs)
     {
+        String [] srcReplaceValues = { request.getServerName(), Integer.toString(request.getServerPort()), request.getContextPath() };
+        
         String source = (String) PortletMessaging.receive(request, IFRAME_SRC_URL);
         
         if (source == null)
         {
-            source = getAttributePreference(prefs, "SRC");
+            source = StringUtils.replaceEach(getAttributePreference(prefs, "SRC"), SRC_REPLACE_KEYS, srcReplaceValues);
         }
         
         // Sometimes, iframe's SRC attribute can be set to a local url to allow cross-domain scripting.
         // If proxy remote URL and its corresponding local path are set, then the proxy remote URL prefix
         // should be replaced by the local path.
         
-        String proxyRemoteURL = getAttributePreference(prefs, "PROXYREMOTEURL");
-        String proxyLocalPath = getAttributePreference(prefs, "PROXYLOCALPATH");
+        String proxyRemoteURL = StringUtils.replaceEach(getAttributePreference(prefs, "PROXYREMOTEURL"), SRC_REPLACE_KEYS, srcReplaceValues);
+        String proxyLocalPath = StringUtils.replaceEach(getAttributePreference(prefs, "PROXYLOCALPATH"), SRC_REPLACE_KEYS, srcReplaceValues);
         
-        if (source == null)
-        {
-            source = "";
-        }
-        else if (StringUtils.isNotEmpty(proxyRemoteURL) && StringUtils.isNotEmpty(proxyLocalPath) && source.startsWith(proxyRemoteURL))
+        if (StringUtils.isNotEmpty(proxyRemoteURL) && StringUtils.isNotEmpty(proxyLocalPath) && StringUtils.startsWith(source, proxyRemoteURL))
         {
-            if (proxyLocalPath.startsWith("/"))
-            {
-                source = proxyLocalPath + source.substring(proxyRemoteURL.length());
-            }
-            else
-            {
-                source = request.getContextPath() + "/" + proxyLocalPath + source.substring(proxyRemoteURL.length());
-            }
+            source = proxyLocalPath + source.substring(proxyRemoteURL.length());
         }
         
         return source;

Modified: portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/proxy/SSOSiteCredentialsProvider.java
URL: http://svn.apache.org/viewvc/portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/proxy/SSOSiteCredentialsProvider.java?rev=819959&r1=819958&r2=819959&view=diff
==============================================================================
--- portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/proxy/SSOSiteCredentialsProvider.java (original)
+++ portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/proxy/SSOSiteCredentialsProvider.java Tue Sep 29 14:14:00 2009
@@ -24,6 +24,6 @@
 public interface SSOSiteCredentialsProvider
 {
     
-    public List<SSOSiteCredentials> getSSOCredentials(HttpServletRequest request, URI siteURI);
+    public List<SSOSiteCredentials> getSSOCredentials(HttpServletRequest request, String siteURL);
     
 }

Modified: portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/proxy/impl/RewritableHttpReverseProxyServiceImpl.java
URL: http://svn.apache.org/viewvc/portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/proxy/impl/RewritableHttpReverseProxyServiceImpl.java?rev=819959&r1=819958&r2=819959&view=diff
==============================================================================
--- portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/proxy/impl/RewritableHttpReverseProxyServiceImpl.java (original)
+++ portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/proxy/impl/RewritableHttpReverseProxyServiceImpl.java Tue Sep 29 14:14:00 2009
@@ -23,7 +23,6 @@
 import java.io.OutputStreamWriter;
 import java.io.Reader;
 import java.io.Writer;
-import java.net.URI;
 import java.util.ArrayList;
 import java.util.Enumeration;
 import java.util.List;
@@ -195,7 +194,7 @@
         
         if (localBaseURL == null)
         {
-            localBaseURL = request.getScheme() + "://" + hostHeaderValue + request.getServletPath();
+            localBaseURL = request.getScheme() + "://" + hostHeaderValue + request.getContextPath() + request.getServletPath();
         }
         
         String proxyTargetURL = proxyPathMapper.getRemoteURL(pathInfo);
@@ -242,7 +241,7 @@
         {
             SSOSiteCredentials firstCreds = credsList.get(0);
             
-            if (firstCreds.isFormAuthentication() && areSameURLPaths(firstCreds.getBaseURL(), proxyTargetURL))
+            if (firstCreds.isFormAuthentication() && StringUtils.equals(firstCreds.getBaseURL(), proxyTargetURL))
             {
                 httpRequest = new HttpPost(proxyTargetURL);
                 List <NameValuePair> formParams = new ArrayList<NameValuePair>();
@@ -536,19 +535,9 @@
         }
         else
         {
-            return credsProvider.getSSOCredentials(request, URI.create(siteURL));
+            return credsProvider.getSSOCredentials(request, siteURL);
         }
     }
     
-    private boolean areSameURLPaths(String url1, String url2)
-    {
-        if (url1 != null && url2 != null)
-        {
-            return StringUtils.removeEnd(url1, "/").equals(StringUtils.removeEnd(url2, "/"));
-        }
-        
-        return false;
-    }
-    
 }
 

Modified: portals/applications/webcontent/trunk/webcontent-war/src/main/webapp/WEB-INF/conf/reverseproxy.properties
URL: http://svn.apache.org/viewvc/portals/applications/webcontent/trunk/webcontent-war/src/main/webapp/WEB-INF/conf/reverseproxy.properties?rev=819959&r1=819958&r2=819959&view=diff
==============================================================================
--- portals/applications/webcontent/trunk/webcontent-war/src/main/webapp/WEB-INF/conf/reverseproxy.properties (original)
+++ portals/applications/webcontent/trunk/webcontent-war/src/main/webapp/WEB-INF/conf/reverseproxy.properties Tue Sep 29 14:14:00 2009
@@ -80,7 +80,7 @@
 
 # Proxy Pass Reverse Mapping configurations for each category
 # ... Put the path item names here. Each path item will be evaluated by the order. 
-proxy.reverse.pass = apache, portals, somewhere 
+proxy.reverse.pass = apache, portals, localhost, somewhere 
 
 # ... Sets detail attributes for each path item.
 
@@ -90,6 +90,10 @@
 proxy.reverse.pass.portals.local = /portals/
 proxy.reverse.pass.portals.remote = http://portals.apache.org/
 
+proxy.reverse.pass.localhost.local = /localhost/
+proxy.reverse.pass.localhost.remote = http://localhost:8080/
+
+# ... 'somewhere' is just an example to show the full configurable items...
 proxy.reverse.pass.somewhere.local = /somewhere/
 proxy.reverse.pass.somewhere.remote = http://somewhere.localhost.com/
 proxy.reverse.pass.somewhere.rewriters = ${defaults.htmlRewriter}, ${defaults.xmlRewriter} 

Modified: portals/applications/webcontent/trunk/webcontent-war/src/main/webapp/WEB-INF/portlet.xml
URL: http://svn.apache.org/viewvc/portals/applications/webcontent/trunk/webcontent-war/src/main/webapp/WEB-INF/portlet.xml?rev=819959&r1=819958&r2=819959&view=diff
==============================================================================
--- portals/applications/webcontent/trunk/webcontent-war/src/main/webapp/WEB-INF/portlet.xml (original)
+++ portals/applications/webcontent/trunk/webcontent-war/src/main/webapp/WEB-INF/portlet.xml Tue Sep 29 14:14:00 2009
@@ -139,7 +139,7 @@
       </preference>
       <preference>
         <name>PROXYLOCALPATH</name>
-        <value>rproxy/portals/</value>
+        <value>${contextPath}/rproxy/portals/</value>
       </preference>
       <preference>
         <name>AUTORESIZE</name>