public static JMSException convertFromActiveMQException(final ActiveMQException me) { JMSException je; switch (me.getType()) { case CONNECTION_TIMEDOUT: je = new JMSException(me.getMessage()); break; je = new javax.jms.IllegalStateException(me.getMessage()); break; je = new JMSException(me.getMessage()); break; je = new InvalidSelectorException(me.getMessage()); break; je = new JMSException(me.getMessage()); break; je = new javax.jms.IllegalStateException(me.getMessage()); break; je = new InvalidDestinationException(me.getMessage()); break; je = new InvalidDestinationException(me.getMessage()); break; je = new JMSSecurityException(me.getMessage()); break;
@Override public void exceptionCaught(final ChannelHandlerContext ctx, final Throwable cause) throws Exception { if (!active) { return; } // We don't want to log this - since it is normal for this to happen during failover/reconnect // and we don't want to spew out stack traces in that event // The user has access to this exeception anyway via the ActiveMQException initial cause ActiveMQException me = new ActiveMQException(cause.getMessage()); me.initCause(cause); synchronized (listener) { try { listenerExecutor.execute(() -> listener.connectionException(channelId(ctx.channel()), me)); active = false; } catch (Exception ex) { ActiveMQClientLogger.LOGGER.errorCallingLifeCycleListener(ex); } } }
/** * @throws ActiveMQException */ private void checkException() throws ActiveMQException { // it's not needed to copy it as we never set it back to null // once the exception is set, the controller is pretty much useless if (handledException != null) { if (handledException instanceof ActiveMQException) { ActiveMQException nestedException; // This is just to be user friendly and give the user a proper exception trace, // instead to just where it was canceled. if (handledException instanceof ActiveMQLargeMessageInterruptedException) { nestedException = new ActiveMQLargeMessageInterruptedException(handledException.getMessage()); } else { nestedException = new ActiveMQException(((ActiveMQException) handledException).getType(), handledException.getMessage()); } nestedException.initCause(handledException); throw nestedException; } else { throw new ActiveMQException(ActiveMQExceptionType.LARGE_MESSAGE_ERROR_BODY, "Error on saving LargeMessageBufferImpl", handledException); } } }
@Override public void encodeRest(final ActiveMQBuffer buffer) { buffer.writeInt(exception.getType().getCode()); buffer.writeNullableString(exception.getMessage()); }
private final CountDownLatch waitLatch = new CountDownLatch(1); return createSessionContext(clientVersion, name, username, password, xa, autoCommitSends, autoCommitAcks, preAcknowledge, minLargeMessageSize, confirmationWindowSize); } catch (ActiveMQException e) { if (e.getType() != ActiveMQExceptionType.INCOMPATIBLE_CLIENT_SERVER_VERSIONS) { throw e; throw new ActiveMQException(ActiveMQExceptionType.INCOMPATIBLE_CLIENT_SERVER_VERSIONS); throw ActiveMQClientMessageBundle.BUNDLE.clientSessionClosed(); inCreateSession = true; inCreateSessionLatch = new CountDownLatch(1); throw cause; if (cause.getType() == ActiveMQExceptionType.UNBLOCKED) {
try { IntegrationTestLogger.LOGGER.info("Waiting to start consumer thread..."); okToConsume.await(20, TimeUnit.SECONDS); } catch (InterruptedException e) { e.printStackTrace(); session = addClientSession(factory.createSession(false, false, true)); consumer = addClientConsumer(session.createConsumer(QUEUE)); session.start(); consumerCounter.incrementAndGet(); ClientMessage m = consumer.receive(1000); if (m == null) { okToEndTest.countDown(); return; } catch (ActiveMQException e) { errors.incrementAndGet(); IntegrationTestLogger.LOGGER.warn("Consumer thread threw exception while receiving messages from server " + targetServer + ".: " + e.getMessage()); } catch (Exception e) { errors.incrementAndGet();
@Test public void testDeleteTemporaryQueueAfterConnectionIsClosed() throws Exception { SimpleString queue = RandomUtil.randomSimpleString(); SimpleString address = RandomUtil.randomSimpleString(); session.createTemporaryQueue(address, queue); RemotingConnectionImpl conn = (RemotingConnectionImpl) server.getRemotingService().getConnections().iterator().next(); final CountDownLatch latch = new CountDownLatch(1); conn.addCloseListener(new CloseListener() { @Override public void connectionClosed() { latch.countDown(); } }); session.close(); sf.close(); // wait for the closing listeners to be fired assertTrue("connection close listeners not fired", latch.await(2 * TemporaryQueueTest.CONNECTION_TTL, TimeUnit.MILLISECONDS)); sf = addSessionFactory(createSessionFactory(locator)); session = sf.createSession(false, true, true); session.start(); try { session.createConsumer(queue); fail("temp queue must not exist after the remoting connection is closed"); } catch (ActiveMQNonExistentQueueException neqe) { //ol } catch (ActiveMQException e) { fail("Invalid Exception type:" + e.getType()); } session.close(); }
server.start(); ClientSessionFactory factory = createSessionFactory(locator); session = (ClientSessionInternal) factory.createSession(); final CountDownLatch latch = new CountDownLatch(1); sessions[0].getRemotingConnection().fail(new ActiveMQException("failure!")); Assert.assertTrue(latch.await(5, TimeUnit.SECONDS)); server.stop();
final CountDownLatch upLatch = new CountDownLatch(5); locator.addClusterTopologyListener(new LatchListener(upLatch, nodes, new CountDownLatch(0))); ClientSessionFactory sf = createSessionFactory(locator); checkContains(new int[]{0, 1, 2, 3, 4}, nodeIDs, nodes); ClientSession session = sf.createSession(); Assert.assertFalse(servers[0].isStarted()); session = checkSessionOrReconnect(session, locator); checkContains(new int[]{1, 2, 3, 4}, nodeIDs, nodes); Assert.assertFalse(servers[2].isStarted()); session = checkSessionOrReconnect(session, locator); checkContains(new int[]{1, 3, 4}, nodeIDs, nodes); Assert.assertFalse(servers[4].isStarted()); session = checkSessionOrReconnect(session, locator); checkContains(new int[]{1, 3}, nodeIDs, nodes); Assert.fail(); } catch (ActiveMQException expected) { Assert.assertEquals(ActiveMQExceptionType.NOT_CONNECTED, expected.getType());
session = addClientSession(factory.createSession(false, true, true)); producer = addClientProducer(session.createProducer(ADDRESS)); } catch (Exception e) { errors.incrementAndGet(); ClientMessage message = session.createMessage(true); message.putStringProperty(Message.HDR_GROUP_ID, new SimpleString(group)); SimpleString dupID = new SimpleString(basicID + ":" + messageCount); message.putStringProperty(Message.HDR_DUPLICATE_DETECTION_ID, dupID); try { messageCount++; } catch (ActiveMQException e) { IntegrationTestLogger.LOGGER.warn("Producer thread threw exception while sending messages to " + targetServer + ": " + e.getMessage()); okToConsume.countDown();
@Test public void testSendManagementWithoutRole() throws Exception { ActiveMQServer server = createServer(); server.start(); HierarchicalRepository<Set<Role>> securityRepository = server.getSecurityRepository(); ActiveMQJAASSecurityManager securityManager = (ActiveMQJAASSecurityManager) server.getSecurityManager(); securityManager.getConfiguration().addUser("auser", "pass"); Role role = new Role("arole", false, false, true, false, false, false, false, false, true, false); Set<Role> roles = new HashSet<>(); roles.add(role); securityRepository.addMatch(configuration.getManagementAddress().toString(), roles); securityManager.getConfiguration().addRole("auser", "arole"); ClientSessionFactory cf = createSessionFactory(locator); ClientSession session = cf.createSession("auser", "pass", false, true, true, false, -1); session.createQueue(configuration.getManagementAddress().toString(), SecurityTest.queueA, true); ClientProducer cp = session.createProducer(configuration.getManagementAddress()); cp.send(session.createMessage(false)); try { cp.send(session.createMessage(false)); } catch (ActiveMQSecurityException se) { //ok } catch (ActiveMQException e) { fail("Invalid Exception type:" + e.getType()); } session.close(); }
session.start(); final SimpleString queueName = new SimpleString("DuplicateDetectionTestQueue"); session.createQueue(queueName, queueName, null, false); ClientProducer producer = session.createProducer(queueName); ClientConsumer consumer = session.createConsumer(queueName); session.close(); sf.close(); server.stop(); server.start(); session = sf.createSession(false, false, false); session.rollback(); } catch (ActiveMQException e) { fail("Invalid Exception type:" + e.getType()); session.rollback(); } catch (ActiveMQException e) { fail("Invalid Exception type:" + e.getType());
@Test public void testDeleteDurableQueueWithoutRole() throws Exception { ActiveMQServer server = createServer(); server.start(); HierarchicalRepository<Set<Role>> securityRepository = server.getSecurityRepository(); ActiveMQJAASSecurityManager securityManager = (ActiveMQJAASSecurityManager) server.getSecurityManager(); securityManager.getConfiguration().addUser("auser", "pass"); Role role = new Role("arole", false, false, true, false, false, false, false, false, true, false); Set<Role> roles = new HashSet<>(); roles.add(role); securityRepository.addMatch(SecurityTest.addressA, roles); securityManager.getConfiguration().addRole("auser", "arole"); ClientSessionFactory cf = createSessionFactory(locator); ClientSession session = cf.createSession("auser", "pass", false, true, true, false, -1); session.createQueue(SecurityTest.addressA, SecurityTest.queueA, true); try { session.deleteQueue(SecurityTest.queueA); Assert.fail("should throw exception"); } catch (ActiveMQSecurityException se) { //ok } catch (ActiveMQException e) { fail("Invalid Exception type:" + e.getType()); } session.close(); }
@Test public void testEntireTransactionRejected() throws Exception { ClientSession session = sf.createSession(false, false, false); session.start(); final SimpleString queueName = new SimpleString("DuplicateDetectionTestQueue"); final SimpleString queue2 = new SimpleString("queue2"); session.createQueue(queueName, queueName, null, false); session.createQueue(queue2, queue2, null, false); ClientProducer producer = session.createProducer(queueName); SimpleString dupID = new SimpleString("abcdefg"); message.putBytesProperty(Message.HDR_DUPLICATE_DETECTION_ID, dupID.getData()); producer.send(message); session.close(); session = sf.createSession(false, false, false); session.start(); session.rollback(); } catch (ActiveMQException e) { fail("Invalid Exception type:" + e.getType());
@Test public void testAddressDoesNotExist() throws Exception { ClientSession sendSession = cf.createSession(false, true, true); server.getAddressSettingsRepository().addMatch(addressA.toString(), new AddressSettings().setAutoCreateAddresses(false)); Set<RoutingType> routingTypes = new HashSet<>(); routingTypes.add(RoutingType.ANYCAST); try { sendSession.createQueue(addressA, RoutingType.MULTICAST, queueA); fail("Creating a queue here should fail since the queue's address doesn't exist and auto-create-addresses = false."); } catch (Exception e) { assertTrue(e instanceof ActiveMQException); ActiveMQException ae = (ActiveMQException) e; assertEquals(ActiveMQExceptionType.ADDRESS_DOES_NOT_EXIST, ae.getType()); } sendSession.close(); } }
server0.getConfiguration().setConnectorConfigurations(connectors); server0.getConfiguration().setBridgeConfigurations(bridgeConfigs); server0.getConfiguration().setQueueConfigurations(queueConfigs0); session0 = csf0.createSession(false, true, true); session1 = csf1.createSession(false, true, true); ClientProducer prod0 = session0.createProducer(testAddress); session1.start(); Bridge bridge = server0.getClusterManager().getBridges().get(bridgeName); SimpleString propKey = new SimpleString("propkey"); final Queue queue = (Queue) server0.getPostOffice().getBinding(new SimpleString(queueName)).getBindable(); ClientMessage message = session0.createMessage(false); message.putIntProperty(propKey, i); forwardingConnection.fail(new ActiveMQException(ActiveMQExceptionType.UNBLOCKED));
@Test public void testExceptionWhileDelivering() throws Exception { queue = server.createQueue(QUEUE, RoutingType.ANYCAST, QUEUE, null, true, false); HangInterceptor hangInt = new HangInterceptor(); try { locator.addIncomingInterceptor(hangInt); ClientSessionFactory factory = locator.createSessionFactory(); ClientSession session = factory.createSession(false, false, false); ClientProducer producer = session.createProducer(QUEUE); ClientConsumer consumer = session.createConsumer(QUEUE); producer.send(session.createMessage(true)); session.commit(); hangInt.close(); session.start(); Assert.assertTrue(hangInt.reusableLatch.await(10, TimeUnit.SECONDS)); hangInt.pendingException = new ActiveMQException(); hangInt.open(); session.close(); session = factory.createSession(false, false); session.start(); consumer = session.createConsumer(QUEUE); ClientMessage msg = consumer.receive(5000); Assert.assertNotNull(msg); msg.acknowledge(); session.commit(); } finally { hangInt.open(); } }
@Test public void testReceiveOnClosedException() throws Exception { ClientSessionFactory cf = createSessionFactory(locator); ClientSession session = cf.createSession(false, true, true); session.createQueue(addressA, queueA, false); ClientConsumer cc = session.createConsumer(queueA); session.start(); session.close(); try { cc.receive(); Assert.fail("should throw exception"); } catch (ActiveMQObjectClosedException oce) { //ok } catch (ActiveMQException e) { Assert.fail("Invalid Exception type:" + e.getType()); } session.close(); }
@Test public void testClientOutgoingInterceptorRejectPacketOnBlockingSend() throws Exception { // must make the call block to exercise the right logic locator.setBlockOnNonDurableSend(true); ClientSessionFactory sf = createSessionFactory(locator); MyOutgoingInterceptor4 interceptor = new MyOutgoingInterceptor4(); sf.getServerLocator().addOutgoingInterceptor(interceptor); ClientSession session = sf.createSession(false, true, true, true); session.createQueue(QUEUE, QUEUE, null, false); ClientProducer producer = session.createProducer(QUEUE); ClientMessage message = session.createMessage(false); try { producer.send(message); Assert.fail(); } catch (ActiveMQException e) { // expected exception Assert.assertTrue(e.getType().getCode() == ActiveMQExceptionType.INTERCEPTOR_REJECTED_PACKET.getCode()); } }