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.


Comments:

Yeah, the proxy URI mapping stuff kinda sucks. However, rather than monkey with "escaped" in rq->vars, I'd blow it away:

<Object ppath="/abc">
NameTrans fn="rewrite" path="http://example.com/abc.jsp"
NameTrans fn="set-variable" remove-vars="escaped" stop="true"
</Object>

Posted by Chris Elving on October 06, 2009 at 06:40 PM PDT #

Thank you very much!
Your article is very useful!
Keep up the good work, Your article is really great and I truly enjoyed reading it. Waiting for some more great articles like this from you in the coming days.

Posted by fake watches on December 19, 2009 at 10:29 PM PST #

Post a Comment:
  • HTML Syntax: NOT allowed
About

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

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
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
   
       
Today