• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to set http request header before redirecting it to different server

 
avneesh atri
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HI,
I am facing a problem in forwarding request to a different server with custom headers . The scenario is like this. Client(Web Browser) will send request to server 1 App A. Request will go from server 1 app A to server 2 AppB ,App B will add some custom header and it has to forward this request to server3 appC . AppC will read this request and headers set by appB and respond accordingly. AppC will return a page and this page should be forwarded to client who has originally sent the request to AppA. How should i forward the request from appB to appC so that my custom headers are set and are passed.
1) RequestDispatcher only forwards the request running on same server . But appC is on different server.
2) Response.sendRedirect will not help as the headers will be lost .
3) Apache.HttpClient is not an option as this will return the response to appB , not to the client . I can not forward this response to client from appB or even from appA .

How can i fix this problem.
 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why are you singling out the forwarding from appB to appC as the problem? The forwarding from appA to appB has the same problem, because they're also on different servers, no?

The first thing that comes to mind is: for forwarding between your own apps, why do you want to use HTTP headers? HTTP headers should mostly be used to control aspects of the HTTP protocol, not carry user data. (But this question is kind of moot, because forwarding does not work across servers, as you know.)

The second thing is: why forward at all? Why can't appA collect all the data it needs via API calls to appB and appC, and then return the result to the user?
 
avneesh atri
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Requirement is like this , i have to set custom header in appB and send it to appC. Is there any solution for this.
 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You may have to challenge that requirement. Even without using custom HTTP headers, forwarding to a different server simply does not work in the way you described.
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Since forwarding will not work, the only solution I can think of is to have server A generate a separate HTTP request to server B with the required headers and data. Next server A reads the response and sends it on as the response to the original request.


What a kludge, but fits the requirement.

Bill
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!