You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by James Cook <ji...@iname.com> on 2000/02/22 01:42:20 UTC

Problem with RequestDispatcher

I am programmatically chaining servlets to facilitate a portal site I am
developing. I found it necessary to use the facade pattern to wrap the
HttpServletRequest object in my portal's doGet() method. In this method, I
make a call to the RequestDispatcher's include() method.

Turns out the RequestDispatcher.include() method uses the following line:

Request realRequest = ((HttpServletRequestFacade)request).getRealRequest();

Of course, I was passing *my* PortalRequestFacade object and I get a class
cast exception. Is it necessary to assume this type of cast? Wouldn't it be
better to have two include() methods, such as:

    public void include(ServletRequest request, ServletResponse response);
    public void include(HttpServletRequestFacade request,
HttpServletRequestFacade response) {
      Request realRequest = request.getRealRequest();
	Response realResponse = response.getRealResponse();
	include (realRequest, realResponse);
}

I would extend your facade class to facilitate my needs, however I would
like this to be a portable solution.

thanks,
jim


Re: Problem with RequestDispatcher

Posted by co...@eng.sun.com.
> Turns out the RequestDispatcher.include() method uses the following line:
> 
> Request realRequest = ((HttpServletRequestFacade)request).getRealRequest();

It seems the spec requires to pass the _original_ request/response object.

I would love to remove this limitation, I also think it's very usefull to
pass arbitrary request objects to RD - but I don't think we can do too
much about this in Servlet 2.2. 

I know few other engines that assume the parameter of RD is the original 
request, so your servlet will not be portable even if we change tomcat.

The reason for this restriction _may_ be the fact that the engine must
change the Request object, and that's not possible unless with the read
only HttpServletRequest. One solution would be to create a facade, but
that's very expensive - too many object allocation/request. 

Costin



> Of course, I was passing *my* PortalRequestFacade object and I get a class
> cast exception. Is it necessary to assume this type of cast? Wouldn't it be
> better to have two include() methods, such as:
> 
>     public void include(ServletRequest request, ServletResponse response);
>     public void include(HttpServletRequestFacade request,
> HttpServletRequestFacade response) {
>       Request realRequest = request.getRealRequest();
> 	Response realResponse = response.getRealResponse();
> 	include (realRequest, realResponse);
> }
> 
> I would extend your facade class to facilitate my needs, however I would
> like this to be a portable solution.
> 
> thanks,
> jim
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tomcat-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tomcat-dev-help@jakarta.apache.org
>