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.api.routing;
8   
9   import org.mule.api.MessagingException;
10  import org.mule.api.MuleEvent;
11  import org.mule.api.processor.MessageProcessor;
12  import org.mule.config.i18n.CoreMessages;
13  import org.mule.config.i18n.Message;
14  
15  /**
16   * <code>RoutingException</code> is a base class for all routing exceptions.
17   * Routing exceptions are only thrown for DefaultInboundRouterCollection and
18   * DefaultOutboundRouterCollection and deriving types. Mule itself does not throw routing
19   * exceptions when routing internal events.
20   */
21  public class RoutingException extends MessagingException
22  {
23      /**
24       * Serial version
25       */
26      private static final long serialVersionUID = 2478458847072048645L;
27  
28      protected final transient MessageProcessor route;
29  
30      public RoutingException(MuleEvent event, MessageProcessor route)
31      {
32          super(generateMessage(null, route), event);
33          this.route = route;
34      }
35  
36      public RoutingException(MuleEvent event, MessageProcessor route, Throwable cause)
37      {
38          super(generateMessage(null, route), event, cause);
39          this.route = route;
40      }
41  
42      public RoutingException(Message message, MuleEvent event, MessageProcessor route)
43      {
44          super(generateMessage(message, route), event);
45          this.route = route;
46      }
47  
48      public RoutingException(Message message, MuleEvent event, MessageProcessor route, Throwable cause)
49      {
50          super(generateMessage(message, route), event, cause);
51          this.route = route;
52      }
53  
54      public MessageProcessor getRoute()
55      {
56          return route;
57      }
58  
59      private static Message generateMessage(Message message, MessageProcessor target)
60      {
61          Message m = CoreMessages.failedToRouterViaEndpoint(target);
62          if (message != null)
63          {
64              message.setNextMessage(m);
65              return message;
66          }
67          else
68          {
69              return m;
70          }
71      }
72  }