I have written such a beast. Basically, from doGet() and doPost() I call
a method, doProxy(), which opens a URL and URL connection like this:
public static void doProxy(HttpServletRequest req,
HttpServletResponse res)
throws ServletException, IOException
{
ServletOutputStream out = res.getOutputStream();
String query = req.getQueryString();
URL url = new URL(src_path + "?" + query);
URLConnection connection = url.openConnection();
BufferedReader in = new BufferedReader(new
InputStreamReader(connection.getInputStream()));
String inputLine;
while ((inputLine = in.readLine()) != null)
{
out.println(replace(inputLine, out));
}
in.close();
out.close();
}
So, for each line read, it calls a replace() method which replaces all
occurrences of the source host with the destination host. I didn't include
the replace() method because it can be specific to your application. Ours
had to search for a host name with a path and replace it with a reference
to a different host with a path to another servlet.
Enjoy.
-----Original Message-----
From: A mailing list for discussion about Sun Microsystem's Java Servlet
API Technology. [mailto:[EMAIL PROTECTED]]On Behalf Of Tom
Gerber
Sent: Wednesday, June 09, 1999 5:00 PM
To: [EMAIL PROTECTED]
Subject: Proxy Servlet
I need a Servlet which will do the following: Take the input query string
and form data and call the same request to another Web server.
This Servlet will basically act as a relay.
For example:
If my servlet is on "www.me.com"
and I call it with an
http://www.me.com/servlet/relay?http://www.other.com/somepageorservlet?that
mayhaveitsownparams
and takes the data stream coming back and modifies all internal URL's to
www.other.com so they are prefixed with http://www.em.com/servlet/relay?
I may be using the wrong terms here (forward/relay) but has anyone written
such a Servlet?
Is the source available? or a good example I can modify to work this way?
I need to be able to forward all form data if it was a post.
Thanks
___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".
Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html
___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".
Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html