Search in sources :

Example 6 with ActiveMQInternalErrorException

use of org.apache.activemq.artemis.api.core.ActiveMQInternalErrorException in project activemq-artemis by apache.

the class DummyInterceptor method intercept.

@Override
public boolean intercept(final Packet packet, final RemotingConnection conn) throws ActiveMQException {
    log.debug("DummyFilter packet = " + packet.getClass().getName());
    syncCounter.addAndGet(1);
    if (sendException) {
        throw new ActiveMQInternalErrorException();
    }
    if (changeMessage) {
        if (packet instanceof SessionReceiveMessage) {
            SessionReceiveMessage deliver = (SessionReceiveMessage) packet;
            log.debug("msg = " + deliver.getMessage().getClass().getName());
            deliver.getMessage().putStringProperty(new SimpleString("DummyInterceptor"), new SimpleString("was here"));
        }
    }
    return true;
}
Also used : ActiveMQInternalErrorException(org.apache.activemq.artemis.api.core.ActiveMQInternalErrorException) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) SessionReceiveMessage(org.apache.activemq.artemis.core.protocol.core.impl.wireformat.SessionReceiveMessage)

Example 7 with ActiveMQInternalErrorException

use of org.apache.activemq.artemis.api.core.ActiveMQInternalErrorException in project activemq-artemis by apache.

the class ActiveMQPacketHandler method handleCreateSession.

private void handleCreateSession(final CreateSessionMessage request) {
    boolean incompatibleVersion = false;
    Packet response;
    try {
        Version version = server.getVersion();
        if (!version.isCompatible(request.getVersion())) {
            throw ActiveMQMessageBundle.BUNDLE.incompatibleClientServer();
        }
        if (!server.isStarted()) {
            throw ActiveMQMessageBundle.BUNDLE.serverNotStarted();
        }
        if (connection.getChannelVersion() == 0) {
            connection.setChannelVersion(request.getVersion());
        } else if (connection.getChannelVersion() != request.getVersion()) {
            ActiveMQServerLogger.LOGGER.incompatibleVersionAfterConnect(request.getVersion(), connection.getChannelVersion());
        }
        Channel channel = connection.getChannel(request.getSessionChannelID(), request.getWindowSize());
        ActiveMQPrincipal activeMQPrincipal = null;
        if (request.getUsername() == null) {
            activeMQPrincipal = connection.getDefaultActiveMQPrincipal();
        }
        OperationContext sessionOperationContext = server.newOperationContext();
        Map<SimpleString, RoutingType> routingTypeMap = protocolManager.getPrefixes();
        CoreSessionCallback sessionCallback = new CoreSessionCallback(request.getName(), protocolManager, channel, connection);
        ServerSession session = server.createSession(request.getName(), activeMQPrincipal == null ? request.getUsername() : activeMQPrincipal.getUserName(), activeMQPrincipal == null ? request.getPassword() : activeMQPrincipal.getPassword(), request.getMinLargeMessageSize(), connection, request.isAutoCommitSends(), request.isAutoCommitAcks(), request.isPreAcknowledge(), request.isXA(), request.getDefaultAddress(), sessionCallback, true, sessionOperationContext, routingTypeMap);
        ServerProducer serverProducer = new ServerProducerImpl(session.getName(), "CORE", request.getDefaultAddress());
        session.addProducer(serverProducer);
        ServerSessionPacketHandler handler = new ServerSessionPacketHandler(server, protocolManager, session, server.getStorageManager(), channel);
        channel.setHandler(handler);
        sessionCallback.setSessionHandler(handler);
        // TODO - where is this removed?
        protocolManager.addSessionHandler(request.getName(), handler);
        response = new CreateSessionResponseMessage(server.getVersion().getIncrementingVersion());
    } catch (ActiveMQClusterSecurityException | ActiveMQSecurityException e) {
        ActiveMQServerLogger.LOGGER.securityProblemWhileCreatingSession(e.getMessage());
        response = new ActiveMQExceptionMessage(e);
    } catch (ActiveMQException e) {
        if (e.getType() == ActiveMQExceptionType.INCOMPATIBLE_CLIENT_SERVER_VERSIONS) {
            incompatibleVersion = true;
            logger.debug("Sending ActiveMQException after Incompatible client", e);
        } else {
            ActiveMQServerLogger.LOGGER.failedToCreateSession(e);
        }
        response = new ActiveMQExceptionMessage(e);
    } catch (Exception e) {
        ActiveMQServerLogger.LOGGER.failedToCreateSession(e);
        response = new ActiveMQExceptionMessage(new ActiveMQInternalErrorException());
    }
    // are not compatible
    if (incompatibleVersion) {
        channel1.sendAndFlush(response);
    } else {
        channel1.send(response);
    }
}
Also used : OperationContext(org.apache.activemq.artemis.core.persistence.OperationContext) ServerSessionPacketHandler(org.apache.activemq.artemis.core.protocol.core.ServerSessionPacketHandler) Packet(org.apache.activemq.artemis.core.protocol.core.Packet) ServerSession(org.apache.activemq.artemis.core.server.ServerSession) ActiveMQPrincipal(org.apache.activemq.artemis.core.security.ActiveMQPrincipal) CreateSessionResponseMessage(org.apache.activemq.artemis.core.protocol.core.impl.wireformat.CreateSessionResponseMessage) Channel(org.apache.activemq.artemis.core.protocol.core.Channel) ActiveMQExceptionMessage(org.apache.activemq.artemis.core.protocol.core.impl.wireformat.ActiveMQExceptionMessage) ActiveMQClusterSecurityException(org.apache.activemq.artemis.api.core.ActiveMQClusterSecurityException) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) ActiveMQInternalErrorException(org.apache.activemq.artemis.api.core.ActiveMQInternalErrorException) ServerProducer(org.apache.activemq.artemis.core.server.ServerProducer) ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) ActiveMQClusterSecurityException(org.apache.activemq.artemis.api.core.ActiveMQClusterSecurityException) ActiveMQInternalErrorException(org.apache.activemq.artemis.api.core.ActiveMQInternalErrorException) ActiveMQSecurityException(org.apache.activemq.artemis.api.core.ActiveMQSecurityException) ServerProducerImpl(org.apache.activemq.artemis.core.server.impl.ServerProducerImpl) ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) Version(org.apache.activemq.artemis.core.version.Version) ActiveMQSecurityException(org.apache.activemq.artemis.api.core.ActiveMQSecurityException) RoutingType(org.apache.activemq.artemis.api.core.RoutingType)

Example 8 with ActiveMQInternalErrorException

use of org.apache.activemq.artemis.api.core.ActiveMQInternalErrorException in project activemq-artemis by apache.

the class SessionTest method testCloseSessionOnDestroyedConnection.

// Closing a session if the underlying remoting connection is dead should cleanly
// release all resources
@Test
public void testCloseSessionOnDestroyedConnection() throws Exception {
    // Make sure we have a short connection TTL so sessions will be quickly closed on the server
    server.stop();
    long ttl = 500;
    server.getConfiguration().setConnectionTTLOverride(ttl);
    server.start();
    cf = createSessionFactory(locator);
    ClientSessionInternal clientSession = (ClientSessionInternal) cf.createSession(false, true, true);
    clientSession.createQueue(queueName, queueName, false);
    /**
     * keep unused variables in order to maintain references to both objects
     */
    @SuppressWarnings("unused") ClientProducer producer = clientSession.createProducer();
    @SuppressWarnings("unused") ClientConsumer consumer = clientSession.createConsumer(queueName);
    Assert.assertEquals(1, server.getRemotingService().getConnections().size());
    RemotingConnection rc = clientSession.getConnection();
    rc.fail(new ActiveMQInternalErrorException());
    clientSession.close();
    long start = System.currentTimeMillis();
    while (true) {
        int cons = server.getRemotingService().getConnections().size();
        if (cons == 0) {
            break;
        }
        long now = System.currentTimeMillis();
        if (now - start > 10000) {
            throw new Exception("Timed out waiting for connections to close");
        }
        Thread.sleep(50);
    }
}
Also used : ClientSessionInternal(org.apache.activemq.artemis.core.client.impl.ClientSessionInternal) RemotingConnection(org.apache.activemq.artemis.spi.core.protocol.RemotingConnection) ActiveMQInternalErrorException(org.apache.activemq.artemis.api.core.ActiveMQInternalErrorException) ClientConsumer(org.apache.activemq.artemis.api.core.client.ClientConsumer) ClientProducer(org.apache.activemq.artemis.api.core.client.ClientProducer) ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) ActiveMQInternalErrorException(org.apache.activemq.artemis.api.core.ActiveMQInternalErrorException) Test(org.junit.Test)

Example 9 with ActiveMQInternalErrorException

use of org.apache.activemq.artemis.api.core.ActiveMQInternalErrorException in project activemq-artemis by apache.

the class TemporaryQueueTest method testDeleteTemporaryQueueWhenClientCrash.

@Test
public void testDeleteTemporaryQueueWhenClientCrash() throws Exception {
    session.close();
    sf.close();
    final SimpleString queue = RandomUtil.randomSimpleString();
    SimpleString address = RandomUtil.randomSimpleString();
    // server must received at least one ping from the client to pass
    // so that the server connection TTL is configured with the client value
    final CountDownLatch pingOnServerLatch = new CountDownLatch(1);
    server.getRemotingService().addIncomingInterceptor(new Interceptor() {

        @Override
        public boolean intercept(final Packet packet, final RemotingConnection connection) throws ActiveMQException {
            if (packet.getType() == PacketImpl.PING) {
                pingOnServerLatch.countDown();
            }
            return true;
        }
    });
    ServerLocator locator = createInVMNonHALocator();
    locator.setConnectionTTL(TemporaryQueueTest.CONNECTION_TTL);
    sf = addSessionFactory(createSessionFactory(locator));
    session = sf.createSession(false, true, true);
    session.createTemporaryQueue(address, queue);
    assertTrue("server has not received any ping from the client", pingOnServerLatch.await(2 * server.getConfiguration().getConnectionTtlCheckInterval(), TimeUnit.MILLISECONDS));
    assertEquals(1, server.getConnectionCount());
    RemotingConnection remotingConnection = server.getRemotingService().getConnections().iterator().next();
    final CountDownLatch serverCloseLatch = new CountDownLatch(1);
    remotingConnection.addCloseListener(new CloseListener() {

        @Override
        public void connectionClosed() {
            serverCloseLatch.countDown();
        }
    });
    ((ClientSessionInternal) session).getConnection().fail(new ActiveMQInternalErrorException("simulate a client failure"));
    // let some time for the server to clean the connections
    assertTrue("server has not closed the connection", serverCloseLatch.await(2 * server.getConfiguration().getConnectionTtlCheckInterval() + 2 * TemporaryQueueTest.CONNECTION_TTL, TimeUnit.MILLISECONDS));
    // The next getCount will be asynchronously done at the end of failure. We will wait some time until it has reached there.
    for (long timeout = System.currentTimeMillis() + 5000; timeout > System.currentTimeMillis() && server.getConnectionCount() > 0; ) {
        Thread.sleep(1);
    }
    assertEquals(0, server.getConnectionCount());
    session.close();
    sf.close();
    ServerLocator locator2 = createInVMNonHALocator();
    sf = addSessionFactory(createSessionFactory(locator2));
    session = sf.createSession(false, true, true);
    session.start();
    ActiveMQAction activeMQAction = new ActiveMQAction() {

        @Override
        public void run() throws ActiveMQException {
            session.createConsumer(queue);
        }
    };
    ActiveMQTestBase.expectActiveMQException("temp queue must not exist after the server detected the client crash", ActiveMQExceptionType.QUEUE_DOES_NOT_EXIST, activeMQAction);
    session.close();
    locator2.close();
}
Also used : Packet(org.apache.activemq.artemis.core.protocol.core.Packet) ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) CloseListener(org.apache.activemq.artemis.core.remoting.CloseListener) RemotingConnection(org.apache.activemq.artemis.spi.core.protocol.RemotingConnection) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) ActiveMQInternalErrorException(org.apache.activemq.artemis.api.core.ActiveMQInternalErrorException) CountDownLatch(java.util.concurrent.CountDownLatch) Interceptor(org.apache.activemq.artemis.api.core.Interceptor) ServerLocator(org.apache.activemq.artemis.api.core.client.ServerLocator) Test(org.junit.Test)

Example 10 with ActiveMQInternalErrorException

use of org.apache.activemq.artemis.api.core.ActiveMQInternalErrorException in project activemq-artemis by apache.

the class ExceptionListenerTest method testListenerCalledForOneConnectionAndSessions.

@Test
public void testListenerCalledForOneConnectionAndSessions() throws Exception {
    Connection conn = cf.createConnection();
    CountDownLatch latch = new CountDownLatch(1);
    MyExceptionListener listener = new MyExceptionListener(latch);
    conn.setExceptionListener(listener);
    Session sess1 = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
    Session sess2 = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
    Session sess3 = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
    ClientSessionInternal coreSession0 = (ClientSessionInternal) ((ActiveMQConnection) conn).getInitialSession();
    ClientSessionInternal coreSession1 = (ClientSessionInternal) ((ActiveMQSession) sess1).getCoreSession();
    ClientSessionInternal coreSession2 = (ClientSessionInternal) ((ActiveMQSession) sess2).getCoreSession();
    ClientSessionInternal coreSession3 = (ClientSessionInternal) ((ActiveMQSession) sess3).getCoreSession();
    coreSession0.getConnection().fail(new ActiveMQInternalErrorException("blah"));
    coreSession1.getConnection().fail(new ActiveMQInternalErrorException("blah"));
    coreSession2.getConnection().fail(new ActiveMQInternalErrorException("blah"));
    coreSession3.getConnection().fail(new ActiveMQInternalErrorException("blah"));
    latch.await(5, TimeUnit.SECONDS);
    // Listener should only be called once even if all sessions connections die
    Assert.assertEquals(1, listener.numCalls);
    conn.close();
}
Also used : ClientSessionInternal(org.apache.activemq.artemis.core.client.impl.ClientSessionInternal) Connection(javax.jms.Connection) ActiveMQConnection(org.apache.activemq.artemis.jms.client.ActiveMQConnection) ActiveMQInternalErrorException(org.apache.activemq.artemis.api.core.ActiveMQInternalErrorException) CountDownLatch(java.util.concurrent.CountDownLatch) Session(javax.jms.Session) ActiveMQSession(org.apache.activemq.artemis.jms.client.ActiveMQSession) Test(org.junit.Test)

Aggregations

ActiveMQInternalErrorException (org.apache.activemq.artemis.api.core.ActiveMQInternalErrorException)11 ActiveMQException (org.apache.activemq.artemis.api.core.ActiveMQException)8 Test (org.junit.Test)5 ClientSessionInternal (org.apache.activemq.artemis.core.client.impl.ClientSessionInternal)4 CountDownLatch (java.util.concurrent.CountDownLatch)3 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)3 Packet (org.apache.activemq.artemis.core.protocol.core.Packet)3 ActiveMQExceptionMessage (org.apache.activemq.artemis.core.protocol.core.impl.wireformat.ActiveMQExceptionMessage)3 RemotingConnection (org.apache.activemq.artemis.spi.core.protocol.RemotingConnection)3 Connection (javax.jms.Connection)2 Session (javax.jms.Session)2 ActiveMQClusterSecurityException (org.apache.activemq.artemis.api.core.ActiveMQClusterSecurityException)2 ActiveMQSecurityException (org.apache.activemq.artemis.api.core.ActiveMQSecurityException)2 ServerSessionPacketHandler (org.apache.activemq.artemis.core.protocol.core.ServerSessionPacketHandler)2 ActiveMQConnection (org.apache.activemq.artemis.jms.client.ActiveMQConnection)2 ActiveMQSession (org.apache.activemq.artemis.jms.client.ActiveMQSession)2 RejectedExecutionException (java.util.concurrent.RejectedExecutionException)1 JMSException (javax.jms.JMSException)1 Queue (javax.jms.Queue)1 ActiveMQIOErrorException (org.apache.activemq.artemis.api.core.ActiveMQIOErrorException)1