Vincent
I assume you mean getServletConfig() and not getConfig().

When I run the test with

String forwardURL = ("/WibbleWobble.jsp");
RequestDispatcher dispatcher =
getServletConfig().getServletContext().getRequestDispatcher( forwardURL );
dispatcher.forward(request, response );


I get the same error.
Is there no way around this using Tomcat 3.2 and I thus need to wait until a
patch fix

Jon



|--------+----------------------->
|        |          "Vincent     |
|        |          Massol"      |
|        |          <vmassol@octo|
|        |          .com>        |
|        |                       |
|        |          03/07/01     |
|        |          12:21        |
|        |          Please       |
|        |          respond to   |
|        |          "Vincent     |
|        |          Massol"      |
|        |                       |
|--------+----------------------->
  >----------------------------------------------------------------------------|
  |                                                                            |
  |       To:     Jon Belinfante/London/CWB@CWB,                               |
  |       [EMAIL PROTECTED]                                   |
  |       cc:                                                                  |
  |       Subject:     Re: Help  :: Problem testing Servlet methods that       |
  |       forward to JSPs                                                      |
  >----------------------------------------------------------------------------|




getConfig() is inherited from GenericServlet. If your class extends
HttpServlet, then it extends GenericServlet ...
-Vincent

----- Original Message -----
From: "Jon Belinfante" <[EMAIL PROTECTED]>
To: "Vincent Massol" <[EMAIL PROTECTED]>;
<[EMAIL PROTECTED]>
Sent: Tuesday, July 03, 2001 12:10 PM
Subject: Re: Help :: Problem testing Servlet methods that forward to JSPs


> Vincent
>
> You state use of line
>
> RequestDispatcher dispatcher =
> getConfig().getServletContext().getRequestDispatcher(forwardURL);
>
> From where do I get getConfig and getServletContext from with in the
Servlet
> code ?
>
> Cheers and thanks for the help.
> Jon
>
>
>
>
>
> |--------+----------------------->
> |        |          "Vincent     |
> |        |          Massol"      |
> |        |          <vmassol@octo|
> |        |          .com>        |
> |        |                       |
> |        |          03/07/01     |
> |        |          11:53        |
> |        |          Please       |
> |        |          respond to   |
> |        |          "Vincent     |
> |        |          Massol"      |
> |        |                       |
> |--------+----------------------->
>
>---------------------------------------------------------------------------
-|
>   |
|
>   |       To:     Jon Belinfante/London/CWB@CWB,
|
>   |       [EMAIL PROTECTED]
|
>   |       cc:
|
>   |       Subject:     Re: Help  :: Problem testing Servlet methods that
|
>   |       forward to JSPs
|
>
>---------------------------------------------------------------------------
-|
>
>
>
>
>
> ----- Original Message -----
> From: "Jon Belinfante" <[EMAIL PROTECTED]>
> To: <[EMAIL PROTECTED]>; "Vincent Massol"
> <[EMAIL PROTECTED]>
> Sent: Tuesday, July 03, 2001 11:12 AM
> Subject: Help :: Problem testing Servlet methods that forward to JSPs
>
>
> > I have a Servlet method that as follows that is meant to do no more then
> forward
> > to a test JSP page called WibbleWobble
> >
>
> --------------------------------------------------------------------------
> ---------------------------------------
> >
> >      protected void doPost(
> >           HttpServletRequest request,
> >           HttpServletResponse response)
> >                throws ServletException, java.io.IOException
> >      {
> >           System.out.println ("Starting : " +new Date());
> >           try
> >           {
> >
> >                String forwardURL = ("/WibbleWobble.jsp");
> >                RequestDispatcher dispatcher =
> request.getRequestDispatcher(
> > forwardURL );
> >           dispatcher.forward(request, response );
> >
>
>
> Ok, here is the story ... :)
>
> 1/ If you look at the Tomcat implementation (for Tomcat 3.x and before
> only - It is fixed for later version as they had to fix this to support
> Servlet 2.3 Filters), you'll see that the forward() and include() methods
do
> a cast of the request object to their own internal object. As the Request
> wrapper does not implement this internal object, it fails.
>
> 2/ The solution I have found for this was to wrap the Servlet Context. But
> in order to wrap the servlet context I also had to wrap the Config object.
> So that config.getServletContext() would return the wrapped context and
then
> config.getServletContext().getRequestDispatcher() would return the wrapped
> dispatcher. Thus when you would call forward() or include() on that
wrapped
> dispatcher it would actually pass the *original* request to the real
> dispatcher foward() or include() method !
>
> 3/ Apparently I have forgotten that there is another way to get a request
> dispatcher ! Through the request, like request.getDispatcher() ! This is a
> bug which has *not* been corrected. I'll correct it asap. In the meantime,
> you can use the following, which will work (as evidenced in the Cactus
suite
> of tests) :
>
> String forwardURL = ("/WibbleWobble.jsp");
> RequestDispatcher dispatcher =
> getConfig().getServletContext().getRequestDispatcher(forwardURL);
> dispatcher.forward(request, response );
>
> Note that you will need to have an init in your test method so that
> getConfig() returns the wrapped config object (as you were already doing)
:
>
> SecurityServlet servlet = new SecurityServlet();
> servlet.init(config); <-- needed
> servlet.doPost( request, response );
>
> Thanks to both of you for this bug discovery and sorry Jari, I have
probably
> skipped your mail that already mentionned that problem (or maybe I simply
> did not understand the issue at that time) ... I'll correct it quickly ...
>
> -Vincent
>
>
>
>
>
>





Reply via email to