camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject svn commit: r1426196 - in /camel/trunk/components: camel-http/ camel-urlrewrite/ camel-urlrewrite/src/main/java/org/apache/camel/component/urlrewrite/ camel-urlrewrite/src/test/java/org/apache/camel/component/urlrewrite/http/ camel-urlrewrite/src/test/...
Date Thu, 27 Dec 2012 13:33:21 GMT
Author: davsclaus
Date: Thu Dec 27 13:33:20 2012
New Revision: 1426196

URL: http://svn.apache.org/viewvc?rev=1426196&view=rev
Log:
CAMEL-5912: More work on camel-urlrewrite

Added:
    camel/trunk/components/camel-urlrewrite/src/test/java/org/apache/camel/component/urlrewrite/http/HttpUrlRewriteModFileTest.java
      - copied, changed from r1426191, camel/trunk/components/camel-urlrewrite/src/test/java/org/apache/camel/component/urlrewrite/http/HttpUrlRewriteModTest.java
    camel/trunk/components/camel-urlrewrite/src/test/resources/example/modrewrite.cfg
Modified:
    camel/trunk/components/camel-http/   (props changed)
    camel/trunk/components/camel-urlrewrite/   (props changed)
    camel/trunk/components/camel-urlrewrite/src/main/java/org/apache/camel/component/urlrewrite/UrlRewriteFilter.java

Propchange: camel/trunk/components/camel-http/
------------------------------------------------------------------------------
--- svn:ignore (original)
+++ svn:ignore Thu Dec 27 13:33:20 2012
@@ -14,3 +14,4 @@ eclipse-classes
 *.ipr
 *.iml
 *.iws
+.idea

Propchange: camel/trunk/components/camel-urlrewrite/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Thu Dec 27 13:33:20 2012
@@ -0,0 +1,17 @@
+.pmd
+.checkstyle
+.ruleset
+target
+.settings
+.classpath
+.project
+.wtpmodules
+prj.el
+.jdee_classpath
+.jdee_sources
+velocity.log
+eclipse-classes
+*.ipr
+*.iml
+*.iws
+.idea

Modified: camel/trunk/components/camel-urlrewrite/src/main/java/org/apache/camel/component/urlrewrite/UrlRewriteFilter.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-urlrewrite/src/main/java/org/apache/camel/component/urlrewrite/UrlRewriteFilter.java?rev=1426196&r1=1426195&r2=1426196&view=diff
==============================================================================
--- camel/trunk/components/camel-urlrewrite/src/main/java/org/apache/camel/component/urlrewrite/UrlRewriteFilter.java
(original)
+++ camel/trunk/components/camel-urlrewrite/src/main/java/org/apache/camel/component/urlrewrite/UrlRewriteFilter.java
Thu Dec 27 13:33:20 2012
@@ -40,13 +40,14 @@ public abstract class UrlRewriteFilter e
 
     private static final Logger LOG = LoggerFactory.getLogger(UrlRewriteFilter.class);
 
-    // TODO: Allow to use a config file for mod rewrite rules as well
     // TODO: Find a better way of starting/stopping this without adding as service to CamelContext
+    // TODO: Dynamic ports of testing
 
     protected CamelContext camelContext;
     protected Conf conf;
     protected UrlRewriter urlRewriter;
     protected String configFile;
+    protected String modRewriteConfFile;
     protected String modRewriteConfText;
     protected boolean useQueryString;
 
@@ -102,6 +103,14 @@ public abstract class UrlRewriteFilter e
         this.modRewriteConfText = modRewriteConfText;
     }
 
+    public String getModRewriteConfFile() {
+        return modRewriteConfFile;
+    }
+
+    public void setModRewriteConfFile(String modRewriteConfFile) {
+        this.modRewriteConfFile = modRewriteConfFile;
+    }
+
     public boolean isUseQueryString() {
         return useQueryString;
     }
@@ -115,7 +124,21 @@ public abstract class UrlRewriteFilter e
         ObjectHelper.notNull(camelContext, "camelContext");
 
         if (conf == null) {
-            if (modRewriteConfText != null) {
+            if (modRewriteConfFile != null) {
+                LOG.debug("Using mod rewrite config file: {} as config for urlRewrite", modRewriteConfFile);
+                InputStream is = camelContext.getClassResolver().loadResourceAsStream(modRewriteConfFile);
+                if (is == null) {
+                    throw new IOException("Cannot load mod rewrite config file: " + modRewriteConfFile);
+                }
+                try {
+                    String text = camelContext.getTypeConverter().mandatoryConvertTo(String.class,
is);
+                    ModRewriteConfLoader loader = new ModRewriteConfLoader();
+                    conf = new Conf();
+                    loader.process(text, conf);
+                } finally {
+                    IOHelper.close(is);
+                }
+            } else if (modRewriteConfText != null) {
                 LOG.debug("Using modRewriteConfText: {} as config for urlRewrite", modRewriteConfText);
                 ModRewriteConfLoader loader = new ModRewriteConfLoader();
                 conf = new Conf();

Copied: camel/trunk/components/camel-urlrewrite/src/test/java/org/apache/camel/component/urlrewrite/http/HttpUrlRewriteModFileTest.java
(from r1426191, camel/trunk/components/camel-urlrewrite/src/test/java/org/apache/camel/component/urlrewrite/http/HttpUrlRewriteModTest.java)
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-urlrewrite/src/test/java/org/apache/camel/component/urlrewrite/http/HttpUrlRewriteModFileTest.java?p2=camel/trunk/components/camel-urlrewrite/src/test/java/org/apache/camel/component/urlrewrite/http/HttpUrlRewriteModFileTest.java&p1=camel/trunk/components/camel-urlrewrite/src/test/java/org/apache/camel/component/urlrewrite/http/HttpUrlRewriteModTest.java&r1=1426191&r2=1426196&rev=1426196&view=diff
==============================================================================
--- camel/trunk/components/camel-urlrewrite/src/test/java/org/apache/camel/component/urlrewrite/http/HttpUrlRewriteModTest.java
(original)
+++ camel/trunk/components/camel-urlrewrite/src/test/java/org/apache/camel/component/urlrewrite/http/HttpUrlRewriteModFileTest.java
Thu Dec 27 13:33:20 2012
@@ -25,14 +25,14 @@ import org.junit.Test;
 /**
  *
  */
-public class HttpUrlRewriteModTest extends CamelTestSupport {
+public class HttpUrlRewriteModFileTest extends CamelTestSupport {
 
     @Override
     protected JndiRegistry createRegistry() throws Exception {
         JndiRegistry jndi = super.createRegistry();
 
         HttpUrlRewrite myRewrite = new HttpUrlRewrite();
-        myRewrite.setModRewriteConfText("RewriteRule page/([^/\\.]+)/?$ index.php?page=$1
[L]");
+        myRewrite.setModRewriteConfFile("example/modrewrite.cfg");
 
         jndi.bind("myRewrite", myRewrite);
 

Added: camel/trunk/components/camel-urlrewrite/src/test/resources/example/modrewrite.cfg
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-urlrewrite/src/test/resources/example/modrewrite.cfg?rev=1426196&view=auto
==============================================================================
--- camel/trunk/components/camel-urlrewrite/src/test/resources/example/modrewrite.cfg (added)
+++ camel/trunk/components/camel-urlrewrite/src/test/resources/example/modrewrite.cfg Thu
Dec 27 13:33:20 2012
@@ -0,0 +1,2 @@
+# our custom mod rewrite rule
+RewriteRule page/([^/\.]+)/?$ index.php?page=$1 [L]



Mime
View raw message