• Post Reply Bookmark Topic Watch Topic
  • New Topic

RequestDispatcher.forward()

 
Johann Evans
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
As I understand, the forward method can only forward within a single servlet context - what can I do if I want to forward to another host? I.e. one host gets a request and forwards this request to another host with another servlet context on another network?
For now I'm using the HttpURLConnection to pass the request and then encode the response - isn't there a more elegant way?
Any tips would be appreciated!
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That sounds like you want to use the response.sendRedirect( other-system-URL );
 
Johann Evans
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That would work, but the sendRedirect requires the client to redirect to the new resource - unfortunately I should have maybe said that the resource is stashed behind a firewall, thus the "proxy" machine from the DMZ must "portal" the request.
 
Philip Shanks
Ranch Hand
Posts: 189
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Based on my limited understanding, it sounds to me like you want to set up an HTTP proxy service. Your servlet will have to make the request on behalf of the actual client, and send the response back.
That's a whole different kettle of fish than simple forwards or redirects, and if you are in a firewall DMZ environment, you will need to address security.
Here is how I understand these terms:
forward(): hands off the HTTP request, headers and all, to another resource to handle -- this is transparent to the client.
redirect(): sends a message back to the client to send a new request to a different resource or host.
Proxy: Service that transparently acts on behalf of the client to retrieve (normally protected or restricted) resources. The resource may have no knowledge of the actual client (normal proxy), or conversely, the client may have no knowledge of the actual resource (reverse proxy).
PCS
[ November 20, 2002: Message edited by: Philip Shanks ]
 
Johann Evans
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thx - it is kind of like a reverse proxy. What I have done now is to use the HttpURLConnection's getInputStream, and using this stream I actually read byte for byte from it - decode certain key features such as specific keywords and pass them onto the client. Once the client requests that resource either by href or src activation, I decode the pathinfo, map the info to an action and then via InputStream, read from the remote protected resource.
It seems to work, although I'm just worried about performance on multiple requests!?
I actually would like to simulate a portal server, but with less complexity...
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is possible to do, getServletContext().getContext( uriPath ).getRequestDispatcher( remotely_included_file ).forward( request, response ) but I'd put money on it not working.
From experience, it is often a poorly implemented piece of functionality in many application servers and will likely cause you more trouble than you're prepared to put up with.
As evil as the alternatives are, I'd still push for making a local HTTP call to the remote resource and piping the output back to the client!
Dave
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!