The URLRewrite Mediator (New in version 4.0) is used to modify and transform the URL values available in the message. The input URL could be taken from the 'To' header of the message or from a property available on the message. Once the input URL is selected, a series of user-defined rewrite rules will be evaluated on the message. Depending on the outcome of these rule evaluations, the URL will be modified and set on the message.
URL rewrite mediator breaks the URL down to seven segments:
- Protocol
- User information
- Hostname
- Port
- Path
- Query
- Reference parameter
Note that this breakdown is inline with the URI specification (RFC2396). URL rewrite mediator enables rewriting each of the above segments separately and finally combining them to get the final URL value. It also supports rewriting the entire URL string at once.
...
Table of Contents | ||||
---|---|---|---|---|
|
...
|
...
UI Configuration
Specify the following properties:
- In Property - By default, the Rewrite Mediator will take the "To" header of the message and will apply the provided rewrite rules on it. If the user specifies an
inPorperty
inProperty
attribute, the mediator will take the value of the specified property as the input URL. - Out Property - Similarly, the mediator by default sets the transformed URL as the "To" header of the message. Alternatively, users can use the
outProperty
attribute to instruct the mediator to set the resulting URL as a property.
The Rewrite Mediator applies URL transformations by evaluating a set of rules on the message. To add a rule to the mediator, click on the "Add Rule" link.
In the window which appears, specify the following options:
A URLRewriteRule node is added under the URLRewrite node in the sequence. Click the URLRewriteRule node to configure the rule.
- Condition - A rule can have an optional condition. If the condition is provided, it will be evaluated first.
- Action - It states what Specify the type of an action should be executed to execute on the URL. This defaults to "set" value.
- Fragment - This attribute can be used to specify the URL fragment on which the action should be executed.
- Option - If the Action is anything other than Remove, select Value or Expression to indicate which type of value you will provide.
- Value/Expression - The values "set," "append" or "prepend" must be specified using either the "value" attribute or the
XPath
attribute. One of these two attributes is always needed unless the value of the "type" attribute is set to "remove."Regex - When users set action to "replace," Enter the value or expression to use with the action, such as the value to set. - Regex - If the action is Replace, specify an additional "regex" attribute must be specified, which that indicates the portion that should be replaced with the given value.
- Delete - Allows to remove the action.
Example
...
<rewrite>
<rewriterule>
<action type="replace" regex="soap" value="services" fragment="path" />
</rewriterule>
</rewrite>
For instance, if our request is as follows:
...
- Removes this action from the rule.
Example
Assume the address URL of a request contains the context "soap", such as http://localhost:8280/
...
soap/StockQuoteProxy1
...
The address URL of the request contains the context "soap. " In the ESB server, all the services are deployed under a context named "services" by default. So, so we want to replace the "To " header will be re-written by replacing the "soap" context with "services." Hence, " in the "To" header (http://localhost:8280/services/StockQuoteProxy1
) so that the requests will be delivered to the server successfully.
Code Block |
---|
...
|
...
hidden | true |
---|
| |
<rewrite>
<rewriterule>
<action type="replace" regex="soap" value="services" fragment="path" />
</rewriterule>
</rewrite>
|
For additional samples, see Rewriting the URL (URL Rewrite Mediator).