<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
      "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
  <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
  <title>WSO2 EI - URL Rewrite Mediator </title>
  <link href="css/EI-docs.css" rel="stylesheet" />
  <link href="styles/dist-docs.css" rel="stylesheet" type="text/css"
  media="all" />
</head>

<body>
<h2>Rewrite Mediator</h2>

<p>URL rewrite mediator is used to modify and transform the URL values available in the message </p>

<p><strong>Properties</strong> </p>
<p>By default the mediator will take the 'To' header of the message and apply the provided rewrite rules on it.
  Alternatively one can specify a property name in the 'inProperty' attribute, in which case the mediator will take the value of
  the specified property as the input URL. Similarly the mediator by default sets the transformed URL as the 'To' header of the message. 
  Alternatively you can use the 'outProperty' attribute to instruct the mediator to set the resulting URL as a property.</p> 
<ul>
    <li>In Property</li>
    <li>>Out Property</li>    
</ul>


<p><strong>Rules</strong> </p>    
<p>The rewrite mediator applies URL transformations by evaluating a set of rules on the message. 
Rules are specified using the 'rewriterule' element. Rules are evaluated in the order they are specified.
A rule can consist of an optional condition and one or more rewrite actions. If the condition is provided 
it will be evaluated first. If it evaluates to 'true' all the specified rewrite actions will be executed.
 Otherwise the set of actions will be skipped. If no condition is specified, the provided rewrite actions will be always executed.
 The condition should be wrapped in a 'condition' element within the 'rule' element.
 Rewrite actions are specified using 'action' elements. </p>
<ol>
 <li>Condition:- A rule can consist of an optional condition. If the condition is provided it will be evaluated first</li>
    <li>Action:- It states which type of action should be executed on the URL. This defaults to 'set' value</li>
    <li>Fragment:- This  attribute can be used to specify the URL fragment on which the action should be executed.
	If not specified this will be taken as 'full' URL, which is the complete URL</li>
    <li>Value/Expression:- The value to 'set', 'append' or 'prepend' must be specified using either the 'value' attribute or the 'xpath' attribute.
		One of these two attributes are always needed unless the value of the 'type' attribute is set to 'remove'</li>
	<li>Regex:- When user  set  action to 'replace' an additional 'regex' 
		attribute must be specified which indicates the portion that should be replaced with the given value. </li>
</ol>


<h3>Syntax</h3>
<pre xml:space="preserve">
&lt;rewrite [inProperty="string"] [outProperty="string"]&gt;
  &lt;rewriterule&gt;
      &lt;condition&gt;
         ...
      &lt;/condition&gt;?
      &lt;action [type="append|prepend|replace|remove|set"] [value="string"]
          [xpath="xpath"] [fragment="protocol|host|port|path|query|ref|user|full"] [regex="regex"]&gt;+
   &lt;/rewriterule&gt;+
&lt;/rewrite&gt;
</pre>

<h3>UI Configuration</h3>

<p><img alt="Rewrite Mediator" src="../rewriterule-mediator/docs/images/rewrite_mediator_screenshot.jpg" /> </p>

<p><strong>Figure1: Rewrite Mediator</strong> </p>

<h4>Properties</h4>
<ul>
    <li>In Property :</li>
	
	<p>
	By default 'rewrite' mediator will take the 'To' header of the message and will apply the provided rewrite rules on it.   
    If user specify a 'inProperty'  attribute, the mediator will take the value of the specified property as the input URL.
	</p>
   
    <li>Out Property :</li>   
	<p>
	 Similarly the mediator by default sets the transformed URL as the 'To' header of the message. 
      Alternatively user can use the 'outProperty' attribute to instruct the mediator to set the resulting URL as a property. 
    </p>
   
</ul>

<h4>Rules</h4>
<p>The rewrite mediator applies URL transformations by evaluating a set of rules on the message </p>
<img alt="Rewriterule Mediator" src="../rewriterule-mediator/docs/images/rewriterule_mediator_screenshot.jpg"/>
<p><strong>Figure2: Rules</strong> </p>
<ul>
    <li>Condition:- A rule can consist of an optional condition. If the condition is provided it will be evaluated first</li>
    <li>Action:- It states which type of action should be executed on the URL. This defaults to 'set' value</li>
    <li>Fragment:- This  attribute can be used to specify the URL fragment on which the action should be executed. For port and full-uri options those actions are not applicable. User should provide the correct port number/full-uri, which will be set.</li>
    <li>Value/Expression:- The value to 'set', 'append' or 'prepend' must be specified using either the 'value' attribute or the 'xpath' attribute.
		One of these two attributes are always needed unless the value of the 'type' attribute is set to 'remove'</li>
	<li>Regex:- When user  set  action to 'replace' an additional 'regex' 
		attribute must be specified which indicates the portion that should be replaced with the given value. </li>
</ul>



<h3>Example</h3>
<pre xml:space="preserve"> &lt;rewrite&gt;
	&lt;rewriterule&gt;
		&lt;action type="replace" regex="soap" value="services" fragment="path" /&gt;
	&lt;/rewriterule&gt;
&lt;/rewrite&gt;</pre>

<p>
For instance; if our request is as follows, 
</p>
<p><strong>"ant stockquote -Daddurl=http://localhost:8280/services/StockQuoteProxy1"</strong></p>
<p>the address URL of the  request contains the context 'soap'. 
In EI server all the services are deployed under a context named 'services' by default. So,'To' header will be re written by replacing the 'soap' context with 'services'.
 Hence the requests will be delivered to the  server successfully.
 </p>
 
</body>
</html>
