You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@synapse.apache.org by hi...@apache.org on 2010/08/23 11:34:04 UTC

svn commit: r988043 - in /synapse/trunk/scratch/hiranya/urlrewrite/src: main/java/org/apache/synapse/mediators/ main/java/org/apache/synapse/mediators/xml/ test/java/org/apache/synapse/mediators/

Author: hiranya
Date: Mon Aug 23 09:34:04 2010
New Revision: 988043

URL: http://svn.apache.org/viewvc?rev=988043&view=rev
Log:
output property support


Modified:
    synapse/trunk/scratch/hiranya/urlrewrite/src/main/java/org/apache/synapse/mediators/URLRewriteMediator.java
    synapse/trunk/scratch/hiranya/urlrewrite/src/main/java/org/apache/synapse/mediators/xml/URLRewriteMediatorFactory.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/URLRewriteMediator.java
URL: http://svn.apache.org/viewvc/synapse/trunk/scratch/hiranya/urlrewrite/src/main/java/org/apache/synapse/mediators/URLRewriteMediator.java?rev=988043&r1=988042&r2=988043&view=diff
==============================================================================
--- synapse/trunk/scratch/hiranya/urlrewrite/src/main/java/org/apache/synapse/mediators/URLRewriteMediator.java (original)
+++ synapse/trunk/scratch/hiranya/urlrewrite/src/main/java/org/apache/synapse/mediators/URLRewriteMediator.java Mon Aug 23 09:34:04 2010
@@ -43,6 +43,7 @@ public class URLRewriteMediator extends 
 
     private List<RewriteRule> rules = new ArrayList<RewriteRule>();
     private String inputProperty;
+    private String outputProperty;
 
     public boolean mediate(MessageContext messageContext) {
         Object[] fragments = newFragmentSet();
@@ -74,7 +75,11 @@ public class URLRewriteMediator extends 
             uri = getURI(fragments, messageContext);
         }
 
-        messageContext.setTo(new EndpointReference(uri.toString()));
+        if (outputProperty != null) {
+            messageContext.setProperty(outputProperty, uri.toString());
+        } else {
+            messageContext.setTo(new EndpointReference(uri.toString()));
+        }
         return true;
     }
 
@@ -142,4 +147,12 @@ public class URLRewriteMediator extends 
     public void setInputProperty(String inputProperty) {
         this.inputProperty = inputProperty;
     }
+
+    public String getOutputProperty() {
+        return outputProperty;
+    }
+
+    public void setOutputProperty(String outputProperty) {
+        this.outputProperty = outputProperty;
+    }
 }

Modified: synapse/trunk/scratch/hiranya/urlrewrite/src/main/java/org/apache/synapse/mediators/xml/URLRewriteMediatorFactory.java
URL: http://svn.apache.org/viewvc/synapse/trunk/scratch/hiranya/urlrewrite/src/main/java/org/apache/synapse/mediators/xml/URLRewriteMediatorFactory.java?rev=988043&r1=988042&r2=988043&view=diff
==============================================================================
--- synapse/trunk/scratch/hiranya/urlrewrite/src/main/java/org/apache/synapse/mediators/xml/URLRewriteMediatorFactory.java (original)
+++ synapse/trunk/scratch/hiranya/urlrewrite/src/main/java/org/apache/synapse/mediators/xml/URLRewriteMediatorFactory.java Mon Aug 23 09:34:04 2010
@@ -43,11 +43,15 @@ public class URLRewriteMediatorFactory e
     public Mediator createMediator(OMElement element) {
         Iterator rules = element.getChildrenWithName(new QName("rule"));
         String inputProperty = element.getAttributeValue(new QName("inProperty"));
+        String outputProperty = element.getAttributeValue(new QName("outProperty"));
 
         URLRewriteMediator mediator = new URLRewriteMediator();
         if (inputProperty != null) {
             mediator.setInputProperty(inputProperty);    
         }
+        if (outputProperty != null) {
+            mediator.setOutputProperty(outputProperty);
+        }
 
         while (rules.hasNext()) {
             RewriteRule rule = parseRule((OMElement) rules.next());
@@ -65,6 +69,7 @@ public class URLRewriteMediatorFactory e
 
         if (actions == null) {
             handleException("At least one rewrite action is required");
+            return null;
         }
 
         RewriteRule rule = new RewriteRule();

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=988043&r1=988042&r2=988043&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 Mon Aug 23 09:34:04 2010
@@ -59,7 +59,7 @@ public class URLRewriteTest extends Test
 
     public void testMediateWithFactory() throws Exception {
         String xml =
-                "<rewrite xmlns=\"http://synapse.apache.org/ns/2010/04/configuration\" inProperty=\"inputURL\">" +
+                "<rewrite xmlns=\"http://synapse.apache.org/ns/2010/04/configuration\" outProperty=\"outputURL\">" +
                 "    <rule>" +
                 "        <condition>" +
                 "            <and>" +
@@ -85,10 +85,11 @@ public class URLRewriteTest extends Test
         MessageContext synMc = new Axis2MessageContext(mc, config, env);
         synMc.setProperty("foo", "/esb");
         synMc.setProperty("inputURL", "http://wso2.org:9763/services/MyService");
-        //synMc.setTo(new EndpointReference("http://wso2.org:9763/services/MyService"));
+        synMc.setTo(new EndpointReference("http://wso2.org:9763/services/MyService"));
 
         mediator.mediate(synMc);
         System.out.println(synMc.getTo().getAddress());
+        System.out.println(synMc.getProperty("outputURL"));
     }
 
     public void testMediate() throws Exception {