View Javadoc

1   /*
2    * $Id: AbstractRedeliveryHandler.java 22159 2011-06-09 00:37:51Z dfeist $
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.transport.jms.redelivery;
12  
13  import org.mule.DefaultMuleMessage;
14  import org.mule.api.MuleException;
15  import org.mule.api.MuleMessage;
16  import org.mule.api.construct.FlowConstruct;
17  import org.mule.api.endpoint.InboundEndpoint;
18  import org.mule.transport.jms.JmsConnector;
19  
20  import javax.jms.JMSException;
21  import javax.jms.Message;
22  
23  public abstract class AbstractRedeliveryHandler implements RedeliveryHandler
24  {
25      protected JmsConnector connector;
26  
27      public abstract void handleRedelivery(Message message, InboundEndpoint endpoint, FlowConstruct flow) throws JMSException, MuleException;
28  
29      /**
30       * The connector associated with this handler is set before
31       * <code>handleRedelivery()</code> is called
32       * 
33       * @param connector the connector associated with this handler
34       */
35      public void setConnector(JmsConnector connector)
36      {
37          this.connector = connector;
38      }
39      
40      protected MuleMessage createMuleMessage(Message message)
41      {
42          try
43          {
44              String encoding = connector.getMuleContext().getConfiguration().getDefaultEncoding();
45              return connector.createMuleMessageFactory().create(message, encoding);
46          }
47          catch (Exception e)
48          {
49              return new DefaultMuleMessage(message, connector.getMuleContext());
50          }
51      }
52  }