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.tck.testmodels.mule;
8   
9   import org.mule.api.MuleEvent;
10  import org.mule.api.MuleMessage;
11  import org.mule.api.endpoint.OutboundEndpoint;
12  import org.mule.api.routing.RoutingException;
13  import org.mule.transport.AbstractMessageDispatcher;
14  
15  public class TestMessageDispatcher extends AbstractMessageDispatcher
16  {
17      public TestMessageDispatcher(final OutboundEndpoint endpoint)
18      {
19          super(endpoint);
20      }
21  
22      @Override
23      protected void doInitialise()
24      {
25          // template method
26      }
27  
28      @Override
29      protected void doDispose()
30      {
31          // template method
32      }
33  
34      @Override
35      protected void doDispatch(MuleEvent event) throws Exception
36      {
37          if (event.getEndpoint().getEndpointURI().toString().equals("test://AlwaysFail"))
38          {
39              throw new RoutingException(event, (OutboundEndpoint) endpoint);
40          }
41      }
42  
43      @Override
44      protected MuleMessage doSend(MuleEvent event) throws Exception
45      {
46          if (event.getEndpoint().getEndpointURI().toString().equals("test://AlwaysFail"))
47          {
48              throw new RoutingException(event, (OutboundEndpoint) endpoint);
49          }
50          return event.getMessage();
51      }
52  
53      @Override
54      protected void doConnect() throws Exception
55      {
56          // no op
57      }
58  
59      @Override
60      protected void doDisconnect() throws Exception
61      {
62          // no op
63      }
64  
65      @Override
66      protected void doStart() 
67      {
68          // no op
69      }
70  
71      @Override
72      protected void doStop() 
73      {
74          // no op
75      }
76  }