• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Forwarding to a different server

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Has anyone successfully forwarded a request and response to a servlet residing on a different server?

We have multiple servers and want to forward some requests to a specific server. All servers run Servlets.

I thought this would work
request.getRequestDispatcher("urlToOtherServer").forward(request, response);
...but what I read is that this will only work on the same server.

I didn't want to open a URL and URLConnection to do this.

Any help or ideas appreciated.
 
Ranch Hand
Posts: 5093
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Think for a moment. You're forwarding REFERENCES TO the request and response Objects.
On the other server these don't exist so the forward won't work.
 
Larry Cryderm
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I thought of that, but didn't know if serialization was involved.
Do you have a recommendation?
Thanks.
 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you need to pass few parameters only to the server , try response.Redirect
 
Jeroen Wenting
Ranch Hand
Posts: 5093
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Larry Cryderm:
I thought of that, but didn't know if serialization was involved.
Do you have a recommendation?
Thanks.



You can't serialize objects over a network during a forward.
You'd need a special mechanism you will have to write yourself to handle it, and send all the data before you do the forward, then in the receiving servlet read in that information based on whatever (maybe use a fixed name, but that's obviously risky as you can't handle more than one request that way).

No, it is not going to be pretty. Better just create a new URL and do a POST request to the other machine making sure all relevant data from the session and request are turned into HTML parameters (meaning essentially plain text in the HTTP headers).
 
Ranch Hand
Posts: 155
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Use an http client and remake the request.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic