View Javadoc
1   /*
2    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
3    * The software in this package is published under the terms of the CPAL v1.0
4    * license, a copy of which has been included with this distribution in the
5    * LICENSE.txt file.
6    */
7   package org.mule.example.errorhandler;
8   
9   import org.mule.api.MuleEventContext;
10  import org.mule.api.MuleException;
11  import org.mule.api.lifecycle.Callable;
12  import org.mule.util.StringMessageUtils;
13  
14  import java.util.ArrayList;
15  import java.util.List;
16  
17  import org.apache.commons.logging.Log;
18  import org.apache.commons.logging.LogFactory;
19  
20  /**
21   * The <code>BusinessErrorManager</code> is a Service that processes 
22   * exceptions of type org.mule.example.errorhandler.exceptions.BusinessException.
23   * The business method simply reports the errors and stops any further processing.
24   */
25  public class BusinessErrorManager implements Callable
26  {
27      /** logger used by this class */
28      private static final Log logger = LogFactory.getLog(BusinessErrorManager.class);
29  
30      public Object onCall(MuleEventContext context) throws MuleException
31      {
32          ErrorMessage msg = (ErrorMessage)context.getMessage().getPayload();
33          // Do something with the error message
34          List<String> msgs = new ArrayList<String>();
35  
36          msgs.add(LocaleMessage.businessErrorManagerError());
37          msgs.add(LocaleMessage.errorDetail(msg.getException().getDetailMessage()));
38          msgs.add(LocaleMessage.errorClass(msg.getException().getClass()));
39  
40          logger.info("\n" + StringMessageUtils.getBoilerPlate(msgs, '*', 80));
41          context.setStopFurtherProcessing(true);
42          return null;
43      }
44  
45  }