Good morning, Samuel. We decided that since FULEE is so difficult to deal with that we should provide some code in Stripes itself to deal with it the best we can. I have added some code to DefaultExceptionHandler that specifically handles FULEE in a way very similar to what you have done. (Which was derived from a class called FULEECatcher that I posted to the list a long time ago.)

Here's what I need you to do now. Remove your FULEE handler and throw it away. Make sure your StripesResources.properties gets the new entry for "validation.file.postBodyTooBig" that has been added to the default StripesResources.properties. Behold the glory (hopefully). :-)

All the drawbacks previously noted still apply. Form repopulation will not work. No parameters (except clean URL params) will be available. But at least you'll be able to tell them what went wrong in a nice way.

If you want, you can extend DefaultExceptionHandler and override getFileUploadLimitExceededExceptionPath(HttpServletRequest) to return a path to a global JSP to report this error instead of having it forward back to the page that it was submitted from.

Please let me know if this works for you or not.

-Ben

Ben Gunter wrote:
Yes, it should. I think I know what's going on, and I'm working on something to address this. I'll get back to you later tonight or tomorrow morning (EDT) about it.

-Ben

Samuel Santos wrote:
But shouldn't it at least show the error message?


On Tue, May 20, 2008 at 7:06 PM, Ben Gunter <[EMAIL PROTECTED] <mailto:[EMAIL PROTECTED]>> wrote:

    Unfortunately, this is as good as it gets. Take a look at this
    thread for more information.

    http://article.gmane.org/gmane.comp.java.stripes.user/1079

    -Ben

    Samuel Santos wrote:
    Thanks Ben for your help, but unfortunately it doesn't work as
    expected.

    It redirects correctly to the form page but loses all the form
    values and error messages.

    My handle code:
        public Resolution handle(FileUploadLimitExceededException
    exception, HttpServletRequest request,
                HttpServletResponse response) throws
    ServletException, IOException {
            LOGGER.warn(exception.getMessage());

            /*
             * This is a hack from Ben Gunter received in the
    Stripes forum. It is related to Jira issue:
             * http://stripes.mc4j.org/jira/browse/STS-402. The
    problem is that when the exception handler is called, it
             * always receives the original request passed to the
    StripesFilter and not the wrapped request. That prevents
             * construction of the FlashScope in which we need to
    store the error message.
             */
            final StripesRequestWrapper wrapper = new
    StripesRequestWrapper(request) {
                /**
                 * Ignore multipart content and set the locale at
    the same time.
                 *
                 * @param request the HTTP request to wrap.
                 */
                @Override
                protected void
    constructMultipartWrapper(HttpServletRequest request) throws
    StripesServletException {
                    Locale locale =
    StripesFilter.getConfiguration().getLocalePicker().pickLocale(request);
                    setLocale(locale);
                }
            };

            // get referer URL
            URL referer = null;
            try {
                referer = new URL(request.getHeader("referer"));
            } catch (Exception e) {
                throw exception;
            }

            // convert referer path to context-relative path
            String path = referer.getFile();
            String contextPath = request.getContextPath();
            if (contextPath.length() > 0) {
                if (!path.startsWith(contextPath + "/"))
                    throw exception;
                path = path.replace(contextPath, "");
            }

            // create action bean and context
            Configuration config = StripesFilter.getConfiguration();
            final PVoucherActionBeanContext context =
    (PVoucherActionBeanContext) config.getActionBeanContextFactory()
                    .getContextInstance(request, response);
            final ActionBean actionBean =
    config.getActionResolver().getActionBean(context);

            // try to guess the field name
            String fieldName = ValidationErrors.GLOBAL_ERROR;
            try {
                BeanInfo beanInfo =
    Introspector.getBeanInfo(actionBean.getClass());
                for (PropertyDescriptor pd :
    beanInfo.getPropertyDescriptors()) {
                    if (pd.getPropertyType().equals(FileBean.class)) {
                        fieldName = pd.getName();
                        break;
                    }
                }
            } catch (Throwable t) {
            }

            // add validation error
            DecimalFormat format = new DecimalFormat("0.00");
            double max = (double) exception.getMaximum() / 1024;
            double posted = (double) exception.getPosted() / 1024;
            context.getValidationErrors().add(fieldName,
                    new LocalizableError("error.file.too.large",
    format.format(max), format.format(posted)));

            // redirect back to referer
            return new RedirectResolution(path) {
                @Override
                public void execute(HttpServletRequest request,
    HttpServletResponse response) throws ServletException,
                        IOException {
                    ExecutionContext executionContext = new
    ExecutionContext();
                    executionContext.setActionBean(actionBean);
                    executionContext.setActionBeanContext(context);
DispatcherHelper.fillInValidationErrors(executionContext);
                    super.execute(wrapper, response);
                }
            }.flash(actionBean);
        }

    --
    Samuel


    On Tue, May 20, 2008 at 5:15 PM, Ben Gunter <[EMAIL PROTECTED]
    <mailto:[EMAIL PROTECTED]>> wrote:

        You are creating the hacked up StripesRequestWrapper, but
        you're never using it. Also, we changed how localizable
        messages are looked up and that would cause an NPE with the
        code you have. I've done a little more hacking on it, and
        the following code will work if you make the wrapper final.

                    // redirect back to referer
                    return new RedirectResolution(path) {
                        @Override
                        public void execute(HttpServletRequest request, 
HttpServletResponse response)
                                throws ServletException, IOException {
                            ExecutionContext exec = new ExecutionContext();
                            exec.setActionBean(actionBean);
                            exec.setActionBeanContext(context);
                            DispatcherHelper.fillInValidationErrors(exec);
                            super.execute(wrapper, response);
                        }
                    }.flash(actionBean);

        -Ben

        
-------------------------------------------------------------------------
        This SF.net email is sponsored by: Microsoft
        Defy all challenges. Microsoft(R) Visual Studio 2008.
        http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
        _______________________________________________
        Stripes-users mailing list
        [email protected]
        <mailto:[email protected]>
        https://lists.sourceforge.net/lists/listinfo/stripes-users




-- Samuel Santos
    http://www.samaxes.com/
    ------------------------------------------------------------------------
    -------------------------------------------------------------------------
    This SF.net email is sponsored by: Microsoft Defy all
    challenges. Microsoft(R) Visual Studio 2008.
    http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
    ------------------------------------------------------------------------

    _______________________________________________
    Stripes-users mailing list
    [email protected] 
<mailto:[email protected]>
    https://lists.sourceforge.net/lists/listinfo/stripes-users

    -------------------------------------------------------------------------
    This SF.net email is sponsored by: Microsoft
    Defy all challenges. Microsoft(R) Visual Studio 2008.
    http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
    _______________________________________________
    Stripes-users mailing list
    [email protected]
    <mailto:[email protected]>
    https://lists.sourceforge.net/lists/listinfo/stripes-users




--
Samuel Santos
http://www.samaxes.com/
------------------------------------------------------------------------

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008. http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
------------------------------------------------------------------------

_______________________________________________
Stripes-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/stripes-users
------------------------------------------------------------------------

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008. http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
------------------------------------------------------------------------

_______________________________________________
Stripes-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/stripes-users
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft 
Defy all challenges. Microsoft(R) Visual Studio 2008. 
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Stripes-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/stripes-users

Reply via email to