request.setHeader in servlet filter

Hi there,

I am working on servlet filter to filter HttpServletRequest before sending it to the original servlet.

The original servlet expects some content posted in the body of HttpServletRequest object.

In my servlet filter, I need to modify this content (already done) and then doFilter to the origin.

And here is the problem:

The original servlet uses HTTP header's content-length value to read the entire content posted. But if I modify this content in my filter, it will never get correct content of the request.

Unfortunately the original servlet is black boxed and there is no way to modify it.

Is there any way to modify HTTP headers of HttpServletRequest in servlet filter?

Thank you for any suggestions,

mato_v

[782 byte] By [mato_va] at [2007-11-26 15:02:18]
# 1

Hum... ServletRequest.getHeader is read only, so you can't change them. There few solution you may try though:

* Try create another wrapper instance of ServletRequest inside your filter and forward it to your black box servlet. You might have to wrote your own implementation to manipulate those Headers.

* How about after you changed your data, redirect/post to your black box with the correct content? Use java.net.HttpURLConnection or a java Http client to do fancy posting if needed.

Hope these helps.

thebugslayera at 2007-7-8 8:51:24 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2
Hi thebugslayer,I already solved my problem overriding getContentLength and getHeader* methods in my HttpServletRequestWrapper as you recommended.Thank you,mato_v
mato_va at 2007-7-8 8:51:24 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...