Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhance bean invoking action to provide built-in exception handling support [SWF-321] #170

Open
spring-operator opened this issue Jun 6, 2007 · 3 comments

Comments

@spring-operator
Copy link
Contributor

spring-operator commented Jun 6, 2007

nebhale opened SWF-321 and commented

Currently, if an exception is thrown as a result of invoking a bean invoking action, the exception propagates back to the flow and the flow is expected to respond to the exception using either an exception handler typically or by declaring an on exception transition. This works fine but generally requires transition to a intermediate state to map the exception onto a set of error validation methods. Either that or the view must translate the exception to error messages. It would be nice if the bean invoking action itself could handle the exception, record suitable validation error messages and return a result that could be handled by the flow. This would make exception handling simpler from the flow definition point of view and build in alert creation.

For example before this feature you'd do this:

<action-state id="changeBeneficiaryAllocations">
<bean-action bean="accountManager" method="updateBeneficiaryAllocationPercentages">
<method-arguments>
<argument expression="flowScope.accountId" />
<argument expression="requestScope.allocationPercentages" />
</method-arguments>
</bean-action>
<transition on="success" to="editBeneficiaries" />
<transition on-exception="accounts.InvalidAllocationException" to="generateErrorMessages"/>
</action-state>

after you'd do this:

<action-state id="changeBeneficiaryAllocations">
<bean-action bean="accountManager" method="updateBeneficiaryAllocationPercentages">
<method-arguments>
<argument expression="flowScope.accountId" />
<argument expression="requestScope.allocationPercentages" />
</method-arguments>
</bean-action>
<transition on="success" to="editBeneficiaries" />
<!-- Error message generated automatically -->
<transition on="invalidAllocation" to="enterNewBeneficiaryAllocations"/>
</action-state>


Affects: 1.0.3

Issue Links:

1 votes, 2 watchers

@spring-operator
Copy link
Contributor Author

Erwin Vervaet commented

I'm not sure about this.
Using an on-exception transition seems to be pretty elegant and most people are happy with it.

@spring-operator
Copy link
Contributor Author

Keith Donald commented

Using transition on-exception is no doubt elegant and powerful. However, it's arguably redundant when all you want to do is map the exception to an error message and logical error outcome, then redisplay a view. Having to implement this same control flow logic over and over again for every call into the service-layer that throws a checked exception results in duplication. It seems we have a natural opportunity to encapsulate some of this inside the bean invoking action itself to simplify exception handling for users (via convention over repetitive configuration).

@spring-operator
Copy link
Contributor Author

Keith Donald commented

This issue depends on enhancements to the RequestContext to expose an API for recording validation error messages.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant