Meaningless Drivel is fun!*
The moose likes Servlets and the fly likes Setting HttpServletRequest headers Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Setting HttpServletRequest headers" Watch "Setting HttpServletRequest headers" New topic
Author

Setting HttpServletRequest headers

Thomas Mcfarrow
Ranch Hand

Joined: Jul 09, 2001
Posts: 137
Hello,

I need to make a code stub for some SSO software that my company uses. I wan't to mimick its behavior by setting HttpServletRequest headers and forwarding it on. How could I set request headers?

Thanks.
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12671
    
    5
If you are modifying an existing request, the servlet API provides the HttpServletRequestWrapper class to accomplsh this since you can't modify an existing request directly.
You create a custom wrapper that watches for getParameter calls specifying the parameters of interest.
If you are creating a new request, just implement the HttpServletRequest interface in your custom class.
Bill


Java Resources at www.wbrogden.com
Fisher Daniel
Ranch Hand

Joined: Sep 14, 2001
Posts: 582
Hi,
I am curious about this...
Where we can modify a request using that request wrapper?
In a filter class or servlet class?

Correct me if my understanding is wrong
thanks
daniel
Thomas Mcfarrow
Ranch Hand

Joined: Jul 09, 2001
Posts: 137
Hello, I don't want to modify the query string. I want to modify the HTTP header.

Thanks in advance.
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12671
    
    5
Basically you use a Filter to substitute your custom request wrapper object for the original request.
Your custom wrapper will be what the servlet sees so every request for a header OR for a parameter OR for an input stream will go to your filter first.
Take a look at the javax.servlet.http.HttpServletRequestWrapper class JavaDocs to see how convenient the designers have made this capability.
Bill
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Setting HttpServletRequest headers
 
Similar Threads
js not refreshed?
Logoff button - what to do?
addHeader() problem
Expires header and window.opener
Adding authentication in SOAP header..