Add check to avoid NPE
(cherry picked from commit f58683ea07)
This commit is contained in:
Timothy Bish 2015-09-08 10:03:23 -04:00
parent 3ffbaf9d89
commit f5b83cbc8f
1 changed files with 7 additions and 6 deletions

View File

@ -24,6 +24,7 @@ import java.util.HashMap;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry;
import javax.jms.Connection; import javax.jms.Connection;
import javax.jms.InvalidSelectorException; import javax.jms.InvalidSelectorException;
@ -355,15 +356,14 @@ public class DestinationView implements DestinationViewMBean {
ActiveMQConnectionFactory cf = new ActiveMQConnectionFactory(brokerUrl); ActiveMQConnectionFactory cf = new ActiveMQConnectionFactory(brokerUrl);
Connection connection = null; Connection connection = null;
try { try {
connection = cf.createConnection(userName, password); connection = cf.createConnection(userName, password);
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageProducer producer = session.createProducer(dest); MessageProducer producer = session.createProducer(dest);
ActiveMQTextMessage msg = (ActiveMQTextMessage) session.createTextMessage(body); ActiveMQTextMessage msg = (ActiveMQTextMessage) session.createTextMessage(body);
for (Iterator iter = headers.entrySet().iterator(); iter.hasNext();) { for (Iterator<Entry<String, String>> iter = headers.entrySet().iterator(); iter.hasNext();) {
Map.Entry entry = (Map.Entry) iter.next(); Entry<String, String> entry = iter.next();
msg.setObjectProperty((String) entry.getKey(), entry.getValue()); msg.setObjectProperty(entry.getKey(), entry.getValue());
} }
producer.setDeliveryMode(msg.getJMSDeliveryMode()); producer.setDeliveryMode(msg.getJMSDeliveryMode());
@ -383,9 +383,10 @@ public class DestinationView implements DestinationViewMBean {
return msg.getJMSMessageID(); return msg.getJMSMessageID();
} finally { } finally {
connection.close(); if (connection != null) {
connection.close();
}
} }
} }
@Override @Override