How to create request object manually?

Can i edit a servlet request at the front controller level and disptach it to real url?

I need the way(maybe a class) to edit the request parameters;

request.getContextPath();

request.getRequestURL();

request.getPathInfo();

request.getServletPath();

i need the equvilance of these methods which are built to SET.

is it possible?

thank you

[393 byte] By [netsonicca] at [2007-11-27 11:52:10]
# 1

> which are built to SET

Servlet filter could use HttpServletRequestWrapper for such purpose.

hiwaa at 2007-7-29 18:42:48 > top of Java-index,Java Essentials,New To Java...
# 2

thanks for the reply. I have looked at RequestWrapper class but really couldnt find the solution that i want.

I only need to reset the value which request.getServletPath() returns. Is it possible to do this with RequestWrapper?

netsonicca at 2007-7-29 18:42:48 > top of Java-index,Java Essentials,New To Java...
# 3

1) Write a subclass of the HttpServletRequestWrapper class and overide your required methods.

2)In the doFilter() method of your filter, call chain.doFilter() method giving your wrapped request object as an argument.

--That's it.

Go to the servlet forum: http://forum.java.sun.com/forum.jspa?forumID=33 and do search with RequestWrapper. Then you will find some nifty examples for tampering the request.

hiwaa at 2007-7-29 18:42:48 > top of Java-index,Java Essentials,New To Java...
# 4

> 1) Write a subclass of the HttpServletRequestWrapper

> class and overide your required methods.

http://forum.java.sun.com/thread.jspa?threadID=682565&tstart=100

I have used the wrapper in that forum but this is just for to set some Parameter to the request. But there is no method like setServletPath on the wrapper class? it is still missing and i need an HELP plz about how to override ServletPath on the request object.

> 2)In the doFilter() method of your filter, call

> chain.doFilter() method giving your wrapped request

> object as an argument.

I did it

public void doFilter(ServletRequest req,ServletResponse res,FilterChain chain)throws IOException,ServletException {

HttpServletRequest request = (HttpServletRequest) req;

HttpRequestWithModifiableParameters myReq= new HttpRequestWithModifiableParameters(request);

request=(HttpServletRequest)myReq;

HttpServletResponse response=(HttpServletResponse)res;

chain.doFilter( request, response );

}

please help about just only how to override ServletPath on request object!!

thank you

netsonicca at 2007-7-29 18:42:48 > top of Java-index,Java Essentials,New To Java...
# 5

> there is no method like setServletPath

I said override your required methods. The request class doesn't have setXxx() methods. You should override getServletPath() method on the wrapper.

> chain.doFilter( request, response )

Simply do:

req = new MyWrapper(req);

chain.doFilter(req, res); //don't write awkward spaces

Your 'request' and 'myReq' are also awkwardly redundant.

hiwaa at 2007-7-29 18:42:48 > top of Java-index,Java Essentials,New To Java...