portals-portalapps-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From woon...@apache.org
Subject svn commit: r820042 - in /portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/proxy: ./ impl/
Date Tue, 29 Sep 2009 17:50:19 GMT
Author: woonsan
Date: Tue Sep 29 17:50:18 2009
New Revision: 820042

URL: http://svn.apache.org/viewvc?rev=820042&view=rev
Log:
APA-17: Changes to create new instance of rewriter every time because rewriter is not designed
to be shared.

Modified:
    portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/proxy/HttpReverseProxyPathMapperProvider.java
    portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/proxy/SSOSiteCredentials.java
    portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/proxy/impl/DefaultHttpReverseProxyPathMapperProviderImpl.java
    portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/proxy/impl/DefaultHttpReverseProxyServlet.java
    portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/proxy/impl/DefaultSSOSiteCredentials.java
    portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/proxy/impl/RewritableHttpReverseProxyServiceImpl.java

Modified: portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/proxy/HttpReverseProxyPathMapperProvider.java
URL: http://svn.apache.org/viewvc/portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/proxy/HttpReverseProxyPathMapperProvider.java?rev=820042&r1=820041&r2=820042&view=diff
==============================================================================
--- portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/proxy/HttpReverseProxyPathMapperProvider.java
(original)
+++ portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/proxy/HttpReverseProxyPathMapperProvider.java
Tue Sep 29 17:50:18 2009
@@ -18,8 +18,8 @@
 
 import javax.servlet.http.HttpServletRequest;
 
-import org.apache.portals.applications.webcontent.rewriter.Rewriter;
 import org.apache.portals.applications.webcontent.rewriter.RewriterController;
+import org.apache.portals.applications.webcontent.rewriter.rules.Ruleset;
 
 /**
  * proxy path mapper provider interface for http reverse proxy service.
@@ -48,9 +48,9 @@
     public RewriterController findRewriterController(HttpServletRequest request);
     
     /**
-     * Finds a reverse proxy rewriter based on the request
+     * Finds a reverse proxy rewriter rules based on the request
      * @return
      */
-    public Rewriter findRewriter(HttpServletRequest request);
+    public Ruleset findRewriterRuleset(HttpServletRequest request);
     
 }
\ No newline at end of file

Modified: portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/proxy/SSOSiteCredentials.java
URL: http://svn.apache.org/viewvc/portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/proxy/SSOSiteCredentials.java?rev=820042&r1=820041&r2=820042&view=diff
==============================================================================
--- portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/proxy/SSOSiteCredentials.java
(original)
+++ portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/proxy/SSOSiteCredentials.java
Tue Sep 29 17:50:18 2009
@@ -16,7 +16,9 @@
  */
 package org.apache.portals.applications.webcontent.proxy;
 
-public interface SSOSiteCredentials
+import java.io.Serializable;
+
+public interface SSOSiteCredentials extends Serializable
 {
     
     public String getBaseURL();

Modified: portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/proxy/impl/DefaultHttpReverseProxyPathMapperProviderImpl.java
URL: http://svn.apache.org/viewvc/portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/proxy/impl/DefaultHttpReverseProxyPathMapperProviderImpl.java?rev=820042&r1=820041&r2=820042&view=diff
==============================================================================
--- portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/proxy/impl/DefaultHttpReverseProxyPathMapperProviderImpl.java
(original)
+++ portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/proxy/impl/DefaultHttpReverseProxyPathMapperProviderImpl.java
Tue Sep 29 17:50:18 2009
@@ -24,8 +24,8 @@
 import org.apache.commons.lang.StringUtils;
 import org.apache.portals.applications.webcontent.proxy.HttpReverseProxyPathMapper;
 import org.apache.portals.applications.webcontent.proxy.HttpReverseProxyPathMapperProvider;
-import org.apache.portals.applications.webcontent.rewriter.Rewriter;
 import org.apache.portals.applications.webcontent.rewriter.RewriterController;
+import org.apache.portals.applications.webcontent.rewriter.rules.Ruleset;
 
 /**
  * Default <CODE>HttpReverseProxyPathMapperProvider</CODE> implementation
@@ -46,17 +46,17 @@
     private List<KeyValue> rewriterControllerPairs;
     
     /**
-     * rewriters
+     * rewriter rulesets
      */
-    private List<KeyValue> rewriterPairs;
+    private List<KeyValue> rewriterRulesetPairs;
     
     public DefaultHttpReverseProxyPathMapperProviderImpl(List<HttpReverseProxyPathMapper>
proxyPathMappers, 
                                                          List<KeyValue> rewriterControllerPairs,
-                                                         List<KeyValue> rewriterPairs)
+                                                         List<KeyValue> rewriterRulesetPairs)
     {
         this.proxyPathMappers = proxyPathMappers;
         this.rewriterControllerPairs = rewriterControllerPairs;
-        this.rewriterPairs = rewriterPairs;
+        this.rewriterRulesetPairs = rewriterRulesetPairs;
     }
     
     public HttpReverseProxyPathMapper findMapper(HttpServletRequest request)
