@Override public void addAddressSettings(final String address, final AddressSettings addressSettings) { server.getAddressSettingsRepository().addMatch(address, addressSettings); }
@Override protected void addConfiguration(ActiveMQServer server) { server.getAddressSettingsRepository().addMatch(INITIAL_QUEUE_NAME, new AddressSettings().setExpiryAddress(FINAL_QUEUE_SS)); }
@Test public void testCreateNonExistentQueue() throws Exception { AddressSettings addressSettings = new AddressSettings(); addressSettings.setAutoCreateQueues(false); getJmsServer().getAddressSettingsRepository().addMatch("#", addressSettings); Connection conn = getConnectionFactory().createConnection(); Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE); try { sess.createQueue("QueueThatDoesNotExist"); ProxyAssertSupport.fail(); } catch (JMSException e) { } conn.close(); }
@Test public void testGetExpiryAddress() throws Exception { SimpleString address = RandomUtil.randomSimpleString(); SimpleString queue = RandomUtil.randomSimpleString(); final SimpleString expiryAddress = RandomUtil.randomSimpleString(); session.createQueue(address, RoutingType.MULTICAST, queue, null, durable); QueueControl queueControl = createManagementControl(address, queue); Assert.assertNull(queueControl.getExpiryAddress()); server.getAddressSettingsRepository().addMatch(address.toString(), new AddressSettings() { private static final long serialVersionUID = 6745306517827764680L; @Override public SimpleString getExpiryAddress() { return expiryAddress; } }); Assert.assertEquals(expiryAddress.toString(), queueControl.getExpiryAddress()); session.deleteQueue(queue); }
@Test public void testCreateNonExistentTopic() throws Exception { getJmsServer().getAddressSettingsRepository().addMatch("#", new AddressSettings().setAutoCreateQueues(false)); getJmsServer().getAddressSettingsRepository().addMatch("#", new AddressSettings().setAutoCreateAddresses(false)); Connection conn = getConnectionFactory().createConnection(); Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE); try { sess.createTopic("TopicThatDoesNotExist"); ProxyAssertSupport.fail("should throw JMSException"); } catch (JMSException e) { // OK } conn.close(); }
@Test public void testWithoutWildcard() { securityRepository.addMatch("queues.1.*", new HashSet<Role>()); HashSet<Role> roles = new HashSet<>(2); roles.add(new Role("test1", true, true, true, true, true, true, true, true, true, true)); roles.add(new Role("test2", true, true, true, true, true, true, true, true, true, true)); securityRepository.addMatch("queues.2.aq", roles); HashSet<Role> hashSet = securityRepository.getMatch("queues.2.aq"); Assert.assertEquals(hashSet.size(), 2); }
@Test public void testGetDeadLetterAddress() throws Exception { SimpleString address = RandomUtil.randomSimpleString(); SimpleString queue = RandomUtil.randomSimpleString(); final SimpleString deadLetterAddress = RandomUtil.randomSimpleString(); session.createQueue(address, RoutingType.MULTICAST, queue, null, durable); QueueControl queueControl = createManagementControl(address, queue); Assert.assertNull(queueControl.getDeadLetterAddress()); server.getAddressSettingsRepository().addMatch(address.toString(), new AddressSettings() { private static final long serialVersionUID = -4919035864731465338L; @Override public SimpleString getDeadLetterAddress() { return deadLetterAddress; } }); Assert.assertEquals(deadLetterAddress.toString(), queueControl.getDeadLetterAddress()); session.deleteQueue(queue); }
protected void setRedistributionDelay(final long delay) { AddressSettings as = new AddressSettings().setRedistributionDelay(delay); getServer(0).getAddressSettingsRepository().addMatch("queues.*", as); getServer(1).getAddressSettingsRepository().addMatch("queues.*", as); getServer(2).getAddressSettingsRepository().addMatch("queues.*", as); }
private void addSettings() { for (Map.Entry<String, AddressSettings> setting : addressSettings.entrySet()) { server.getAddressSettingsRepository().addMatch(setting.getKey(), setting.getValue()); } }
@Test public void testCreateTopicWhileQueueWithSameNameExists() throws Exception { getJmsServer().getAddressSettingsRepository().addMatch("#", new AddressSettings().setAutoCreateQueues(false)); getJmsServer().getAddressSettingsRepository().addMatch("#", new AddressSettings().setAutoCreateAddresses(false)); Connection conn = getConnectionFactory().createConnection(); Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE); try { sess.createTopic("TestQueue"); ProxyAssertSupport.fail("should throw JMSException"); } catch (JMSException e) { // OK } conn.close(); }
@Test public void testSingletwo() { securityRepository.addMatch("queues.another.aq.*", new HashSet<Role>()); HashSet<Role> roles = new HashSet<>(2); roles.add(new Role("test1", true, true, true, true, true, true, true, true, true, true)); roles.add(new Role("test2", true, true, true, true, true, true, true, true, true, true)); securityRepository.addMatch("queues.aq", roles); HashSet<Role> roles2 = new HashSet<>(2); roles2.add(new Role("test1", true, true, true, true, true, true, true, true, true, true)); roles2.add(new Role("test2", true, true, true, true, true, true, true, true, true, true)); roles2.add(new Role("test3", true, true, true, true, true, true, true, true, true, true)); securityRepository.addMatch("queues.another.andanother", roles2); HashSet<Role> hashSet = securityRepository.getMatch("queues.another.andanother"); Assert.assertEquals(hashSet.size(), 3); }
protected void setRedistributionDelay(final long delay) { AddressSettings as = new AddressSettings().setRedistributionDelay(delay); getServer(0).getAddressSettingsRepository().addMatch("queues.*", as); getServer(1).getAddressSettingsRepository().addMatch("queues.*", as); }
@Override protected void performRuntime(final OperationContext context, final ModelNode operation, final ModelNode model) throws OperationFailedException { final ActiveMQServer server = getActiveMQServer(context, operation); if(server != null) { final PathAddress address = PathAddress.pathAddress(operation.require(ModelDescriptionConstants.OP_ADDR)); final AddressSettings settings = createSettings(context, model); server.getAddressSettingsRepository().addMatch(address.getLastElement().getValue(), settings); } }
@Test public void testCreateQueueWhileTopicWithSameNameExists() throws Exception { AddressSettings addressSettings = new AddressSettings(); addressSettings.setAutoCreateQueues(false); addressSettings.setAutoCreateAddresses(false); getJmsServer().getAddressSettingsRepository().addMatch("#", addressSettings); Connection conn = getConnectionFactory().createConnection(); Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE); try { sess.createQueue("TestTopic"); ProxyAssertSupport.fail("should throw JMSException"); } catch (JMSException e) { // OK } conn.close(); }
@Test public void testIllegalMatches() { HierarchicalRepository<String> repository = new HierarchicalObjectRepository<>(); try { repository.addMatch("hjhjhjhjh.#.hhh", "test"); fail("expected exception"); } catch (IllegalArgumentException e) { // pass } try { repository.addMatch(null, "test"); fail("expected exception"); } catch (IllegalArgumentException e) { // pass } }
protected void setRedistributionDelay(final long delay) { AddressSettings as = new AddressSettings().setRedistributionDelay(delay); getServer(0).getAddressSettingsRepository().addMatch("queues.*", as); getServer(1).getAddressSettingsRepository().addMatch("queues.*", as); }
@Override protected void performRuntime(final OperationContext context, final ModelNode operation, final ModelNode model) throws OperationFailedException { final ActiveMQServer server = getActiveMQServer(context, operation); if(server != null) { final PathAddress address = PathAddress.pathAddress(operation.require(ModelDescriptionConstants.OP_ADDR)); final AddressSettings settings = createSettings(context, model); server.getAddressSettingsRepository().addMatch(address.getLastElement().getValue(), settings); } }
@Test public void testAutoDestinationCreationOnProducerSend() throws JMSException { AddressSettings addressSetting = new AddressSettings(); addressSetting.setAutoCreateQueues(true); addressSetting.setAutoCreateAddresses(true); String address = "foo"; server.getAddressSettingsRepository().addMatch(address, addressSetting); connection.start(); Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); TextMessage message = session.createTextMessage("bar"); Queue queue = new ActiveMQQueue(address); MessageProducer producer = session.createProducer(null); producer.send(queue, message); MessageConsumer consumer = session.createConsumer(queue); TextMessage message1 = (TextMessage) consumer.receive(1000); assertTrue(message1.getText().equals(message.getText())); }
@Test public void testAutoCreateOnSendToQueueSecurity() throws Exception { ((ActiveMQJAASSecurityManager) server.getSecurityManager()).getConfiguration().addUser("guest", "guest"); ((ActiveMQJAASSecurityManager) server.getSecurityManager()).getConfiguration().setDefaultUser("guest"); ((ActiveMQJAASSecurityManager) server.getSecurityManager()).getConfiguration().addRole("guest", "rejectAll"); Role role = new Role("rejectAll", false, false, false, false, false, false, false, false, false, false); Set<Role> roles = new HashSet<>(); roles.add(role); server.getSecurityRepository().addMatch("#", roles); Connection connection = cf.createConnection(); Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); javax.jms.Queue queue = ActiveMQJMSClient.createQueue(QUEUE_NAME); try { session.createProducer(queue); Assert.fail("Sending a message here should throw a JMSSecurityException"); } catch (Exception e) { Assert.assertTrue(e instanceof JMSSecurityException); } connection.close(); }