Daniel could have written this a wee bit clearer.
It is indeed the struts request processor and not us that is doing the
wrapping.
The resulting HttpServletRequest (with implementing class of
org.apache.struts.upload.MultipartRequestWrapper) is always returning null
for getParameter() and an empty enumeration for getParameterNames().
(We ARE treating it like any other request - or would be if the code even
got as far as calling our action methods)

This of course kills our dispatch actions <!--Our dispatch action class is
actually a copy&paste job as I wanted to add some convienience methods to
all actions and got sick and tired trying to keep them synced between my
ActionBase and DispatchActionBase. It is just a copy of the dispatch action
in struts but inherits from my GTActionBase class which inherits from
Action, instead of inheriting directly from Action as the original does.-->
as they cannot find their method parameter... (It would also kill a lot of
our own code if execution could even get that far...) Switch the form back
to a normal form (as opposed to a multipart/form-data) enctype, and the
parameters will start working again.

btw: We *have* overridden the RequestProcessor with our own class that
inherits from the struts supplied RequestProcessor, but our class only
overrides the processActionForm() method (and even that delegates to the
super().processActionForm()) when it doesnt have to perform special
handling.
In the process of disagnosing this problem I have overriden
processMultipart() by copying and pasting the method into my request
processor class, and have added two println so I can see it detecting the
multipart nature of the request and choosing to use the wrapper (also moved
the {} to a _readable_ position ;->):

    protected HttpServletRequest processMultipart(HttpServletRequest
request)
    {
      System.out.println("processRequest():Request class=" +
request.getClass().getName()); //<--Added
      if (!"POST".equals(request.getMethod()))
      {
        return (request);
      }
      String contentType = request.getContentType();
      if ((contentType != null) &&
contentType.startsWith("multipart/form-data"))
      {
        System.out.println("Wrapping request with MultipartRequestWrapper");
// <-- Added
        return (new MultipartRequestWrapper(request));
      }
      else
      {
        System.out.println("Request is not for multipart/form-data"); // <--
Added
        return (request);
      }
    }


I added the following method to my DispatchAction superclass (yes - the
copy&pasted clone with funny inheritance):
  private void dumpRequest(HttpServletRequest request)
  {
    System.out.println("Request Class=" + request.getClass().getName());
    System.out.println("Request parameter
dump:-----------------------------");
    Enumeration params = request.getParameterNames();
    while(params.hasMoreElements())
    {
      String param = (String)params.nextElement();
      System.out.println(param + "=" + request.getParameter(param));
    }

System.out.println("----------------------------------------------------");
  }
I call this in the first line of perform() before the code (which is
identical to the _real_ dispatch action as its copied and pasted) excutes.
It is showing the request as having no parameters, a fact backed up by the
dispatch action code which fails as it cant find the method parameter, so
doesnt know which method in the subclass to call...

The full method is below: As you can see, only the dumpRequest() line is
different from the _real_ struts dispatch action. The if(name==null) check
returns true, thus causing the response.sendError() to be called. If the
form is not enctype="multipart/form-data" this check returns false, and the
appropriate method in the subclass will get called...

    /**
     * Process the specified HTTP request, and create the corresponding HTTP
     * response (or forward to another web component that will create it).
     * Return an <code>ActionForward</code> instance describing where and
how
     * control should be forwarded, or <code>null</code> if the response has
     * already been completed.
     *
     * @param mapping The ActionMapping used to select this instance
     * @param actionForm The optional ActionForm bean for this request (if
any)
     * @param request The HTTP request we are processing
     * @param response The HTTP response we are creating
     *
     * @exception IOException if an input/output error occurs
     * @exception ServletException if a servlet exception occurs
     */
    public ActionForward perform(ActionMapping mapping,
                 ActionForm form,
                 HttpServletRequest request,
                 HttpServletResponse response)
    throws IOException, ServletException {
dumpRequest(request);
        // Identify the request parameter containing the method name
        String parameter = mapping.getParameter();
        if (parameter == null) {
            String message =
                messages.getMessage("dispatch.handler", mapping.getPath());
            log.error(message);
            response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
                               message);
            return (null);
        }

        // Identify the method name to be dispatched to
        String name = request.getParameter(parameter);
        if (name == null) {
            String message =
                messages.getMessage("dispatch.parameter", mapping.getPath(),
                                    parameter);
            log.error(message);
            response.sendError(HttpServletResponse.SC_BAD_REQUEST,
                               message);
            return (null);
        }

        // Invoke the named method, and return the result
        return dispatchMethod(mapping,form,request,response,name);

    }

-----Original Message-----
From: Martin Cooper [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, July 16, 2002 12:11
To: 'Struts Users Mailing List'
Subject: RE: MultipartRequestWrapper.getParameter() not returning
anything


You shouldn't be doing any wrapping yourself - the use of the wrapper is
internal to Struts, and should be transparent to you. If you remove any of
your own code that's trying to use the wrapper (i.e. just assume it's a
normal request), things should start working.

--
Martin Cooper


> -----Original Message-----
> From: Daniel J. D'Cotta [mailto:[EMAIL PROTECTED]]
> Sent: Monday, July 15, 2002 8:58 PM
> To: Struts Users List
> Subject: MultipartRequestWrapper.getParameter() not returning anything
>
>
> Hi,
>
> I am using Struts 1.1-B1 with Tomcat 4.0.3.
>
> When I change my form enctype to 'multipart/form-data' and
> wrap the request
> into a MultipartRequestWrapper, the getParameter() and
> getParameterNames()
> are not returning any values at all.
>
> Has anyone encountered this problem before. Is there any work around?
>
>
> Regards,
> Daniel D'Cotta
>
> Ext: 212
>
>
> --
> To unsubscribe, e-mail:
<mailto:[EMAIL PROTECTED]>
For additional commands, e-mail:
<mailto:[EMAIL PROTECTED]>



--
To unsubscribe, e-mail:
<mailto:[EMAIL PROTECTED]>
For additional commands, e-mail:
<mailto:[EMAIL PROTECTED]>


--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to