Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Request is not of javax.servlet.ServletRequestWrapper type

4 views
Skip to first unread message

Nick Boyce

unread,
May 24, 2005, 9:40:11 PM5/24/05
to
I've coded up a custom "processPreprocess" hook for a Struts
application we're writing on a Websphere platform - the hook being
designed to run at the start of every interaction (request) and detect
when the user's session has timed out.

This works fine for every screen in the application, *except* the one
screen which allows the user to do a file-upload (i.e. enctype =
multipart/form-data) - if I let the session time out on this screen
then the following exception is reported :

==========================< cut >===========================
[24/05/05 21:26:12:977 GMT] 883980a WebGroup I SRVE0180I:
[APCUpload]
[/APCUpload] [Servlet.LOG]: /errorPage.jsp: init
[24/05/05 21:26:12:977 GMT] 883980a WebGroup I SRVE0181I:
[APCUpload]
[/APCUpload] [Servlet.LOG]: JspFactoryImpl: Exception initializing
page
context: java.lang.IllegalArgumentException: Request is not of
javax.servlet.ServletRequestWrapper type
at
com.ibm.ws.webcontainer.webapp.WebAppDispatcherRequest.getWASProxiedHttpServ
letRequest(WebAppDispatcherRequest.java:155)
at
com.ibm.ws.webcontainer.webapp.WebAppDispatcherRequest.getSession(WebAppDisp
atcherRequest.java:234)
at
com.ibm.ws.webcontainer.webapp.WebAppDispatcherRequest.getSession(WebAppDisp
atcherRequest.java:219)
at
org.apache.jasper.runtime.PageContextImpl._initialize(PageContextImpl.java:1
40)
at
org.apache.jasper.runtime.PageContextImpl.initialize(PageContextImpl.java:11
6)
at
org.apache.jasper.runtime.JspFactoryImpl.internalGetPageContext(JspFactoryIm
pl.java:225)
at
org.apache.jasper.runtime.JspFactoryImpl.getPageContext(JspFactoryImpl.java:
190)
at org.apache.jsp._errorPage._jspService(_errorPage.java:103)
etc., etc.
==========================< cut >===========================

I have been unable to find any explanation of what this exception
actually means, or how to fix the problem. I'd be very grateful for
any light anyone can shed.

Here's the source code for the hook :

==========================< cut >===========================
public class APCRequestProcessor extends RequestProcessor {

/**
* <!-- Method processPreprocess -->
*
* <P>If the user's session has timed out, forward them to the
* error page so that the message "Sorry - your session has timed out"
* can be displayed.</P>
*
* @see
org.apache.struts.action.RequestProcessor#processPreprocess(HttpServletReque
st, HttpServletResponse)
* @see
http://www.onjava.com/pub/a/onjava/2004/11/10/ExtendingStruts.html?page=last
&x-order=date
*
*/

protected boolean processPreprocess
( HttpServletRequest request,
HttpServletResponse response )
{
boolean standardProcessRequired = true;

if ( request.getServletPath().equals("/securityAction.do") ) {
// User is trying to login ..... let them continue.
return true;
}
if ( request.getServletPath().equals("/errorPage.jsp") ) {
// About to display the error page ..... continue.
return true;
}

// check for session timeout :
// look for a userBean for the logged in user in
// the session data :
HttpSession session = request.getSession(true);
UserBean loggedInUser =
(UserBean)session.getAttribute(Beans.USER_LOGGED_IN);
if ( loggedInUser == null ) {
System.out.println("timeout detected (no logged-in user)");
try {

request.getRequestDispatcher("errorPage.jsp").forward(request,response);
standardProcessRequired = false;
} catch (Exception e) {
String msg = "APCRequestProcessor: Exception "
+ e.toString() +
" caught while forwarding to error page";
System.out.println(msg);
}
}

return standardProcessRequired;
}
}
==========================< cut >===========================

TIA
Nick Boyce
Bristol,UK
--
The irony is that Bill Gates claims to be making a stable operating
system and Linus Torvalds claims to be trying to take over the world.
-- seen on the net

Andrea Desole

unread,
May 25, 2005, 4:03:23 AM5/25/05
to

I don't know how Struts hooks work, but I find interesting this mix of
Jasper and WebSphere in the same stack. It looks strange that IBM uses
Jasper to compile its pages.
Also, I don't see anything in your code that can change the request; I
just see a few getters.
Did you try to load the jsp without hook?

Nick Boyce

unread,
May 25, 2005, 8:39:51 AM5/25/05
to
Andrea Desole wrote:

> I don't know how Struts hooks work, but I find interesting this mix of
> Jasper and WebSphere in the same stack. It looks strange that IBM uses
> Jasper to compile its pages.

Sorry - I can't comment on any use IBM makes of Jasper - that's all
internal to Websphere, and hidden from me. FWIW we're using WebSphere
Studio Enterprise Developer V5.0.0 on WinXP - that's the IDE, and the
web app server (J2EE container), all in one.

> Also, I don't see anything in your code that can change the request; I
> just see a few getters.

The idea is not to get involved in /changing/ the request (if you mean
the URI that is) - just to forward the user to a new JSP, instead of
passing the request on to the action class that it would normally hit.
I appreciate though that it looks as if I may need to fiddle with the
request metadata, to change its "type" (whatever that is) to
javax.servlet.ServletRequestWrapper.

