AMQ-5892 - remove default stack trace from service warn to debug level on async error; makes it consistent with transport logging

This commit is contained in:
gtully 2015-07-16 15:17:55 +01:00
parent 0cfd225912
commit b1ea29ed14
3 changed files with 57 additions and 10 deletions

View File

@ -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) {

View File

@ -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);
}
}
};

View File

@ -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<Object> stackTrace = new AtomicReference<Object>();
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);