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.routing.outbound;
8   
9   import org.mule.api.MuleEvent;
10  import org.mule.api.MuleException;
11  import org.mule.api.processor.MessageProcessor;
12  import org.mule.api.routing.RoutingException;
13  import org.mule.api.routing.filter.Filter;
14  
15  import java.util.List;
16  
17  /**
18   * <code>OutboundPassThroughRouter</code> allows outbound routing over a single
19   * endpoint without any filtering. This class is used by Mule when a single outbound
20   * router is set on a Service.
21   */
22  public class OutboundPassThroughRouter extends FilteringOutboundRouter
23  {
24      public OutboundPassThroughRouter()
25      {
26          super();
27      }
28  
29      @Override
30      public void addRoute(MessageProcessor target) throws MuleException
31      {
32          if (target == null)
33          {
34              return;
35          }
36          if (routes.size() == 1)
37          {
38              throw new IllegalArgumentException("Only one target can be set on the PassThrough router");
39          }
40          super.addRoute(target);
41      }
42  
43      @Override
44      public void setRoutes(List<MessageProcessor> endpoints) throws MuleException
45      {
46          if (endpoints.size() > 1)
47          {
48              throw new IllegalArgumentException("Only one endpoint can be set on the PassThrough router");
49          }
50          super.setRoutes(endpoints);
51      }
52  
53      @Override
54      public void setFilter(Filter filter)
55      {
56          throw new UnsupportedOperationException(
57              "The Pass Through cannot use filters, use the FilteringOutboundRouter instead");
58      }
59  
60      @Override
61      public MuleEvent route(MuleEvent event) throws RoutingException
62      {
63          if (routes == null || routes.size() == 0)
64          {
65              return event;
66          }
67          return super.route(event);
68      }
69  }