Monday Oct 05, 2009

A Creative Way Of Using The Rewrite NameTrans SAF in WS7.0

When creating a reverse proxy mapping from a pattern like "/abc" to a file resource like "http://remoteserver/abc.jsp" on the remote server, the map function creates an undesirable effect of adding a slash "/", to the end of the URL that is being rewritten.  While this is per design,  and adding the slash "/" is intentional behavior of the reverse proxy functionality, this can be problematic when the mapping is to a file resource rather than to a file path.


The first problem with this is that the path gets rewritten to "http://remoteserver/abc.jsp/", causing a "404 Not Found" response from the remote server.  Another problematic effect of this is if the request to "/abc" was for a POST request.  When the request is for a POST to "/abc", the path gets rewritten to "http://remoteserver/abc.jsp/" via a "302 Redirect" response from the map function, resulting in the POST entity body being dropped from the request.


Web Server 7.0 is highly configurable and contains configurable features that can help remedy a problem like this in our reverse proxy functionality.  Here is a quick and easy way to do it - add the following configuration to the default object in the obj.conf before your general map NameTrans line to your reverse-proxy object :



<If uri="/abc">
NameTrans fn="rewrite" path="/abc/"
NameTrans fn="map" from="/abc" to="http://remoteserver/abc.jsp"
<If defined $vars{'escaped'} and $vars{'escaped'} =~'(.\*)/$'>
Route fn="set-variable" $vars{'escaped'}="$1"
</If>
</If>

By utilizing the above configuration, the rewrite NameTrans SAF will append a slash "/" to the end of the request path so to avoid the undesired behavior of the map NameTrans SAF.  The usage of the set-variable Route SAF is to remove the slash "/" for the escaped variable.


Documentation for the rewrite SAF.


About

Quick tips and tricks, problems and resolutions, questions and answer, to help you with your Sun Java System Web Server.

Search

Archives
« October 2009
SunMonTueWedThuFriSat
    
1
2
3
4
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
       
Today