wood burning stoves 2.0*
The moose likes Servlets and the fly likes  forwarding  using a Servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark " forwarding  using a Servlet" Watch " forwarding  using a Servlet" New topic
Author

forwarding using a Servlet

nicole lewis
Greenhorn

Joined: Nov 04, 2009
Posts: 3
Hi All,

I am new to Java Servlets so really appreciate your help.

In my situation i have a web application in private Zone and i need to provide access to outside (over the web) users through server (forwarding) in public Zone which redirect request to private zone.
i can't use reverse proxy because need to provide encryption between two servers.
I wrote a simple forwarding app with servlet work with http messages but for web site GUI not display.
Also when user clicks links it didn't go though the forwarding servlet.


i am using tomcat in both places
Thanks
ramprasad madathil
Ranch Hand

Joined: Jan 24, 2005
Posts: 489

What exactly is the error? Isnt your forwrading servlet not invoked? Is it throwing an error when it's invoked? Does it fail to contact the other application across the firewall?
Lorand Komaromi
Ranch Hand

Joined: Oct 08, 2009
Posts: 276
nicole lewis wrote:
Also when user clicks links it didn't go though the forwarding servlet.


You'll have to replace all the URLs with the URL of the forwarding servlet, and maybe pass the original address in a GET parameter...

Could you show us the code of getString()..?


OCJP 6 (93%)
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41141
    
  45
Welcome to JavaRanch.

So you're trying to send back a page that essentially consists of a different page from a different server? You'll run into problems with that approach - namely all the URLs will be pointing to the private server, but they'll now go to the public one - which likely won't know what to do with them, unless you're putting elaborate mechanisms in place to do this kind of forwarding for ALL request; is that what you're planning to do? Essentially to write a web app that serves as a proxy for another web app? If so, I bet that there are existing web apps out there on the web that do this kind of thing.


Ping & DNS - my free Android networking tools app
nicole lewis
Greenhorn

Joined: Nov 04, 2009
Posts: 3
Thanks for the replies

@ramprasad madathil
My problem is response doesn't have images,css ,java scripts ect.And also when user clicks response UI link it try to connect original site (which reside in private Zone) .

@Lorand Komaromi
nicole lewis
Greenhorn

Joined: Nov 04, 2009
Posts: 3
@ Ulf Dittmer

Thanks for the reply
Yes i tested few web applications which serve as proxy's but problem is i need to provide encryption/decryption between two servers.I couldn't found any open source application for that purpose.
Lorand Komaromi
Ranch Hand

Joined: Oct 08, 2009
Posts: 276
nicole lewis wrote:
My problem is response doesn't have images,css ,java scripts ect.And also when user clicks response UI link it try to connect original site (which reside in private Zone) .


Yes, like we said, you have to rewrite all the URLs!

nicole lewis wrote:
str = br.readLine()


Are you sure that all the forwarded pages contain a new line at the end..?

nicole lewis wrote:
returnStr += str;


Take a look at StringBuilder!
Lorand Komaromi
Ranch Hand

Joined: Oct 08, 2009
Posts: 276
Lorand Komaromi wrote:
Take a look at StringBuilder!


Or even better, don't buffer the forwarded resources, send them directly to your outputsream as you're reading!
ramprasad madathil
Ranch Hand

Joined: Jan 24, 2005
Posts: 489

also when user clicks response UI link it try to connect original site (which reside in private Zone) .


That would happen only if you have the entire url path in the links of the pages delivered by the original site. If you have urls relative to the context root (for images, css, js and even jsps), they would link back to your public site only. It's a different thing that the url wouldnt be found at the public site. To achieve that, here is what I would do if such home written proxying is the only option available -

There have been previous posts that spoke about url rewriting. So if you can do that and append a common identifier at the begining of all urls served by the other site - say /private/<original_url> , it's a matter of writing a mapping in your web.xml that forwards all such requests (with this pattern) to your forwarding Servlet.

cheers,
ram.

Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41141
    
  45
Yes i tested few web applications which serve as proxy's but problem is i need to provide encryption/decryption between two servers.I couldn't found any open source application for that purpose.

It's most likely easier and faster to take an existing solution and add encryption to it, than to write a proxy from scratch (for which you'll also need to write the encryption code).
 
wood burning stoves
 
subject: forwarding using a Servlet
 
Similar Threads
Using Netbean 6.8 to create a Servlet app that queries a database
Issues regarding Applet-Servlet communication
HELP! Applet's trouble with Servlet's response
access to internal web site using Servlet redirection/forwarding with 3DES Encryption
Limit on Data/Key-Value Pairs in Form Submission