From d7cd6455953fc4985fce387ea6b9ca6a4510ca6b Mon Sep 17 00:00:00 2001 From: Howard Gao Date: Wed, 11 Mar 2015 16:48:44 +0800 Subject: [PATCH] Fix jms/spring-integration example --- .../config/impl/SecurityConfiguration.java | 23 +++++++++++++++++++ .../activemq/jms/example/MessageSender.java | 18 ++++++++++++++- .../src/main/resources/spring-jms-beans.xml | 23 +++++++++++++++++++ 3 files changed, 63 insertions(+), 1 deletion(-) diff --git a/activemq-server/src/main/java/org/apache/activemq/core/config/impl/SecurityConfiguration.java b/activemq-server/src/main/java/org/apache/activemq/core/config/impl/SecurityConfiguration.java index a40f3615d3..45566e1ed9 100644 --- a/activemq-server/src/main/java/org/apache/activemq/core/config/impl/SecurityConfiguration.java +++ b/activemq-server/src/main/java/org/apache/activemq/core/config/impl/SecurityConfiguration.java @@ -21,6 +21,7 @@ import org.apache.activemq.core.server.ActiveMQMessageBundle; import java.util.ArrayList; import java.util.HashMap; +import java.util.Iterator; import java.util.List; import java.util.Map; @@ -37,6 +38,28 @@ public class SecurityConfiguration */ protected final Map> roles = new HashMap>(); + public SecurityConfiguration() + { + } + + public SecurityConfiguration(Map users, Map> roles) + { + Iterator> iter = users.entrySet().iterator(); + while (iter.hasNext()) + { + Map.Entry entry = iter.next(); + addUser(entry.getKey(), entry.getValue()); + } + Iterator>> iter1 = roles.entrySet().iterator(); + while (iter1.hasNext()) + { + Map.Entry> entry = iter1.next(); + for (String role : entry.getValue()) + { + addRole(entry.getKey(), role); + } + } + } public void addUser(final String user, final String password) { diff --git a/examples/jms/spring-integration/src/main/java/org/apache/activemq/jms/example/MessageSender.java b/examples/jms/spring-integration/src/main/java/org/apache/activemq/jms/example/MessageSender.java index 2b08ccc208..1d5401db68 100644 --- a/examples/jms/spring-integration/src/main/java/org/apache/activemq/jms/example/MessageSender.java +++ b/examples/jms/spring-integration/src/main/java/org/apache/activemq/jms/example/MessageSender.java @@ -19,6 +19,7 @@ package org.apache.activemq.jms.example; import javax.jms.Connection; import javax.jms.ConnectionFactory; import javax.jms.Destination; +import javax.jms.JMSException; import javax.jms.MessageProducer; import javax.jms.Session; import javax.jms.TextMessage; @@ -50,9 +51,10 @@ public class MessageSender public void send(String msg) { + Connection conn = null; try { - Connection conn = connectionFactory.createConnection(); + conn = connectionFactory.createConnection(); Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE); MessageProducer producer = session.createProducer(destination); TextMessage message = session.createTextMessage(msg); @@ -62,5 +64,19 @@ public class MessageSender { ex.printStackTrace(); } + finally + { + if (conn != null) + { + try + { + conn.close(); + } + catch (JMSException e) + { + e.printStackTrace(); + } + } + } } } diff --git a/examples/jms/spring-integration/src/main/resources/spring-jms-beans.xml b/examples/jms/spring-integration/src/main/resources/spring-jms-beans.xml index bcbb01ba0a..14bb5c8fc3 100644 --- a/examples/jms/spring-integration/src/main/resources/spring-jms-beans.xml +++ b/examples/jms/spring-integration/src/main/resources/spring-jms-beans.xml @@ -24,8 +24,31 @@ under the License. xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd"> + + + + + + + + + + + + + guest + + + + + + + + + +