Bug 43669

Summary: ApplicationDispatcher.unwrapRequest raises "cannot be cast to javax.servlet.ServletRequestWrapper"
Product: Tomcat 5 Reporter: Mailmur <mailmur>
Component: CatalinaAssignee: Tomcat Developers Mailing List <dev>
Severity: normal    
Priority: P2    
Version: 5.5.24   
Target Milestone: ---   
Hardware: Other   
OS: other   

Description Mailmur 2007-10-21 13:36:09 UTC
Tomcat 5.5.x:
  private void unwrapRequest(State state) {
    // Advance to the next request in the chain
    previous = current;
    current = ((ServletRequestWrapper) current).getRequest(); // !! CAST ERROR

Exception is thrown when request is forwarded:
  "com.outerrim.servlet.OfflineHttpServletRequest cannot be cast to 

This is my offlineHttpServletRequest and Response classes:
  public class OfflineHttpServletRequest implements HttpServletRequest { ... }
  public class OfflineHttpServletResponse implements HttpServletResponse { ... }

They provide me a way to call servlet urls without the real webclient requests.
This is used in a background thread, that must trigger "dispatcher.forward(req,
res)" method call.
   RequestDispatcher dispatcher = ctx.getRequestDispatcher(url);
   dispatcher.forward(offReq, offRes);

Classes work fine in Tomcat5.0.x releases. 

Is it really a new requirement, that customized classes must inherit
ServletRequestWrapper/ServletResponseWrapper classes?
Comment 1 Mailmur 2007-10-21 13:46:47 UTC

*** This bug has been marked as a duplicate of 39417 ***
Comment 2 Mailmur 2007-10-21 13:52:10 UTC
And to comment what happened to my forward.request. Yes, it worked fine and went
to the destination webapplication url. But then applicationdispatcher tries to
roll back to the caller, it fails due to a ClassCastException.