@@ -105,15 +105,15 @@
         return null;
     }
     
-    public Rewriter findRewriter(HttpServletRequest request)
+    public Ruleset findRewriterRuleset(HttpServletRequest request)
     {
         String pathInfo = request.getPathInfo();
         
-        for (KeyValue pair : rewriterPairs)
+        for (KeyValue pair : rewriterRulesetPairs)
         {
             if (StringUtils.startsWith(pathInfo, (String) pair.getKey()))
             {
-                return (Rewriter) pair.getValue();
+                return (Ruleset) pair.getValue();
             }
         }
         

Modified: portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/proxy/impl/DefaultHttpReverseProxyServlet.java
URL: http://svn.apache.org/viewvc/portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/proxy/impl/DefaultHttpReverseProxyServlet.java?rev=820042&r1=820041&r2=820042&view=diff
==============================================================================
--- portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/proxy/impl/DefaultHttpReverseProxyServlet.java
(original)
+++ portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/proxy/impl/DefaultHttpReverseProxyServlet.java
Tue Sep 29 17:50:18 2009
@@ -16,6 +16,7 @@
  */
 package org.apache.portals.applications.webcontent.proxy.impl;
 
+import java.io.BufferedInputStream;
 import java.io.File;
 import java.io.IOException;
 import java.io.InputStream;
@@ -54,8 +55,8 @@
 import org.apache.portals.applications.webcontent.proxy.HttpReverseProxyPathMapperProvider;
 import org.apache.portals.applications.webcontent.proxy.HttpReverseProxyService;
 import org.apache.portals.applications.webcontent.rewriter.MappingRewriterController;
-import org.apache.portals.applications.webcontent.rewriter.Rewriter;
 import org.apache.portals.applications.webcontent.rewriter.RewriterController;
+import org.apache.portals.applications.webcontent.rewriter.rules.Ruleset;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -133,7 +134,7 @@
         List<HttpReverseProxyPathMapper> proxyPathMappers = new ArrayList<HttpReverseProxyPathMapper>();
         
         List<KeyValue> rewriterControllerPairs = new ArrayList<KeyValue>();
-        List<KeyValue> rewriterPairs = new ArrayList<KeyValue>();
+        List<KeyValue> rewriterRulesetPairs = new ArrayList<KeyValue>();
         
         Configuration passConf = configuration.subset("proxy.reverse.pass");
         String [] pathNames = passConf.getStringArray("");
@@ -162,9 +163,14 @@
                     if (rewriterController != null)
                     {
                         rewriterControllerPairs.add(new DefaultKeyValue(localBasePath, rewriterController));
-                        String rewriterRuleConf = (rewriterRuleConfsLength > 1 ? rewriterRuleConfs[1]
: null);
-                        Rewriter rewriter = createRewriter(rewriterController, rewriterRuleConf);
-                        rewriterPairs.add(new DefaultKeyValue(localBasePath, rewriter));
+                        Ruleset rewriterRuleset = null;
+                        
+                        if (rewriterRuleConfsLength > 1)
+                        {
+                            rewriterRuleset = loadRewriterRuleset(rewriterController, rewriterRuleConfs[1]);
+                        }
+                        
+                        rewriterRulesetPairs.add(new DefaultKeyValue(localBasePath, rewriterRuleset));
                     }
                 }
             }
@@ -174,7 +180,7 @@
             throw new ServletException("Failed to initialize url mappings. " + e);
         }
         
-        HttpReverseProxyPathMapperProvider proxyPathMapperProvider = new DefaultHttpReverseProxyPathMapperProviderImpl(proxyPathMappers,
rewriterControllerPairs, rewriterPairs);
+        HttpReverseProxyPathMapperProvider proxyPathMapperProvider = new DefaultHttpReverseProxyPathMapperProviderImpl(proxyPathMappers,
rewriterControllerPairs, rewriterRulesetPairs);
         HttpReverseProxyService tempProxyService = new RewritableHttpReverseProxyServiceImpl(proxyPathMapperProvider);
         
         Configuration serverConf = configuration.subset("proxy.server");
@@ -300,34 +306,6 @@
         return new MappingRewriterController(getServletContext().getRealPath(rulesMappingResourcePath),
buildClassList(rewriterClassNames), buildClassList(adaptorClassNames));
     }
     
