mirror of https://github.com/apache/activemq.git
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
This commit is contained in:
parent
7f9bbbc28e
commit
2f1e430c26
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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 <a href="http://stomp.codehaus.org/">STOMP</a> 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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
|
@ -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 <a href="http://hiramchirino.com">chirino</a>
|
||||
*/
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue