You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Warren Bell <wa...@gmail.com> on 2012/02/12 20:54:24 UTC

Modifying requests and responses in a proxy

I am in the process of writing a servlet that acts as a proxy where I
can modify request post parameters and thought I better check and see if
I am trying to reinvent the wheel.

I see there are proxies like mod_proxy that can be used to connect
Apache to Tomcat and I also saw Tomcat virtual hosts, but i am not sure
that either of these can handle what I am trying to do.

I want to be able to modify the request sent by the client and then
forward it to the target server. I also want to be able to modify the
response sent back by the target server and then forward it back to the
client.

Client Browser -> Proxy (modify request) -> Target Server
Target Server -> Proxy (modify response) -> Client Browser

Other requirements:

1. I do not want to use an Apache/Tomcat combination, Tomcat only.

2. The Proxy and Target Server are two different applications (contexts)
that may be running in the same instance of Tomcat or may be on two
different physical servers at different locations across the Internet.
The solution needs to work in both of these scenarios.

3. It needs to accommodate any rewriting of headers with host info in
them like 302 redirect Location headers.

My current solution uses a combination of a Servlet Filter that wraps
the request and response, so I can modify them, and then passes it to a
proxy servlet. I have it working pretty well as long as the proxy
servlet is run as the ROOT app in one instance of Tomcat and the target
server runs in another instance of Tomcat. The minute I try to run the
proxy servlet with a context path or run the proxy servlet and the
target app in the same Tomcat instance, I run into an evil 302 loop with
the target server app or a loop with the proxy itself. I thought I
better check and see if there is a better way of doing all of this
before I spend any more time coding for these situations.

-- 
Thanks,

Warren Bell

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


RE: Modifying requests and responses in a proxy

Posted by "Caldarale, Charles R" <Ch...@unisys.com>.
> From: Warren Bell [mailto:warrenbell2@gmail.com] 
> Subject: Modifying requests and responses in a proxy

> I am in the process of writing a servlet that acts as a proxy where I
> can modify request post parameters and thought I better check and see if
> I am trying to reinvent the wheel.

Maybe.  Take a look at this before spending too much time on it:

http://code.google.com/p/urlrewritefilter/

(This used to be hosted at tuckey.org, but appears to have recently moved.)

 - Chuck


THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY MATERIAL and is thus for use only by the intended recipient. If you received this in error, please contact the sender and delete the e-mail and its attachments from all computers.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org