From issues-return-22680-apmail-struts-issues-archive=struts.apache.org@struts.apache.org Sat Oct 26 17:52:35 2013 Return-Path: X-Original-To: apmail-struts-issues-archive@minotaur.apache.org Delivered-To: apmail-struts-issues-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 5432410A7D for ; Sat, 26 Oct 2013 17:52:35 +0000 (UTC) Received: (qmail 63135 invoked by uid 500); 26 Oct 2013 17:52:33 -0000 Delivered-To: apmail-struts-issues-archive@struts.apache.org Received: (qmail 62783 invoked by uid 500); 26 Oct 2013 17:52:31 -0000 Mailing-List: contact issues-help@struts.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@struts.apache.org Delivered-To: mailing list issues@struts.apache.org Received: (qmail 62770 invoked by uid 99); 26 Oct 2013 17:52:31 -0000 Received: from arcas.apache.org (HELO arcas.apache.org) (140.211.11.28) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 26 Oct 2013 17:52:31 +0000 Date: Sat, 26 Oct 2013 17:52:31 +0000 (UTC) From: "Lukasz Lenart (JIRA)" To: issues@struts.apache.org Message-ID: In-Reply-To: References: Subject: [jira] [Updated] (WW-4234) Ability to catch service layer exceptions at one place and allow adding action messages/errors before results are rendered MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 [ https://issues.apache.org/jira/browse/WW-4234?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ] Lukasz Lenart updated WW-4234: ------------------------------ Issue Type: Improvement (was: New Feature) > Ability to catch service layer exceptions at one place and allow adding action messages/errors before results are rendered > -------------------------------------------------------------------------------------------------------------------------- > > Key: WW-4234 > URL: https://issues.apache.org/jira/browse/WW-4234 > Project: Struts 2 > Issue Type: Improvement > Affects Versions: 2.3.15.3 > Reporter: Shailesh Arvind Vaishampayan > Priority: Minor > Fix For: 2.3.x > > > I am working with an application involoving Struts2 in web layer and Spring in business layer. I also have BusinessException class which will be used by all business services to create business related validation failures which must go up to web layer and should be show to users as validation message. I can easily do this by writing in my Action class: > {code:java} > ClientAction extends ActionSupport throws Exception{ > .... > try{ > clientService.searchClient(); > }catch(InvalidClientSearchCriteriaException e){ > addActionMessage("Invlid Search Criteria"); > } > ... > {code} > And similar code in every action class. However i dont want to pollute my action classes with try catch blocks. Instead it would be much better if i can write on try catch block at one place and catch all the exceptions there as BusinessExceptions and create messages /errors from embedded messages/errors in those exceptions. One approach i could think of was to use interceptor or preResultListener. But I cannot use interceptor like below which catches business exceptions thrown from action classes... > {code:java} > ExceptionInterceptor extends AbstractInterceptor(ActionInvocation ivocation,...){ > try{ > invocation.invoke(); > }catch(Exception e){ > if(e instanceof BusinessException){ > ActionSupport as = (ActionSupport)invocation.getAction(); > String message = extractMessagefromException()//--custom method to extract message embedded in exception. > as.addActionMessages(message); > //-- above will not work result has already been rendered right? and hence it wouldn't matter if i add actoinmessages now. > } > } > } > {code} > Second approach of of preResultListener is to add action messages just like above in preResultListener's method as result is yet to be rendered and i can safely change that. However not sure if preResultListener will ever execute if exception is thrown in action? and even if it does how i can get the exception object thrown by the action.? > There has to be something out of the box so that actions are not cluttered with try-catch blocks -- This message was sent by Atlassian JIRA (v6.1#6144)