View Javadoc

1   /*
2    * $Id: AbstractReplyToPropertyRequestReplyReplier.java 23154 2011-10-12 06:00:08Z dirk.olmes $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.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.routing.requestreply;
12  
13  import org.mule.api.MuleEvent;
14  import org.mule.api.MuleException;
15  import org.mule.api.config.MuleProperties;
16  import org.mule.api.processor.MessageProcessor;
17  import org.mule.api.processor.RequestReplyReplierMessageProcessor;
18  import org.mule.api.transport.ReplyToHandler;
19  import org.mule.processor.AbstractInterceptingMessageProcessor;
20  
21  import org.apache.commons.lang.BooleanUtils;
22  
23  public abstract class AbstractReplyToPropertyRequestReplyReplier extends AbstractInterceptingMessageProcessor
24      implements RequestReplyReplierMessageProcessor
25  {
26      @Override
27      public MuleEvent process(MuleEvent event) throws MuleException
28      {
29          MuleEvent resultEvent;
30          if (shouldProcessEvent(event))
31          {
32              Object replyTo = event.getReplyToDestination();
33              ReplyToHandler replyToHandler = event.getReplyToHandler();
34  
35              resultEvent = processNext(event);
36  
37              // Allow components to stop processing of the ReplyTo property (e.g. CXF)
38              final String replyToStop = resultEvent.getMessage().getInvocationProperty(
39                      MuleProperties.MULE_REPLY_TO_STOP_PROPERTY);
40              if (resultEvent != null && !BooleanUtils.toBoolean(replyToStop))
41              {
42                  // reply-to processing should not resurrect a dead event
43                  processReplyTo(event, resultEvent, replyToHandler, replyTo);
44              }
45          }
46          else
47          {
48              resultEvent = processNext(event);
49          }
50          return resultEvent;
51      }
52  
53      protected abstract boolean shouldProcessEvent(MuleEvent event);
54  
55      protected void processReplyTo(MuleEvent event,
56                                    MuleEvent result,
57                                    ReplyToHandler replyToHandler,
58                                    Object replyTo) throws MuleException
59      {
60          if (result != null && replyToHandler != null)
61          {
62              String requestor = result.getMessage().getOutboundProperty(
63                  MuleProperties.MULE_REPLY_TO_REQUESTOR_PROPERTY);
64              if ((requestor != null && !requestor.equals(event.getFlowConstruct().getName()))
65                  || requestor == null)
66              {
67                  replyToHandler.processReplyTo(event, result.getMessage(), replyTo);
68              }
69          }
70      }
71  
72      public void setReplyProcessor(MessageProcessor replyMessageProcessor)
73      {
74          // Not used
75      }
76  
77  }