From 0dc6e0c622c1a49a5c9def37ca9a7bf53d132c3a Mon Sep 17 00:00:00 2001 From: Bosanac Dejan Date: Tue, 17 Nov 2009 13:16:05 +0000 Subject: [PATCH] https://issues.apache.org/activemq/browse/AMQ-2499 - don't show passwords in log files git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@881267 13f79535-47bb-0310-9956-ffa450edef68 --- .../kaha/impl/async/DataFileAppender.java | 29 +++++++++++++++---- .../kaha/impl/async/NIODataFileAppender.java | 21 +++++++++++++- .../activemq/util/IntrospectionSupport.java | 11 +++++-- .../src/test/resources/log4j.properties | 2 +- 4 files changed, 52 insertions(+), 11 deletions(-) diff --git a/activemq-core/src/main/java/org/apache/activemq/kaha/impl/async/DataFileAppender.java b/activemq-core/src/main/java/org/apache/activemq/kaha/impl/async/DataFileAppender.java index f470de6737..1f4fd036d6 100644 --- a/activemq-core/src/main/java/org/apache/activemq/kaha/impl/async/DataFileAppender.java +++ b/activemq-core/src/main/java/org/apache/activemq/kaha/impl/async/DataFileAppender.java @@ -21,6 +21,7 @@ import java.io.InterruptedIOException; import java.io.RandomAccessFile; import java.util.Map; import java.util.concurrent.CountDownLatch; +import java.util.concurrent.atomic.AtomicReference; import org.apache.activemq.util.ByteSequence; import org.apache.activemq.util.DataByteArrayOutputStream; @@ -48,7 +49,7 @@ class DataFileAppender { protected final CountDownLatch shutdownDone = new CountDownLatch(1); protected int maxWriteBatchSize = DEFAULT_MAX_BATCH_SIZE; - private boolean running; + protected boolean running; private Thread thread; public static class WriteKey { @@ -82,6 +83,7 @@ class DataFileAppender { public final WriteCommand first; public final CountDownLatch latch = new CountDownLatch(1); public int size; + public AtomicReference exception = new AtomicReference(); public WriteBatch(DataFile dataFile, WriteCommand write) throws IOException { this.dataFile = dataFile; @@ -179,6 +181,10 @@ class DataFileAppender { } catch (InterruptedException e) { throw new InterruptedIOException(); } + IOException exception = batch.exception.get(); + if (exception != null) { + throw exception; + } } return location; @@ -216,10 +222,7 @@ class DataFileAppender { if (shutdown) { throw new IOException("Async Writter Thread Shutdown"); } - if (firstAsyncException != null) { - throw firstAsyncException; - } - + if (!running) { running = true; thread = new Thread() { @@ -231,6 +234,11 @@ class DataFileAppender { thread.setDaemon(true); thread.setName("ActiveMQ Data File Writer"); thread.start(); + firstAsyncException = null; + } + + if (firstAsyncException != null) { + throw firstAsyncException; } if (nextWriteBatch == null) { @@ -298,6 +306,7 @@ class DataFileAppender { protected void processQueue() { DataFile dataFile = null; RandomAccessFile file = null; + WriteBatch wb = null; try { DataByteArrayOutputStream buff = new DataByteArrayOutputStream(maxWriteBatchSize); @@ -321,7 +330,7 @@ class DataFileAppender { enqueueMutex.notify(); } - WriteBatch wb = (WriteBatch)o; + wb = (WriteBatch)o; if (dataFile != wb.dataFile) { if (file != null) { dataFile.closeRandomAccessFile(file); @@ -406,6 +415,14 @@ class DataFileAppender { } catch (IOException e) { synchronized (enqueueMutex) { firstAsyncException = e; + if (wb != null) { + wb.latch.countDown(); + wb.exception.set(e); + } + if (nextWriteBatch != null) { + nextWriteBatch.latch.countDown(); + nextWriteBatch.exception.set(e); + } } } catch (InterruptedException e) { } finally { diff --git a/activemq-core/src/main/java/org/apache/activemq/kaha/impl/async/NIODataFileAppender.java b/activemq-core/src/main/java/org/apache/activemq/kaha/impl/async/NIODataFileAppender.java index 5fbdf53a20..62a0a84eae 100644 --- a/activemq-core/src/main/java/org/apache/activemq/kaha/impl/async/NIODataFileAppender.java +++ b/activemq-core/src/main/java/org/apache/activemq/kaha/impl/async/NIODataFileAppender.java @@ -47,6 +47,7 @@ class NIODataFileAppender extends DataFileAppender { DataFile dataFile = null; RandomAccessFile file = null; FileChannel channel = null; + WriteBatch wb = null; try { @@ -81,13 +82,14 @@ class NIODataFileAppender extends DataFileAppender { enqueueMutex.notify(); } - WriteBatch wb = (WriteBatch)o; + wb = (WriteBatch)o; if (dataFile != wb.dataFile) { if (file != null) { dataFile.closeRandomAccessFile(file); } dataFile = wb.dataFile; file = dataFile.openRandomAccessFile(true); + System.out.println("new channel?"); channel = file.getChannel(); } @@ -180,16 +182,33 @@ class NIODataFileAppender extends DataFileAppender { } catch (IOException e) { synchronized (enqueueMutex) { firstAsyncException = e; + if (wb != null) { + wb.latch.countDown(); + wb.exception.set(e); + } + if (nextWriteBatch != null) { + nextWriteBatch.latch.countDown(); + nextWriteBatch.exception.set(e); + } } } catch (InterruptedException e) { } finally { try { if (file != null) { dataFile.closeRandomAccessFile(file); + dataFile = null; + file.close(); + file = null; + } + if (channel != null) { + System.out.println("Closing channel"); + channel.close(); + channel = null; } } catch (IOException e) { } shutdownDone.countDown(); + running = false; } } diff --git a/activemq-core/src/main/java/org/apache/activemq/util/IntrospectionSupport.java b/activemq-core/src/main/java/org/apache/activemq/util/IntrospectionSupport.java index f2cbdfc04f..cdb9034e5c 100755 --- a/activemq-core/src/main/java/org/apache/activemq/util/IntrospectionSupport.java +++ b/activemq-core/src/main/java/org/apache/activemq/util/IntrospectionSupport.java @@ -262,23 +262,28 @@ public final class IntrospectionSupport { boolean first = true; for (Iterator iter = entrySet.iterator(); iter.hasNext();) { Map.Entry entry = (Map.Entry)iter.next(); + Object value = entry.getValue(); + Object key = entry.getKey(); if (first) { first = false; } else { buffer.append(", "); } - buffer.append(entry.getKey()); + buffer.append(key); buffer.append(" = "); - appendToString(buffer, entry.getValue()); + + appendToString(buffer, key, value); } buffer.append("}"); return buffer.toString(); } - protected static void appendToString(StringBuffer buffer, Object value) { + protected static void appendToString(StringBuffer buffer, Object key, Object value) { if (value instanceof ActiveMQDestination) { ActiveMQDestination destination = (ActiveMQDestination)value; buffer.append(destination.getQualifiedName()); + } else if (key.toString().contains("password")){ + buffer.append("*****"); } else { buffer.append(value); } diff --git a/activemq-core/src/test/resources/log4j.properties b/activemq-core/src/test/resources/log4j.properties index 980445e997..91348e85b9 100755 --- a/activemq-core/src/test/resources/log4j.properties +++ b/activemq-core/src/test/resources/log4j.properties @@ -18,7 +18,7 @@ # # The logging properties used during tests.. # -log4j.rootLogger=INFO, out, stdout +log4j.rootLogger=DEBUG, out, stdout #log4j.logger.org.apache.activemq=DEBUG