/ Monitor / Documentation / Membrane Router / URL Rewriting with a HTTP Proxy

URL Rewriting

Requires version 1.3.0 or above.

Membrane Monitor/Router can change the path URI of a request. A request to

http://router.predic8.com/blz-service?wsdl

can be rewritten to

http://thomas-bayer.com/axis/services/BLZService?wsdl

The hostname is changed by the routing rule. To change the path URI you have to use an interceptor. Membrane comes with a SimpleURLRewriteInterceptor that can do the modification.

SimpleURLRewriteInterceptor

To demonstrate how the interceptor works the following steps describe how to map the WSDL of the BLZService to a nicer URL.

Open the file:

MEMBRANE_INSTALL_DIR/configuration/monitor-beans.xml

There you find a configuration of the SimpleURLRewritingInterceptor.

      
      <bean id="urlRewriter" class="com.predic8.membrane.core.interceptor.rewrite.SimpleURLRewriteInterceptor">
        <property name="displayName" value="Simple URL Rewriter" />
        <property name="mapping">
          <map>
            <entry>
          <key>
            <value>/blz-service?wsdl</value>
          </key>
          <value>/axis2/services/BLZService?wsdl</value>
        </entry>
          </map>
        </property>
      </bean>
      
      
Listing 1: SimpleURLRewritingInterceptor Configuration

You can specify as many mappings as you want. The key is the path URI of the request and the value is the path URI you want your request to be sent to. First, we have to associate the interceptor with a routing rule. Start Membrane Monitor and create a Simple Reverse Proxy Rule.

Creating a new Rule
Figure 1: Creating a new Rule

Specify 2000 as the port number on which the router will listen.

Listen Port
Figure 2: Listen Port

Than specify thomas-bayer.com as target host and 80 as target port. Next click on Finish.

Target Host and Port
Figure 3: Target Host and Port

To add the interceptor rightclick on the newly created rule in the Rule View and choose edit. Click onto the Interceptors tab and than on Add.

Configuring Interceptors for a Rule
Figure 4: Configuring Interceptors for a Rule

On the Add New Interceptor dialog choose Simple URL Rewriter and click on Ok. Simple URL Rewriter is the display name of the interceptor we have just configured in the XML file.

Add New Interceptor Dialog
Figure 5: Add New Interceptor Dialog

Now you can see the Simple URL Rewriter in the list of the engaged interceptors for this rule.

Simple URL Rewriter Interceptor
Figure 6: Simple URL Rewriter Interceptor

Test the monitor by opening the URL http://localhost:2000/blz-service?wsdl in your browser. You should get the WSDL from the BLZ service.

Requesting the WSDL with a nicer URL
Figure 7: Requesting the WSDL with a nicer URL