Sorry, Samuel. I meant to respond earlier today.
FileUploadExceededException is exceptional (no put intended) in that it
can be thrown during the construction of the StripesRequestWrapper
itself. Since the wrapper isn't created correctly, we can't pass it to
the exception handler. Just about any other exception would occur after
successful construction of the wrapper, and in those cases you would get
the wrapper in your handler.
I don't know why you would be getting an exception when trying to flash
a bean. Can you give us a stack trace?
-Ben
Samuel Santos wrote:
Any on this issue?
I'm working with revision 910.
On Sun, May 18, 2008 at 3:17 AM, Samuel Santos <[EMAIL PROTECTED]
<mailto:[EMAIL PROTECTED]>> wrote:
I use Stripes 1.5beta and the bug
http://stripesframework.org/jira/browse/STS-402 still happens.
Using Ben hack to handle the FileUploadLimitExceededException:
public Resolution handle(FileUploadLimitExceededException
exception, HttpServletRequest request,
HttpServletResponse response) throws ServletException,
IOException {
/*
* 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.
*/
// start of hack
// wrap the request without handling multipart data
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);
}
};
// end of hack
// 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();
PVoucherActionBeanContext context = (MyActionBeanContext)
config.getActionBeanContextFactory()
.getContextInstance(request, response);
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).flash(actionBean);
}
still crashes when flashing the action bean!
Isn't there a better way to handle this exception with Stripes 1.5?
Cheers,
Samuel
--
Samuel Santos
http://www.samaxes.com/
--
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