Set headers for HttpServletRequest object?
hey, I've written a web application and I have methods which take in
a HttpServletRequest object and process the request headers.
How can I test my methods which take in HttpServletRequest object? I need to set the values of the headers, usually this is done by an external party but when I'm testing I need to manually set attributes and corresponding values. So is there a way to set these headers manually for testing purposes? or can you suggest some way I can write my test cases?
Thanks
Re: Set headers for HttpServletRequest object?
Well in your unit testing you could fire up a jetty webserver and then actually fire off a proper request and let it all work on its own. However you could also create a class that implements the HttpServletRequest interface and pass that object in.
// Json
Re: Set headers for HttpServletRequest object?
thanks, I can write a class to implement that interface but what methods do I then call in order to set the values of the request headers? I can see there's a getHeaders() method of HttpServletRequest but there's no setHeader() method. so how do I get around this?
Re: Set headers for HttpServletRequest object?
Try response.setHeader() :)
You can't set any headers on the request because once you have access to the request the headers will already have been read by the web server.
// Json