title: Add Action Message In Struts 2 Interceptor After Action Invocation
body: <p>I have a unique problem with passing an action message in a JSON result.</p>
  
  <p>Right now, if I add an action message within my action (in a JSON action), I will pick that up in JavaScript and capture the action message and alert the user via JGrowl.  However, I don't want the logic of adding an action message in each action.  I have an underlying service project with a request context that is shared among the request, and I am able to add warning messages there.  What I'd like to do is to transform those warning messages to action messages for use on my front end, but the action will never have to be aware of them.  This is useful because I can insert warnings when accessing databases, or if there are hairy business rules, etc.</p>
  
  <p>As I mentioned before, it already works when adding them directly in the action so I know the JSON result works fine and passes along the action messages correctly.  We have an interceptor that is hit every time for managing this request context already, so I'd like to append on the action messages in this interceptor to the action being called.  </p>
  
  <p>However, the problem I'm finding is that I need to call actionInvocation.invoke() first as any warning messages will be generated as a result of that.  After that, I check for the messages and attempt to apply them as action messages.  These action messages never show up in my JSON response, so I'm wondering if it's possible to add those messages into the response in the interceptor AFTER the invoke() call.  Here's the bulk of my intercept method:</p>
  
  <pre><code>    try {           
          // Invoke the action.
          String result = actionInvocation.invoke();
  
          //add all warning messages as an action message to be displayed on that front end
          if (CollectionUtils.isNotEmpty(context.getWarningMessages())) {
  
              ActionSupport action = (ActionSupport) actionInvocation.getAction();
  
              for (String s : context.getWarningMessages()) {
                  action.addActionError(s);
              }
          }
  
          return result;
  </code></pre>
  
  <p>I tried adding the logic to add the action messages in the finally block instead of after the call to invoke() to no avail.</p>
  
  <p>Thanks,
  Andy</p>