-    private Rewriter createRewriter(RewriterController rwc, String rewriterRulesResourcePath)
throws Exception
-    {
-        Rewriter rewriter = null;
-        InputStream rewriterRulesInput = null;
-        
-        try
-        {
-            if (!StringUtils.isBlank(rewriterRulesResourcePath))
-            {
-                rewriterRulesInput = getServletContext().getResourceAsStream(rewriterRulesResourcePath);
-                rewriter = rwc.createRewriter(rwc.loadRuleset(rewriterRulesInput));
-            }
-            else
-            {
-                rewriter = rwc.createRewriter();
-            }
-        }
-        finally
-        {
-            if (rewriterRulesInput != null)
-            {
-                IOUtils.closeQuietly(rewriterRulesInput);
-            }
-        }
-        
-        return rewriter;
-    }
-    
     private HttpRoute buildHttpRoute(Configuration routeConf) throws Exception
     {
         HttpRoute httpRoute = null;
@@ -576,4 +554,36 @@
             }
         }
     }
+    
+    private Ruleset loadRewriterRuleset(RewriterController rewriterController, String rulesConfResourcePath)
+    {
+        Ruleset ruleset = null;
+        
+        InputStream is = null;
+        InputStream bis = null;
+        
+        try
+        {
+            if (!StringUtils.isBlank(rulesConfResourcePath))
+            {
+                is = getServletContext().getResourceAsStream(rulesConfResourcePath);
+                bis = new BufferedInputStream(is);
+                ruleset = rewriterController.loadRuleset(bis);
+            }
+        }
+        finally
+        {
+            if (bis != null)
+            {
+                IOUtils.closeQuietly(bis);
+            }
+            if (is != null)
+            {
+                IOUtils.closeQuietly(is);
+            }
+        }
+        
+        return ruleset;
+    }
+    
 }

Modified: portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/proxy/impl/DefaultSSOSiteCredentials.java
URL: http://svn.apache.org/viewvc/portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/proxy/impl/DefaultSSOSiteCredentials.java?rev=820042&r1=820041&r2=820042&view=diff
==============================================================================
--- portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/proxy/impl/DefaultSSOSiteCredentials.java
(original)
+++ portals/applications/webcontent/trunk/webcontent-jar/src/main/java/org/apache/portals/applications/webcontent/proxy/impl/DefaultSSOSiteCredentials.java
Tue Sep 29 17:50:18 2009
@@ -5,6 +5,8 @@
 public class DefaultSSOSiteCredentials implements SSOSiteCredentials
 {
     
+    private static final long serialVersionUID = 1L;
+    
     private String baseURL;
     private String host;
     private int port = -1;

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=820042&r1=820041&r2=820042&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 17:50:18 2009
@@ -64,10 +64,9 @@
 import org.apache.portals.applications.webcontent.proxy.HttpReverseProxyService;
 import org.apache.portals.applications.webcontent.proxy.SSOSiteCredentials;
 import org.apache.portals.applications.webcontent.proxy.SSOSiteCredentialsProvider;
-import org.apache.portals.applications.webcontent.rewriter.ParserAdaptor;
 import org.apache.portals.applications.webcontent.rewriter.Rewriter;
 import org.apache.portals.applications.webcontent.rewriter.RewriterController;
-import org.apache.portals.applications.webcontent.rewriter.RewriterException;
+import org.apache.portals.applications.webcontent.rewriter.rules.Ruleset;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -430,7 +429,21 @@
                 out = response.getOutputStream();
 
                 RewriterController rewriterController = proxyPathMapperProvider.findRewriterController(request);
-                Rewriter rewriter = proxyPathMapperProvider.findRewriter(request);
+                Rewriter rewriter = null;
+                
+                if (rewriterController != null)
+                {
+                    Ruleset rewriterRuleset = proxyPathMapperProvider.findRewriterRuleset(request);
+                    
+                    if (rewriterRuleset == null)
+                    {
+                        rewriter = rewriterController.createRewriter();
+                    }
+                    else
+                    {
+                        rewriter = rewriterController.createRewriter(rewriterRuleset);
+                    }
+                }
                 
                 if (rewriterController == null || rewriter == null)
                 {
@@ -475,12 +488,13 @@
                         writer = new OutputStreamWriter(out);
                     }
                     
+                    rewriter.setBaseUrl(localBaseURL + request.getPathInfo());
                     rewriter.rewrite(rewriterController.createParserAdaptor(mimeType), reader,
writer);
                     writer.flush();
                 }
             }
         }
-        catch (RewriterException e)
+        catch (Exception e)
         {
             if (log.isDebugEnabled())
             {



Mime
View raw message