View Javadoc

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