Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

The URLRewrite Mediator 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 oncemessages. This can be done by defining a rewrite action for each fragment of a selected property value. Alternatively, you can rewrite the entire URL string at once.

Info

The URLRewrite mediator is a content aware mediator.

...

Table of Contents
maxLevel3
minLevel3
styleborder:1
locationtop
typeflat
separatorpipe

...

Syntax

Code Block
languagexml
<rewrite [inProperty="string"] [outProperty="string"]>
    <rewriterule>
        <condition>
        ...
        </condition>?
        <action [type="append|prepend|replace|remove|set"] [value="string"]
          [xpath="xpath"] [fragment="protocol|host|port|path|query|ref|user|full"] [regex="regex"]>+
    </rewriterule>+
</rewrite>

 

...

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 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 The parameters available to configure the URL Rewrite mediator are as follows.

Parameter NameDescription
In PropertyThis parameter is used to enter property of which the value should be considered the input URL. The rewrite rules are applied to the value of the property entered in this parameter to generate the result URL. If no property is entered, the rewrite rules will be applied to the To header of the message.
Out Property
Anchor
Out
Out
This parameter is used to enter the property to which the transformations done via the rewrite rules should be applied. If no property is entered, the transformations will be applied to the  To header of the message.

The Rewrite mediator applies the URL transformations by evaluating a set of rules on the message. To add a rule to the mediator, click on the "click Add Rule" link.

Image Removed

A URLRewriteRule node is added under the URLRewrite node in the sequence. Click the URLRewriteRule node to configure the rule.

Image Removed

  • Condition - A rule can have an optional condition. If the condition is provided, it will be evaluated first.
  • Action - Specify the type of action 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 - 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 that indicates the portion that should be replaced with the given value.
  • Delete - Removes this action from the rule.

Example

Assume the address URL of a request contains the context "soap", such as . The rewrite rule will be added to the mediator tree as a child of the URLRewrite mediator (see the image below).

Image Added

Click URLRewriteRule in the mediator tree to configure the rewrite rule you added. The following section will be displayed.

Image Added

A rule can consist of one or more rewrite actions and an optional condition. The Condition parameter is used to enter the optional condition. If a condition is specified, it will be evaluated before the rewrite actions, and the rewrite actions will be executed only if the condition evaluates to true.

A rewrite action is added by clicking Add Action which would display the following row.

Image Added

The parameters available to configure a rewrite action are as follows.

Parameter NameDescription
Action

This parameter is used to specify the action to be performed by the rewrite action. Each rewrite action is performed on a fragment entered in the Fragment parameter. Possible values are as follows.

  • Replace: If this is selected, the existing in property value fragment will be replaced by the result value.
  • Remove: If this is selected, the result value will be removed from the in property value fragment.
  • Append: If this is selected, the result value will be added to the end of the in property value fragment.
  • Prepend: If this is selected, the result value will be added to the beginning of the in property value fragment.
  • Set: If this is selected, the result value will be set as the in property value fragment.
Fragment

The fragment of the in property (i.e. input URL) for which the rewrite action should be performed. The available fragments are as follows.

  • Protocol:
  • Host
  • Port
  • Path
  • Query
  • Ref
  • User
  • Full
Info

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.

Option

This parameter is used to define the result value of the rewrite action. Select one of the following.

  • Value: If this is selected, the result value would be a static value.
  • Expression: If this is selected, the result value will be evaluated using an expression.
Value/ExpressionThis parameter is used to enter the result value of the URLRewrite mediator as a static value or an expression, depending on what you selected for the Option parameter.
Namespace EditorYou can click this link to add namespaces when you are providing an expression. Then the Namespace Editor panel would appear where you can provide any number of namespace prefixes and URLs used in the XPath expression. 
RegexThis parameter is used to specify which part of the in property value fragment should be replaced by the result value if you selected Replace for the Action parameter.
DeleteClick Delete in the relevant row to remove a rewrite action.
Info
titleNote

You can configure the mediator using XML. Click switch to source view in the Mediator window.

Image Added

Example

In this example, the URLRewrite mediator has a rewrite action which replaces the value soap with value services in the fragment path of the input URL. Since no in property or an out  property is specified, the To header of the  request is both the input  to which the rewrite rule is applied and the target where the result URL is set. This configuration is typically used when the address URL of a request contains the context soap which needs to be converted since all the services are deployed under a context named services in the ESB server. Thus, the URL http://localhost:8280/soap/StockQuoteProxy1. In the ESB server, all the services are deployed under a context named "services" by default, so we want to replace the "soap" context with "services" in the "To" header ( is rewritten as http://localhost:8280/services/StockQuoteProxy1) so to ensure that the requests will be are successfully delivered to the server successfully. 

Code Block
XML
XML
<rewrite>
	<rewriterule>
		<action type="replace" regex="soap" value="services" fragment="path" />
	</rewriterule>
</rewrite>

Samples

For additional samplesmore examples, see Rewriting the URL (URL Rewrite Mediator).: