You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Craig McClanahan <cr...@gmail.com> on 2004/10/27 18:09:21 UTC

Re: overriding MultipartRequestWrapper class

Hmm ... looks like RequestProcessor.processMultipart() always uses a
MultipartRequestWrapper if the content type is "multipart/form-data". 
The controller setting you are trying to change sets the
MultipartHandler class, not the request wrapper class.

One could argue that the wrapper class ought to be pluggable as well
(if you believe so, the best thing would be to submit an enhancement
request into http://issues.apache.org/bugzilla/).  In the mean time,
one thing you can do is use the getRequest() method of each wrapper,
and walk up the chain of wrappers to find the one you want.  Something
like:

    MySpecialRequest myRequest = null;
    if (request instanceof MySpecialRequest) {
        myRequest = (MySpecialRequest) request;
    } else if (request instance of HttpServletRequestWrapper) {
        HttpServletRequestWrapper wrapper = (HttpServletRequestWrapper) request;
        while (wrapper != null) {
            if (wrapper instanceof MySpecialRequest) {
                myRequest = (MySpecialRequest) wrapper;
                break;
            }
            wrapper = (HttpServletRequestWrapper) wrapper.getRequest();
        }
    }

You'll run into problems if for some reason your wrapped request isn't
in the stack, so you might put some extra error checking in for that
... but something along these lines should get you access to the
special things in your wrapper.

Craig

On Wed, 27 Oct 2004 12:45:49 +0300, Seyhan Basmaci <sb...@teb.com.tr> wrote:
> 
> We are decorating each request object for our requirements.
> 
>     MySpecialRequest customReq=  MySpecialRequest(request);
> 
> Also , MySpecialRequest extends HttpRequest
> 
> If the content type is  multipart/form-data ,also struts decorates  our request object in
> processMultipart method and returns an instance of "MultipartRequestWrapper" class.
> Then our code fall into "ClassCastException" error.
>  (  MySpecialRequest req=  (MySpecialRequest) request;  )
> 
> to override this problem;
> 
> firstly,in struts-config.xml , I added  MultipartClass class definiton,
> <controller MultipartClass="com.internet.common.util.MyServletRequestWrapper" >
> 
> later, I changed superClass of my "MySpecialRequest" class as such below ;
> MySpecialRequest extends MultipartRequestWrapper
> 
> but, struts still returns an instance of  MultipartRequestWrapper,, my code still fails..
> 
> any idea or solution to this problem ???
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
> 
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org