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;
}
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);
}
}
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);
}
}
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();
}
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();
}
Aggregations