[
http://www.stripesframework.org/jira/browse/STS-857?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
John Newman updated STS-857:
----------------------------
Attachment: STS-857.patch
Improved patch. I wasn't aware of the catch block further up the call stack.
sample usage:
public class ActionBeanPropertyBinder extends DefaultActionBeanPropertyBinder {
@Override
protected void handlePropertyBindingError(ActionBean bean,
ParameterName name, List<Object> values, Exception e,
ValidationErrors errors) {
if (e instanceof StaleDataException) {
throw (StaleDataException) e;
} else if (e instanceof RecordDeletedException) {
throw (RecordDeletedException) e;
} else {
super.handlePropertyBindingError(bean, name, values, e,
errors);
}
}
@Override
protected void handlePropertyConversionError(Exception e, ActionBean
bean,
ParameterName propertyName, String[] values, String
value,
Class<?> declaredType, Class<?> scalarType,
ValidationMetadata validationInfo,
List<ValidationError> errors,
List<Object> returns, TypeConverter<?> converter,
TypeConverterFactory factory, Locale locale) {
if (e instanceof StaleDataException) {
throw (StaleDataException) e;
} else if (e instanceof RecordDeletedException) {
throw (RecordDeletedException) e;
} else {
super.handlePropertyConversionError(e, bean,
propertyName, values,
value, declaredType, scalarType,
validationInfo, errors,
returns, converter, factory, locale);
}
}
}
Now those two exception types can get caught by an exception handler and dealt
with appropriately, instead of just logging a warning.
> DefaultActionPropertyBinder - type conversion exceptions are just logged as a
> warning, should optionally be rethrown
> --------------------------------------------------------------------------------------------------------------------
>
> Key: STS-857
> URL: http://www.stripesframework.org/jira/browse/STS-857
> Project: Stripes
> Issue Type: Improvement
> Components: Validation
> Affects Versions: Release 1.5.6
> Reporter: John Newman
> Attachments: STS-857.patch, STS-857.patch
>
>
> DefaultActionBeanPropertyBinder
> line 730
> protected List<Object> convert(ActionBean bean, ParameterName
> propertyName, String[] values,
> Class<?> declaredType, Class<?> scalarType,
> ValidationMetadata validationInfo,
> List<ValidationError> errors) {
> // huge method
> line 781
> try {
> // huge try block
> }
> line 810
> catch (Exception e) {
> log.warn(e, "Looks like type converter ", converter, "
> threw an exception.");
> }
> Well, that isn't what I expected. If a type converter has a defect and is
> throwing exceptions all over the place, I would like to know about it through
> the ExceptionHandler. Logging a warning is fine, but I'd like to have it
> rethrown right there. In the spirit of backwards compatibility it might be
> better to have an optional hook,
> protected void handleTypeConverterException(ActionBean bean, ParameterName
> propertyName, String[] values,
> Class<?> declaredType, Class<?> scalarType,
> ValidationMetadata validationInfo,
> List<ValidationError> errors, Exception e) {
> // subclass this
> }
>
> here I could wire in my own code to wrap in a RuntimeException and rethrow
> [or whatever]. In my case I am _trying to throw a checked exception from a
> type converter, and hoping it will get caught by the ExceptionHandler which
> will then take care of it properly. But I can't get anything besides a
> warning in the log.
> And in general, this binder class is really not very subclassable. There's
> mostly just very long methods (..that were declared as protected .. not
> private), and there's no real usable hooks for a subclass to come in and
> customize small aspects of its behavior. And if you think about it, this
> would be one of the more valuable classes to be able to customize, but you
> can't do it unless you're comfortable lifting large chunks of code from the
> superclass.
> A patch for the exception hook is attached... i'd like to continue on
> breaking this class up into more manageable chunks. Any thoughts?
--
This message is automatically generated by JIRA.
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
------------------------------------------------------------------------------
RSA(R) Conference 2012
Save $700 by Nov 18
Register now
http://p.sf.net/sfu/rsa-sfdev2dev1
_______________________________________________
Stripes-development mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/stripes-development