Coverage Report - org.mule.transport.jms.JmsMuleMessageFactory
 
Classes in this File Line Coverage Branch Coverage Complexity
JmsMuleMessageFactory
0%
0/89
0%
0/14
0
 
 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;
 8  
 
 9  
 import org.mule.DefaultMuleMessage;
 10  
 import org.mule.api.MuleContext;
 11  
 import org.mule.api.MuleMessage;
 12  
 import org.mule.api.config.MuleProperties;
 13  
 import org.mule.transport.AbstractMuleMessageFactory;
 14  
 
 15  
 import java.util.Enumeration;
 16  
 import java.util.HashMap;
 17  
 import java.util.Map;
 18  
 
 19  
 import javax.jms.Destination;
 20  
 import javax.jms.JMSException;
 21  
 import javax.jms.Message;
 22  
 
 23  
 public class JmsMuleMessageFactory extends AbstractMuleMessageFactory
 24  
 {
 25  
     public JmsMuleMessageFactory(MuleContext context)
 26  
     {
 27  0
         super(context);
 28  0
     }
 29  
 
 30  
     @Override
 31  
     protected Class<?>[] getSupportedTransportMessageTypes()
 32  
     {
 33  0
         return new Class[]{ Message.class };
 34  
     }
 35  
 
 36  
     @Override
 37  
     protected Object extractPayload(Object transportMessage, String encoding) throws Exception
 38  
     {
 39  0
         return transportMessage;
 40  
     }
 41  
 
 42  
     @Override
 43  
     protected void addProperties(DefaultMuleMessage muleMessage, Object transportMessage) throws Exception
 44  
     {        
 45  0
         Message jmsMessage = (Message) transportMessage;
 46  
         
 47  0
         Map<String, Object> messageProperties = new HashMap<String, Object>();
 48  0
         addCorrelationProperties(jmsMessage, muleMessage, messageProperties);
 49  0
         addDeliveryModeProperty(jmsMessage, messageProperties);
 50  0
         addDestinationProperty(jmsMessage, messageProperties);
 51  0
         addExpirationProperty(jmsMessage, messageProperties);
 52  0
         addMessageIdProperty(jmsMessage, messageProperties);
 53  0
         addPriorityProperty(jmsMessage, messageProperties);
 54  0
         addRedeliveredProperty(jmsMessage, messageProperties);
 55  0
         addJMSReplyTo(muleMessage, jmsMessage);
 56  0
         addTimestampProperty(jmsMessage, messageProperties);
 57  0
         addTypeProperty(jmsMessage, messageProperties);
 58  
 
 59  0
         propagateJMSProperties(jmsMessage, messageProperties);
 60  
         
 61  0
         muleMessage.addInboundProperties(messageProperties);
 62  0
     }
 63  
 
 64  
     protected void propagateJMSProperties(Message jmsMessage, Map<String, Object> messageProperties)
 65  
     {
 66  
         try
 67  
         {
 68  0
             Enumeration<?> e = jmsMessage.getPropertyNames();
 69  0
             while (e.hasMoreElements())
 70  
             {
 71  0
                 String key = (String) e.nextElement();
 72  
                 try
 73  
                 {
 74  0
                     Object value = jmsMessage.getObjectProperty(key);
 75  0
                     if (value != null)
 76  
                     {
 77  0
                         messageProperties.put(key, value);
 78  
                     }
 79  
                 }
 80  0
                 catch (JMSException e1)
 81  
                 {
 82  
                     // ignored
 83  0
                 }
 84  0
             }
 85  
         }
 86  0
         catch (JMSException e1)
 87  
         {
 88  
             // ignored
 89  0
         }
 90  0
     }
 91  
 
 92  
     protected void addTypeProperty(Message jmsMessage, Map<String, Object> messageProperties)
 93  
     {
 94  
         try
 95  
         {
 96  0
             String value = jmsMessage.getJMSType();
 97  0
             if (value != null)
 98  
             {
 99  0
                 messageProperties.put(JmsConstants.JMS_TYPE, value);
 100  
             }
 101  
         }
 102  0
         catch (JMSException e)
 103  
         {
 104  
             // ignored
 105  0
         }
 106  0
     }
 107  
 
 108  
     protected void addTimestampProperty(Message jmsMessage, Map<String, Object> messageProperties)
 109  
     {
 110  
         try
 111  
         {
 112  0
             long value = jmsMessage.getJMSTimestamp();
 113  0
             messageProperties.put(JmsConstants.JMS_TIMESTAMP, Long.valueOf(value));
 114  
         }
 115  0
         catch (JMSException e)
 116  
         {
 117  
             // ignored
 118  0
         }
 119  0
     }
 120  
 
 121  
     protected void addJMSReplyTo(MuleMessage muleMessage, Message jmsMessage)
 122  
     {
 123  
         try
 124  
         {
 125  0
             Destination replyTo = jmsMessage.getJMSReplyTo();
 126  0
             if (replyTo != null)
 127  
             {
 128  0
                 muleMessage.setOutboundProperty(JmsConstants.JMS_REPLY_TO, replyTo);
 129  
             }
 130  
 
 131  0
             muleMessage.setReplyTo(replyTo);
 132  
         }
 133  0
         catch (JMSException e)
 134  
         {
 135  
             // ignored
 136  0
         }
 137  0
     }
 138  
 
 139  
     protected void addRedeliveredProperty(Message jmsMessage, Map<String, Object> messageProperties)
 140  
     {
 141  
         try
 142  
         {
 143  0
             boolean value = jmsMessage.getJMSRedelivered();
 144  0
             messageProperties.put(JmsConstants.JMS_REDELIVERED, Boolean.valueOf(value));
 145  
         }
 146  0
         catch (JMSException e)
 147  
         {
 148  
             // ignored
 149  0
         }
 150  0
     }
 151  
 
 152  
     protected void addPriorityProperty(Message jmsMessage, Map<String, Object> messageProperties)
 153  
     {
 154  
         try
 155  
         {
 156  0
             int value = jmsMessage.getJMSPriority();
 157  0
             messageProperties.put(JmsConstants.JMS_PRIORITY, Integer.valueOf(value));
 158  
         }
 159  0
         catch (JMSException e)
 160  
         {
 161  
             // ignored
 162  0
         }
 163  0
     }
 164  
 
 165  
     protected void addMessageIdProperty(Message jmsMessage, Map<String, Object> messageProperties)
 166  
     {
 167  
         try
 168  
         {
 169  0
             String value = jmsMessage.getJMSMessageID();
 170  0
             if (value != null)
 171  
             {
 172  0
                 messageProperties.put(JmsConstants.JMS_MESSAGE_ID, value);
 173  0
                 messageProperties.put(MuleProperties.MULE_MESSAGE_ID_PROPERTY, value);
 174  
             }
 175  
         }
 176  0
         catch (JMSException e)
 177  
         {
 178  
             // ignored
 179  0
         }
 180  0
     }
 181  
 
 182  
     protected void addExpirationProperty(Message jmsMessage, Map<String, Object> messageProperties)
 183  
     {
 184  
         try
 185  
         {
 186  0
             long value = jmsMessage.getJMSExpiration();
 187  0
             messageProperties.put(JmsConstants.JMS_EXPIRATION, Long.valueOf(value));
 188  
         }
 189  0
         catch (JMSException e)
 190  
         {
 191  
             // ignored
 192  0
         }
 193  0
     }
 194  
 
 195  
     protected void addDestinationProperty(Message jmsMessage, Map<String, Object> messageProperties)
 196  
     {
 197  
         try
 198  
         {
 199  0
             Destination value = jmsMessage.getJMSDestination();
 200  0
             if (value != null)
 201  
             {
 202  0
                 messageProperties.put(JmsConstants.JMS_DESTINATION, value);
 203  
             }
 204  
         }
 205  0
         catch (JMSException e)
 206  
         {
 207  
             // ignored
 208  0
         }
 209  0
     }
 210  
 
 211  
     protected void addDeliveryModeProperty(Message jmsMessage, Map<String, Object> messageProperties)
 212  
     {
 213  
         try
 214  
         {
 215  0
             int value = jmsMessage.getJMSDeliveryMode();
 216  0
             messageProperties.put(JmsConstants.JMS_DELIVERY_MODE, Integer.valueOf(value));
 217  
         }
 218  0
         catch (JMSException e)
 219  
         {
 220  
             // ignored
 221  0
         }
 222  0
     }
 223  
 
 224  
     protected void addCorrelationProperties(Message jmsMessage, MuleMessage muleMessage, 
 225  
         Map<String, Object> messageProperties)
 226  
     {
 227  
         try
 228  
         {
 229  0
             String value = jmsMessage.getJMSCorrelationID();
 230  0
             if (value != null)
 231  
             {
 232  0
                 messageProperties.put(JmsConstants.JMS_CORRELATION_ID, value);
 233  
                 // this property is used my getCorrelationId in MuleMessage, but we want
 234  
                 // it on the INBOUND scoped properties so don't use setCorrelationId
 235  0
                 messageProperties.put(MuleProperties.MULE_CORRELATION_ID_PROPERTY, value);
 236  
             }
 237  
         }
 238  0
         catch (JMSException e)
 239  
         {
 240  
             // ignored
 241  0
         }
 242  0
     }
 243  
 }