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.service;
8   
9   import org.mule.api.MessagingException;
10  import org.mule.api.MuleEvent;
11  import org.mule.api.MuleException;
12  import org.mule.api.processor.MessageProcessor;
13  import org.mule.api.routing.RoutingException;
14  import org.mule.api.service.Service;
15  import org.mule.routing.MessageFilter;
16  
17  /**
18   * <code>ForwardingConsumer</code> is used to forward an incoming event over another transport without
19   * invoking a service. This can be used to implement a bridge accross different transports.
20   * @deprecated
21   */
22  @Deprecated
23  public class ForwardingConsumer extends MessageFilter
24  {
25      @Override
26      public MuleEvent processNext(MuleEvent event) throws MessagingException
27      {
28          if (!(event.getFlowConstruct() instanceof Service))
29          {
30              throw new UnsupportedOperationException("ForwardingConsumer is only supported with Service");
31          }
32  
33          MessageProcessor processor = ((Service) event.getFlowConstruct()).getOutboundMessageProcessor();
34  
35          // Set the stopFurtherProcessing flag to true to inform the
36          // DefaultInboundRouterCollection not to route these events to the service
37          event.setStopFurtherProcessing(true);
38  
39          if (processor == null)
40          {
41              logger.debug("Descriptor has no outbound router configured to forward to, continuing with normal processing");
42              return event;
43          }
44          else
45          {
46              try
47              {
48                  MuleEvent resultEvent = processor.process(event);
49                  if (resultEvent != null)
50                  {
51                      return resultEvent;
52                  }
53                  else
54                  {
55                      return null;
56                  }
57              }
58              catch (MuleException e)
59              {
60                  throw new RoutingException(event, this, e);
61              }
62          }
63      }
64  }