View Javadoc

1   /*
2    * $Id: PipelineService.java 12269 2008-07-10 04:19:03Z dfeist $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSource, Inc.  All rights reserved.  http://www.mulesource.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.model.pipeline;
12  
13  import org.mule.api.MuleEvent;
14  import org.mule.api.MuleException;
15  import org.mule.api.MuleMessage;
16  import org.mule.api.MuleRuntimeException;
17  import org.mule.api.component.Component;
18  import org.mule.api.transport.DispatchException;
19  import org.mule.component.SimpleCallableJavaComponent;
20  import org.mule.config.i18n.CoreMessages;
21  import org.mule.model.direct.DirectService;
22  
23  public class PipelineService extends DirectService
24  {
25      /**
26       * Serial version
27       */
28      private static final long serialVersionUID = -2788210157354765190L;
29  
30      public PipelineService()
31      {
32          super();
33      }
34  
35      protected MuleMessage doSend(MuleEvent event) throws MuleException
36      {
37          try
38          {
39              MuleMessage result = component.onCall(event);
40              MuleMessage returnMessage = null;
41              returnMessage = (MuleMessage) result;
42  
43              if (!event.isStopFurtherProcessing())
44              {
45                  // // TODO what about this code?
46                  // Map context = RequestContext.clearProperties();
47                  // if (context != null) {
48                  // returnMessage.addProperties(context);
49                  // }
50                  if (outboundRouter.hasEndpoints())
51                  {
52                      MuleMessage outboundReturnMessage = outboundRouter.route(returnMessage, event.getSession(),
53                          event.isSynchronous());
54                      if (outboundReturnMessage != null)
55                      {
56                          returnMessage = outboundReturnMessage;
57                      }
58                  }
59                  else
60                  {
61                      logger.debug("Outbound router on service '" + name + "' doesn't have any endpoints configured.");
62                  }
63              }
64  
65              return returnMessage;
66          }
67          catch (Exception e)
68          {
69              throw new DispatchException(event.getMessage(), event.getEndpoint(), e);
70          }
71      }
72  
73      protected void doDispatch(MuleEvent event) throws MuleException
74      {
75          sendEvent(event);
76      }
77  
78      // @Override
79      public void setComponent(Component component)
80      {
81          if (!(component instanceof SimpleCallableJavaComponent))
82          {
83              throw new MuleRuntimeException(CoreMessages.objectNotOfCorrectType(component.getClass(),
84                  SimpleCallableJavaComponent.class));
85          }
86          super.setComponent(component);
87      }
88  
89  }