Author: hiranya
Date: Fri Aug 13 23:13:04 2010
New Revision: 985401

URL: http://svn.apache.org/viewvc?rev=985401&view=rev
Log:
Minor refactoring


Modified:
    
synapse/trunk/scratch/hiranya/urlrewrite/src/main/java/org/apache/synapse/mediators/RewriteRule.java
    
synapse/trunk/scratch/hiranya/urlrewrite/src/test/java/org/apache/synapse/mediators/URLRewriteTest.java

Modified: 
synapse/trunk/scratch/hiranya/urlrewrite/src/main/java/org/apache/synapse/mediators/RewriteRule.java
URL: 
http://svn.apache.org/viewvc/synapse/trunk/scratch/hiranya/urlrewrite/src/main/java/org/apache/synapse/mediators/RewriteRule.java?rev=985401&r1=985400&r2=985401&view=diff
==============================================================================
--- 
synapse/trunk/scratch/hiranya/urlrewrite/src/main/java/org/apache/synapse/mediators/RewriteRule.java
 (original)
+++ 
synapse/trunk/scratch/hiranya/urlrewrite/src/main/java/org/apache/synapse/mediators/RewriteRule.java
 Fri Aug 13 23:13:04 2010
@@ -42,13 +42,14 @@ public class RewriteRule {
                         Map<String,String> headers) {
 
         EvaluatorContext ctx = new EvaluatorContext(uriString, headers);
-        try {
-            if (condition != null && !condition.evaluate(ctx)) {
+        if (condition != null) {
+            try {
+                if (!condition.evaluate(ctx)) {
+                    return;
+                }
+            } catch (EvaluatorException e) {
                 return;
             }
-        } catch (EvaluatorException e) {
-            e.printStackTrace();
-            return;
         }
 
         String result;
@@ -68,7 +69,6 @@ public class RewriteRule {
                 fragments[4] = uri.getPath();
                 fragments[5] = uri.getQuery();
                 fragments[6] = uri.getFragment();
-
             } catch (URISyntaxException e) {
                 return;
             }

Modified: 
synapse/trunk/scratch/hiranya/urlrewrite/src/test/java/org/apache/synapse/mediators/URLRewriteTest.java
URL: 
http://svn.apache.org/viewvc/synapse/trunk/scratch/hiranya/urlrewrite/src/test/java/org/apache/synapse/mediators/URLRewriteTest.java?rev=985401&r1=985400&r2=985401&view=diff
==============================================================================
--- 
synapse/trunk/scratch/hiranya/urlrewrite/src/test/java/org/apache/synapse/mediators/URLRewriteTest.java
 (original)
+++ 
synapse/trunk/scratch/hiranya/urlrewrite/src/test/java/org/apache/synapse/mediators/URLRewriteTest.java
 Fri Aug 13 23:13:04 2010
@@ -21,15 +21,13 @@ package org.apache.synapse.mediators;
 
 import junit.framework.TestCase;
 import org.apache.synapse.MessageContext;
+import org.apache.synapse.util.xpath.SynapseXPath;
 import org.apache.synapse.commons.evaluators.EqualEvaluator;
+import org.apache.synapse.commons.evaluators.source.URLTextRetriever;
 import org.apache.synapse.config.SynapseConfiguration;
 import org.apache.synapse.core.axis2.Axis2MessageContext;
 import org.apache.synapse.core.axis2.Axis2SynapseEnvironment;
 import org.apache.synapse.core.SynapseEnvironment;
-import org.apache.axis2.addressing.EndpointReference;
-import org.apache.axiom.soap.SOAPEnvelope;
-import org.apache.axiom.om.OMAbstractFactory;
-import org.apache.axiom.om.OMDocument;
 
 import java.net.URI;
 import java.net.URISyntaxException;
@@ -55,12 +53,13 @@ public class URLRewriteTest extends Test
         }
     }
 
-    public void testMediate() {
+    public void testMediate() throws Exception {
         org.apache.axis2.context.MessageContext mc =
                 new org.apache.axis2.context.MessageContext();
         SynapseConfiguration config = new SynapseConfiguration();
         SynapseEnvironment env = new Axis2SynapseEnvironment(config);
         MessageContext synMc = new Axis2MessageContext(mc, config, env);
+        synMc.setProperty("prop1", "ref1");
 
         URLRewriteMediator mediator = new URLRewriteMediator();
 
@@ -73,6 +72,17 @@ public class URLRewriteTest extends Test
         r2.setFragmentIndex(URLRewriteMediator.PATH);
         mediator.addRule(r2);
 
+        EqualEvaluator eval = new EqualEvaluator();
+        URLTextRetriever txtRtvr = new URLTextRetriever();
+        txtRtvr.setFragment("port");
+        eval.setTextRetriever(txtRtvr);
+        eval.setValue("8080");
+        RewriteRule r3 = new RewriteRule();
+        r3.setCondition(eval);
+        r3.setXpath(new SynapseXPath("get-property('prop1')"));
+        r3.setFragmentIndex(URLRewriteMediator.REF);
+        mediator.addRule(r3);
+
         mediator.mediate(synMc);
         System.out.println(synMc.getTo());
     }


Reply via email to