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