You said you have handle(FileUPloadExcceded) in DelegatingExceptionHandler ...

Take a look at its parent class DefaultExceptionHandler  - you are overriding 
this:

    /**
     * <p>
     * {...@link FileUploadLimitExceededException} is notoriously difficult to 
handle for several
     * reasons:
     * <ul>
     * <li>The exception is thrown during construction of the {...@link 
StripesRequestWrapper}. Many
     * Stripes components rely on the presence of this wrapper, yet it cannot 
be created normally.</li>
     * <li>It happens before the request lifecycle has begun. There is no 
{...@link ExecutionContext},
     * {...@link ActionBeanContext}, or {...@link ActionBean} associated with 
the request yet.</li>
     * <li>None of the request parameters in the POST body can be read without 
risking denial of
     * service. That includes the {...@code _sourcePage} parameter that 
indicates the page from which
     * the request was submitted.</li>
     * </ul>
     * </p>
     * <p>
     * This exception handler makes an attempt to handle the exception as 
gracefully as possible. It
     * relies on the HTTP Referer header to determine where the request was 
submitted from. It uses
     * introspection to guess the field name of the {...@link FileBean} field 
that exceeded the POST
     * limit. It instantiates an {...@link ActionBean} and {...@link 
ActionBeanContext} and adds a
     * validation error to report the field name, maximum POST size, and actual 
POST size. Finally,
     * it forwards to the referer.
     * </p>
     * <p>
     * While this is a best effort, it won't be ideal for all situations. If 
this method is unable
     * to handle the exception properly for any reason, it rethrows the 
exception. Subclasses can
     * call this method in a {...@code try} block, providing additional 
processing in the {...@code catch}
     * block.
     * </p>
     * <p>
     * A simple way to provide a single, global error page for this type of 
exception is to override
     * {...@link #getFileUploadExceededExceptionPath(HttpServletRequest)} to 
return the path to your
     * global error page.
     * <p>
     * 
     * @param exception The exception that needs to be handled
     * @param request The servlet request
     * @param response The servlet response
     * @return A {...@link Resolution} to forward to the path returned by
     *         {...@link 
#getFileUploadExceededExceptionPath(HttpServletRequest)}
     * @throws FileUploadLimitExceededException If
     *             {...@link 
#getFileUploadExceededExceptionPath(HttpServletRequest)} returns null or
     *             this method is unable for any other reason to forward to the 
error page
     */
    protected Resolution handle(FileUploadLimitExceededException exception,
            HttpServletRequest request, HttpServletResponse response)
            throws FileUploadLimitExceededException {
        // Get the path to which we will forward to display the message
        final String path = getFileUploadExceededExceptionPath(request);
        if (path == null)
            throw exception;

        final StripesRequestWrapper wrapper;
        final ActionBeanContext context;
        final ActionBean actionBean;
        try {
            // Create a new request wrapper, avoiding the pitfalls of multipart
            wrapper = new StripesRequestWrapper(request) {
                @Override
                protected void constructMultipartWrapper(HttpServletRequest 
request)
                        throws StripesServletException {
                    
setLocale(configuration.getLocalePicker().pickLocale(request));
                }
            };

            // Create the ActionBean and ActionBeanContext
            context = 
configuration.getActionBeanContextFactory().getContextInstance(wrapper,
                    response);
            actionBean = 
configuration.getActionResolver().getActionBean(context);
            wrapper.setAttribute(StripesConstants.REQ_ATTR_ACTION_BEAN, 
actionBean);
        }
        catch (ServletException e) {
            log.error(e);
            throw exception;
        }

        // Try to guess the field name by finding exactly one FileBean field
        String fieldName = null;
        try {
            BeanInfo beanInfo = Introspector.getBeanInfo(actionBean.getClass());
            for (PropertyDescriptor pd : beanInfo.getPropertyDescriptors()) {
                if (FileBean.class.isAssignableFrom(pd.getPropertyType())) {
                    if (fieldName == null) {
                        // First FileBean field found so set the field name
                        fieldName = pd.getName();
                    }
                    else {
                        // There's more than one FileBean field so don't use a 
field name
                        fieldName = null;
                        break;
                    }
                }
            }
        }
        catch (Exception e) {
            // Not a big deal if we can't determine the field name
        }

        // Add validation error with parameters for max post size and actual 
posted size (KB)
        DecimalFormat format = new DecimalFormat("0.00");
        double max = (double) exception.getMaximum() / 1024;
        double posted = (double) exception.getPosted() / 1024;
        LocalizableError error = new 
LocalizableError("validation.file.postBodyTooBig", format
                .format(max), format.format(posted));
        if (fieldName == null)
            context.getValidationErrors().addGlobalError(error);
        else
            context.getValidationErrors().add(fieldName, error);

        // Create an ExecutionContext so that the validation errors can be 
filled in
        ExecutionContext exectx = new ExecutionContext();
        exectx.setActionBean(actionBean);
        exectx.setActionBeanContext(context);
        DispatcherHelper.fillInValidationErrors(exectx);

        // Forward back to referer, using the wrapped request
        return new ForwardResolution(path) {
            @Override
            public void execute(HttpServletRequest request, HttpServletResponse 
response)
                    throws ServletException, IOException {
                super.execute(wrapper, response);
            }
        };
    }

    /**
     * Get the path to which the {...@link Resolution} returned by
     * {...@link #handle(FileUploadLimitExceededException, HttpServletRequest, 
HttpServletResponse)}
     * should forward to report the error. The default implementation attempts 
to determine this
     * from the HTTP Referer header. If it is unable to do so, it returns null. 
Subclasses may
     * override this method to return whatever they wish. The return value must 
be relative to the
     * application context root.
     * 
     * @param request The request that generated the exception
     * @return The context-relative path from which the request was submitted
     */
    protected String getFileUploadExceededExceptionPath(HttpServletRequest 
request) {
        // Get the referer URL so we can bounce back to it
        URL referer = null;
        try {
            referer = new URL(request.getHeader("referer"));
        }
        catch (Exception e) {
            // Header not found? Invalid? Can't do anything with it :(
            return null;
        }

        // Convert the referer path to a context-relative path
        String path = referer.getFile();
        String contextPath = request.getContextPath();
        if (contextPath.length() > 1) {
            // We can't handle it if the POST came from outside our app
            if (!path.startsWith(contextPath + "/"))
                return null;

            path = path.replace(contextPath, "");
        }

        return path;
    }


