From 2f1e430c26094e33573f20d761576d1316533767 Mon Sep 17 00:00:00 2001 From: "Hiram R. Chirino" Date: Tue, 6 Mar 2007 20:20:20 +0000 Subject: [PATCH] Better Stomp protocol trace logging support. When the ?transport.trace=true option is specified on a stomp connector, we now log the Stomp protocol frames instead of the ActiveMQ command objects. git-svn-id: https://svn.apache.org/repos/asf/activemq/branches/activemq-4.1@515282 13f79535-47bb-0310-9956-ffa450edef68 --- .../activemq/transport/stomp/StompFrame.java | 24 +++++++++++++++++++ .../stomp/StompSslTransportFactory.java | 11 +++++---- .../stomp/StompTransportFactory.java | 2 ++ .../transport/stomp/StompTransportFilter.java | 20 +++++++++++++++- 4 files changed, 51 insertions(+), 6 deletions(-) diff --git a/activemq-core/src/main/java/org/apache/activemq/transport/stomp/StompFrame.java b/activemq-core/src/main/java/org/apache/activemq/transport/stomp/StompFrame.java index 95668f6b35..7dfec18a95 100644 --- a/activemq-core/src/main/java/org/apache/activemq/transport/stomp/StompFrame.java +++ b/activemq-core/src/main/java/org/apache/activemq/transport/stomp/StompFrame.java @@ -17,8 +17,10 @@ */ package org.apache.activemq.transport.stomp; +import java.util.Arrays; import java.util.Collections; import java.util.HashMap; +import java.util.Iterator; import java.util.Map; import org.apache.activemq.command.Command; @@ -147,4 +149,26 @@ public class StompFrame implements Command { return false; } + public String toString() { + StringBuffer buffer = new StringBuffer(); + buffer.append(getAction()); + buffer.append("\n"); + Map headers = getHeaders(); + for (Iterator iter = headers.entrySet().iterator(); iter.hasNext();) { + Map.Entry entry = (Map.Entry) iter.next(); + buffer.append(entry.getKey()); + buffer.append(":"); + buffer.append(entry.getValue()); + buffer.append("\n"); + } + buffer.append("\n"); + if( getContent()!=null ) { + try { + buffer.append(new String(getContent())); + } catch (Throwable e) { + buffer.append(Arrays.toString(getContent())); + } + } + return buffer.toString(); + } } diff --git a/activemq-core/src/main/java/org/apache/activemq/transport/stomp/StompSslTransportFactory.java b/activemq-core/src/main/java/org/apache/activemq/transport/stomp/StompSslTransportFactory.java index 9d5e96109a..e15914f214 100644 --- a/activemq-core/src/main/java/org/apache/activemq/transport/stomp/StompSslTransportFactory.java +++ b/activemq-core/src/main/java/org/apache/activemq/transport/stomp/StompSslTransportFactory.java @@ -17,13 +17,13 @@ */ package org.apache.activemq.transport.stomp; -import org.apache.activemq.transport.tcp.TcpTransportFactory; -import org.apache.activemq.transport.tcp.SslTransportFactory; -import org.apache.activemq.transport.Transport; -import org.apache.activemq.wireformat.WireFormat; - import java.util.Map; +import org.apache.activemq.transport.Transport; +import org.apache.activemq.transport.tcp.SslTransportFactory; +import org.apache.activemq.util.IntrospectionSupport; +import org.apache.activemq.wireformat.WireFormat; + /** * A STOMP over SSL transport factory * @@ -37,6 +37,7 @@ public class StompSslTransportFactory extends SslTransportFactory { public Transport compositeConfigure(Transport transport, WireFormat format, Map options) { transport = new StompTransportFilter(transport, new LegacyFrameTranslator()); + IntrospectionSupport.setProperties(transport, options); return super.compositeConfigure(transport, format, options); } } diff --git a/activemq-core/src/main/java/org/apache/activemq/transport/stomp/StompTransportFactory.java b/activemq-core/src/main/java/org/apache/activemq/transport/stomp/StompTransportFactory.java index 47197fe2a9..ba5a90257a 100644 --- a/activemq-core/src/main/java/org/apache/activemq/transport/stomp/StompTransportFactory.java +++ b/activemq-core/src/main/java/org/apache/activemq/transport/stomp/StompTransportFactory.java @@ -21,6 +21,7 @@ import java.util.Map; import org.apache.activemq.transport.Transport; import org.apache.activemq.transport.tcp.TcpTransportFactory; +import org.apache.activemq.util.IntrospectionSupport; import org.apache.activemq.wireformat.WireFormat; /** @@ -36,6 +37,7 @@ public class StompTransportFactory extends TcpTransportFactory { public Transport compositeConfigure(Transport transport, WireFormat format, Map options) { transport = new StompTransportFilter(transport, new LegacyFrameTranslator()); + IntrospectionSupport.setProperties(transport, options); return super.compositeConfigure(transport, format, options); } } \ No newline at end of file diff --git a/activemq-core/src/main/java/org/apache/activemq/transport/stomp/StompTransportFilter.java b/activemq-core/src/main/java/org/apache/activemq/transport/stomp/StompTransportFilter.java index 8fb0e50351..eea9207b22 100644 --- a/activemq-core/src/main/java/org/apache/activemq/transport/stomp/StompTransportFilter.java +++ b/activemq-core/src/main/java/org/apache/activemq/transport/stomp/StompTransportFilter.java @@ -25,6 +25,8 @@ import org.apache.activemq.command.Command; import org.apache.activemq.transport.Transport; import org.apache.activemq.transport.TransportFilter; import org.apache.activemq.util.IOExceptionSupport; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; /** * The StompTransportFilter normally sits on top of a TcpTransport @@ -36,7 +38,7 @@ import org.apache.activemq.util.IOExceptionSupport; * @author chirino */ public class StompTransportFilter extends TransportFilter { - + static final private Log log = LogFactory.getLog(StompTransportFilter.class); private final ProtocolConverter protocolConverter; private final Object sendToActiveMQMutex = new Object(); @@ -44,6 +46,8 @@ public class StompTransportFilter extends TransportFilter { private final FrameTranslator frameTranslator; + private boolean trace; + public StompTransportFilter(Transport next, FrameTranslator translator) { super(next); this.frameTranslator = translator; @@ -61,6 +65,9 @@ public class StompTransportFilter extends TransportFilter { public void onCommand(Object command) { try { + if( trace ) { + log.trace("Received: \n"+command); + } protocolConverter.onStompCommad((StompFrame) command); } catch (IOException e) { onException(e); @@ -76,6 +83,9 @@ public class StompTransportFilter extends TransportFilter { } public void sendToStomp(StompFrame command) throws IOException { + if( trace ) { + log.trace("Sending: \n"+command); + } synchronized(sendToStompMutex) { next.oneway(command); } @@ -85,4 +95,12 @@ public class StompTransportFilter extends TransportFilter { { return frameTranslator; } + + public boolean isTrace() { + return trace; + } + + public void setTrace(boolean trace) { + this.trace = trace; + } }