diff --git a/activemq-broker/src/main/java/org/apache/activemq/broker/TransportConnection.java b/activemq-broker/src/main/java/org/apache/activemq/broker/TransportConnection.java index 84d2101c6c..6a3d8d9051 100755 --- a/activemq-broker/src/main/java/org/apache/activemq/broker/TransportConnection.java +++ b/activemq-broker/src/main/java/org/apache/activemq/broker/TransportConnection.java @@ -309,7 +309,11 @@ public class TransportConnection implements Connection, Task, CommandVisitor { } else if (!stopping.get() && !inServiceException) { inServiceException = true; try { - SERVICELOG.warn("Async error occurred: ", e); + if (SERVICELOG.isDebugEnabled()) { + SERVICELOG.debug("Async error occurred: " + e, e); + } else { + SERVICELOG.warn("Async error occurred: " + e); + } ConnectionError ce = new ConnectionError(); ce.setException(e); if (pendingStop) { diff --git a/activemq-unit-tests/src/test/java/org/apache/activemq/bugs/AMQ3625Test.java b/activemq-unit-tests/src/test/java/org/apache/activemq/bugs/AMQ3625Test.java index a386202ef0..90a88337b4 100644 --- a/activemq-unit-tests/src/test/java/org/apache/activemq/bugs/AMQ3625Test.java +++ b/activemq-unit-tests/src/test/java/org/apache/activemq/bugs/AMQ3625Test.java @@ -26,7 +26,6 @@ import org.junit.After; import org.junit.Before; import org.junit.Test; -import java.io.File; import java.util.concurrent.atomic.AtomicBoolean; import static org.junit.Assert.assertFalse; @@ -84,14 +83,11 @@ public class AMQ3625Test { Appender appender = new DefaultTestAppender() { @Override public void doAppend(LoggingEvent event) { - if (event.getThrowableInformation() != null) { - Throwable t = event.getThrowableInformation().getThrowable(); - if (t instanceof SecurityException) { - authenticationFailed.set(true); - } - if (t instanceof NullPointerException) { - gotNPE.set(true); - } + if (event.getMessage().toString().contains("java.lang.SecurityException")) { + authenticationFailed.set(true); + } + if (event.getMessage().toString().contains("NullPointerException")) { + gotNPE.set(true); } } }; diff --git a/activemq-unit-tests/src/test/java/org/apache/activemq/security/SecurityJMXTest.java b/activemq-unit-tests/src/test/java/org/apache/activemq/security/SecurityJMXTest.java index 1222b3bd18..058a2eb584 100644 --- a/activemq-unit-tests/src/test/java/org/apache/activemq/security/SecurityJMXTest.java +++ b/activemq-unit-tests/src/test/java/org/apache/activemq/security/SecurityJMXTest.java @@ -20,6 +20,8 @@ package org.apache.activemq.security; import java.net.URI; import java.util.HashMap; import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicBoolean; +import java.util.concurrent.atomic.AtomicReference; import javax.jms.Connection; import javax.jms.DeliveryMode; @@ -37,8 +39,14 @@ import junit.framework.TestCase; import org.apache.activemq.ActiveMQConnectionFactory; import org.apache.activemq.broker.BrokerFactory; import org.apache.activemq.broker.BrokerService; +import org.apache.activemq.broker.TransportConnection; +import org.apache.activemq.broker.TransportConnector; import org.apache.activemq.broker.jmx.QueueViewMBean; import org.apache.activemq.command.ActiveMQQueue; +import org.apache.activemq.transport.stomp.StompConnection; +import org.apache.activemq.util.DefaultTestAppender; +import org.apache.log4j.Appender; +import org.apache.log4j.spi.LoggingEvent; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -58,6 +66,45 @@ public class SecurityJMXTest extends TestCase { broker.stop(); } + public void testDeniedViaStompNoStackTrace() throws Exception { + final AtomicBoolean gotExpected = new AtomicBoolean(false); + final AtomicReference stackTrace = new AtomicReference(); + + final Appender appender = new DefaultTestAppender() { + public void doAppend(LoggingEvent event) { + String message = event.getMessage().toString(); + if (message.contains("Async error occurred")) { + gotExpected.set(true); + stackTrace.set(event.getThrowableInformation()); + } + } + }; + + final org.apache.log4j.Logger toVerify = org.apache.log4j.Logger.getLogger(TransportConnection.class.getName() + ".Service"); + + toVerify.addAppender(appender); + + try { + + TransportConnector stomp = broker.addConnector("stomp://localhost:0"); + broker.startTransportConnector(stomp); + StompConnection stompConnection = new StompConnection(); + stompConnection.open(stomp.getConnectUri().getHost(), stomp.getConnectUri().getPort()); + stompConnection.connect("guest", "password"); + // async sub + stompConnection.subscribe("/queue/USERS.Q"); + stompConnection.receive(1000); + stompConnection.close(); + + } finally { + toVerify.removeAppender(appender); + } + + assertTrue("Got async error:", gotExpected.get()); + assertNull("No stack trace", stackTrace.get()); + } + + public void testMoveMessages() throws Exception { JMXServiceURL url = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://localhost:1199/jmxrmi"); JMXConnector connector = JMXConnectorFactory.connect(url, null);