-----Original Message-----
From: Krzysztof Osiecki [mailto:rome...@gmail.com] 
Sent: Monday, April 20, 2009 7:16 AM
To: stripes-users@lists.sourceforge.net
Subject: Re: [Stripes-users] Large file upload does not stop after 
FileUploadLimitExceededException

misok <michal.kos...@...> writes:
> When I try to handle FileUploadLimitExceededException the user is not
> redirected to the error page until the file is not fully uploaded.

That's the way HTTP works. When sending data to server you are forming request, 
and after successfully recieving your data server responds.

The solution is to use flash or applet to upload files, that way you can force 
client side not to send too much data to server.


------------------------------------------------------------------------------
Stay on top of everything new and different, both inside and 
around Java (TM) technology - register by April 22, and save
$200 on the JavaOne (SM) conference, June 2-5, 2009, San Francisco.
300 plus technical and hands-on sessions. Register today. 
Use priority code J9JMT32. http://p.sf.net/sfu/p
_______________________________________________
Stripes-users mailing list
Stripes-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/stripes-users

------------------------------------------------------------------------------
Stay on top of everything new and different, both inside and 
around Java (TM) technology - register by April 22, and save
$200 on the JavaOne (SM) conference, June 2-5, 2009, San Francisco.
300 plus technical and hands-on sessions. Register today. 
Use priority code J9JMT32. http://p.sf.net/sfu/p
_______________________________________________
Stripes-users mailing list
Stripes-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/stripes-users

Reply via email to