I've tried adding each of the following calls:
request = processMultipart(request);
response.setContentType("text/html");
response.reset();
(without having any clear idea that they're needed) but this made no
difference at all.

The WWW page I got the idea from suggested that this call:

request.getRequestDispatcher("errorPage.jsp").forward(request,response);
is all that's needed.
See
http://www.onjava.com/pub/a/onjava/2004/11/10/ExtendingStruts.html?page=last&x-order=date

> Did you try to load the jsp without hook?

Well ... yes ... that's the way the whole app was before I wrote the
hook. Everything works fine without the hook. My other colleagues are
all running the same code as me, without the hook. It's just that we
want to be able to detect session timeout due to inactivity, which
means we need to plug in at some point while processing every incoming
request, to see whether Websphere has invalidated the user's session
since their last interaction. The Struts "processPreprocess" hook gets
called at the start of processing for every incoming request - it
should return a boolean indicating whether or not to hand the request
on in to the app for any further processing by the rest of the system.

Cheers,
Nick

Andrea Desole

unread,
May 25, 2005, 9:21:56 AM5/25/05
to

Nick Boyce wrote:
>
> Sorry - I can't comment on any use IBM makes of Jasper - that's all
> internal to Websphere, and hidden from me. FWIW we're using WebSphere
> Studio Enterprise Developer V5.0.0 on WinXP - that's the IDE, and the
> web app server (J2EE container), all in one.

apparently you are right. Surprisingly, I would say (surprisingly IBM is
using Jasper, I mean :-))

>
> The idea is not to get involved in /changing/ the request (if you mean
> the URI that is) - just to forward the user to a new JSP, instead of
> passing the request on to the action class that it would normally hit.
> I appreciate though that it looks as if I may need to fiddle with the
> request metadata, to change its "type" (whatever that is) to
> javax.servlet.ServletRequestWrapper.

Well, what I was thinking is that somewhere someone is changing it to a
class that is now ServletRequestWrapper. The problem is where.
What is possible is that Struts is doing it. Maybe you are getting a
wrong request type in the hook and then forwarding it to the jsp, or
something similar. Try to add a line to the error jsp page to write the
type of the request, and then load it with and without hook. In that way
you can know if the hook or something else is changing the request type.
And maybe you can check in a debugger what type the request in the hook is.

>
> Well ... yes ... that's the way the whole app was before I wrote the
> hook. Everything works fine without the hook. My other colleagues are
> all running the same code as me, without the hook. It's just that we
> want to be able to detect session timeout due to inactivity, which
> means we need to plug in at some point while processing every incoming
> request, to see whether Websphere has invalidated the user's session
> since their last interaction. The Struts "processPreprocess" hook gets
> called at the start of processing for every incoming request - it
> should return a boolean indicating whether or not to hand the request
> on in to the app for any further processing by the rest of the system.

how about a servlet filter?

Nick

unread,
May 25, 2005, 8:40:22 PM5/25/05
to
On Wed, 25 May 2005 15:21:56 +0200, Andrea Desole
<ne...@desole.demon.NO.SPAM.PLEASE.nl> wrote:

> Well, what I was thinking is that somewhere someone is changing it to a
> class that is now ServletRequestWrapper. The problem is where.
> What is possible is that Struts is doing it. Maybe you are getting a
> wrong request type in the hook and then forwarding it to the jsp, or
> something similar. Try to add a line to the error jsp page to write the
> type of the request, and then load it with and without hook. In that way
> you can know if the hook or something else is changing the request type.
> And maybe you can check in a debugger what type the request in the hook is.

You were right - it seems Struts presents the request as a
MultipartRequestWrapper object when the request is a file upload.
This object is an extension of ServletRequestWrapper.

I've solved the problem now, but putting this code in :

HttpServletRequest req;
if(requestType.equalsIgnoreCase(
"org.apache.struts.upload.MultipartRequestWrapper") ) {
req = ((MultipartRequestWrapper)request).getRequest();
} else {
req = request;
}

The call to getRequest() returns the underlying object, and all now
works as desired.

> how about a servlet filter?

I've seen that a lot of people use a filter for this purpose - I'll
look into the idea when I have some more time.

Thanks for your help.

Nick Boyce
Bristol,UK
--
"... the fundamental design flaws are completely hidden by the
superficial design flaws."
Douglas Adams(1952 - 2001): So Long and Thanks For All The Fish.

Andrea Desole

unread,
May 26, 2005, 4:49:37 AM5/26/05
to

Nick wrote:
> You were right - it seems Struts presents the request as a
> MultipartRequestWrapper object when the request is a file upload.
> This object is an extension of ServletRequestWrapper.

then I don't understand why websphere is complaining.

>
> I've solved the problem now, but putting this code in :
>
> HttpServletRequest req;
> if(requestType.equalsIgnoreCase(
> "org.apache.struts.upload.MultipartRequestWrapper") ) {
> req = ((MultipartRequestWrapper)request).getRequest();
> } else {
> req = request;
> }
>
> The call to getRequest() returns the underlying object, and all now
> works as desired.

fair enough. You are assuming here something about the implementation of
struts, which is not great, but I guess you have no other solution.

>
> I've seen that a lot of people use a filter for this purpose - I'll
> look into the idea when I have some more time.

servlet filters are pretty easy; the only question is if you can
forward. But I think you can

>
> Thanks for your help.

you are welcome!

0 new messages