Fix jms/spring-integration example
This commit is contained in:
parent
5fe83ce8d1
commit
d7cd645595
|
@ -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<String, List<String>> roles = new HashMap<String, List<String>>();
|
||||
|
||||
public SecurityConfiguration()
|
||||
{
|
||||
}
|
||||
|
||||
public SecurityConfiguration(Map<String, String> users, Map<String, List<String>> roles)
|
||||
{
|
||||
Iterator<Map.Entry<String, String>> iter = users.entrySet().iterator();
|
||||
while (iter.hasNext())
|
||||
{
|
||||
Map.Entry<String, String> entry = iter.next();
|
||||
addUser(entry.getKey(), entry.getValue());
|
||||
}
|
||||
Iterator<Map.Entry<String, List<String>>> iter1 = roles.entrySet().iterator();
|
||||
while (iter1.hasNext())
|
||||
{
|
||||
Map.Entry<String, List<String>> entry = iter1.next();
|
||||
for (String role : entry.getValue())
|
||||
{
|
||||
addRole(entry.getKey(), role);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void addUser(final String user, final String password)
|
||||
{
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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">
|
||||
|
||||
<bean id="securityManager" class="org.apache.activemq.spi.core.security.ActiveMQSecurityManagerImpl">
|
||||
<constructor-arg>
|
||||
<bean class="org.apache.activemq.core.config.impl.SecurityConfiguration">
|
||||
<constructor-arg name="users">
|
||||
<map>
|
||||
<entry key="guest" value="guest"/>
|
||||
</map>
|
||||
</constructor-arg>
|
||||
<constructor-arg name="roles">
|
||||
<map>
|
||||
<entry key="guest">
|
||||
<list>
|
||||
<value>guest</value>
|
||||
</list>
|
||||
</entry>
|
||||
</map>
|
||||
</constructor-arg>
|
||||
<property name="DefaultUser" value="guest"/>
|
||||
</bean>
|
||||
</constructor-arg>
|
||||
</bean>
|
||||
|
||||
<bean id="EmbeddedJms" class="org.apache.activemq.integration.spring.SpringJmsBootstrap" init-method="start"
|
||||
destroy-method="stop">
|
||||
<property name="SecurityManager" ref="securityManager"/>
|
||||
</bean>
|
||||
|
||||
<bean id="connectionFactory" class="org.apache.activemq.jms.client.ActiveMQJMSConnectionFactory">
|
||||
|
|
Loading…
Reference in New Issue