diff options
| author | Robert Godfrey <rgodfrey@apache.org = rgodfrey = Robert Godfrey rgodfrey@apache.org@apache.org> | 2014-04-11 22:48:38 +0000 |
|---|---|---|
| committer | Robert Godfrey <rgodfrey@apache.org = rgodfrey = Robert Godfrey rgodfrey@apache.org@apache.org> | 2014-04-11 22:48:38 +0000 |
| commit | 1e13b57a17562ca81cd9133779ce6fd3d42faee7 (patch) | |
| tree | 44d2ba08f321d7367e049d6c69cb98414f5a6a0d /qpid/java | |
| parent | 85b8f44076e0f66f628bcdf9becc17c5ead45402 (diff) | |
| download | qpid-python-1e13b57a17562ca81cd9133779ce6fd3d42faee7.tar.gz | |
QPID-5683 : [Java Broker] Make the AMQP 1.0 protocol logging available through log4j (like the rest of the broker) rather than java.logging
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@1586792 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'qpid/java')
2 files changed, 93 insertions, 29 deletions
diff --git a/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/transport/ConnectionEndpoint.java b/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/transport/ConnectionEndpoint.java index 92ddad1c67..5c54497b66 100644 --- a/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/transport/ConnectionEndpoint.java +++ b/qpid/java/amqp-1-0-common/src/main/java/org/apache/qpid/amqp_1_0/transport/ConnectionEndpoint.java @@ -21,37 +21,50 @@ package org.apache.qpid.amqp_1_0.transport; +import java.net.SocketAddress; +import java.nio.ByteBuffer; +import java.nio.charset.Charset; +import java.security.Principal; +import java.util.ArrayList; +import java.util.Arrays; import java.util.HashSet; import java.util.Map; import java.util.Set; +import java.util.concurrent.TimeoutException; +import java.util.logging.Level; +import java.util.logging.Logger; + +import javax.security.sasl.SaslException; +import javax.security.sasl.SaslServer; import org.apache.qpid.amqp_1_0.codec.DescribedTypeConstructorRegistry; import org.apache.qpid.amqp_1_0.codec.ValueWriter; import org.apache.qpid.amqp_1_0.framing.AMQFrame; import org.apache.qpid.amqp_1_0.framing.SASLFrame; -import org.apache.qpid.amqp_1_0.type.*; +import org.apache.qpid.amqp_1_0.type.Binary; +import org.apache.qpid.amqp_1_0.type.FrameBody; +import org.apache.qpid.amqp_1_0.type.SaslFrameBody; +import org.apache.qpid.amqp_1_0.type.Symbol; +import org.apache.qpid.amqp_1_0.type.UnsignedInteger; +import org.apache.qpid.amqp_1_0.type.UnsignedShort; +import org.apache.qpid.amqp_1_0.type.codec.AMQPDescribedTypeRegistry; import org.apache.qpid.amqp_1_0.type.security.SaslChallenge; import org.apache.qpid.amqp_1_0.type.security.SaslCode; import org.apache.qpid.amqp_1_0.type.security.SaslInit; import org.apache.qpid.amqp_1_0.type.security.SaslMechanisms; import org.apache.qpid.amqp_1_0.type.security.SaslOutcome; import org.apache.qpid.amqp_1_0.type.security.SaslResponse; -import org.apache.qpid.amqp_1_0.type.transport.*; +import org.apache.qpid.amqp_1_0.type.transport.Attach; +import org.apache.qpid.amqp_1_0.type.transport.Begin; +import org.apache.qpid.amqp_1_0.type.transport.Close; +import org.apache.qpid.amqp_1_0.type.transport.ConnectionError; +import org.apache.qpid.amqp_1_0.type.transport.Detach; +import org.apache.qpid.amqp_1_0.type.transport.Disposition; +import org.apache.qpid.amqp_1_0.type.transport.End; import org.apache.qpid.amqp_1_0.type.transport.Error; -import org.apache.qpid.amqp_1_0.type.codec.AMQPDescribedTypeRegistry; - -import javax.security.sasl.SaslException; -import javax.security.sasl.SaslServer; - -import java.net.SocketAddress; -import java.nio.ByteBuffer; -import java.nio.charset.Charset; -import java.security.Principal; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.concurrent.TimeoutException; -import java.util.logging.Level; -import java.util.logging.Logger; +import org.apache.qpid.amqp_1_0.type.transport.Flow; +import org.apache.qpid.amqp_1_0.type.transport.Open; +import org.apache.qpid.amqp_1_0.type.transport.Transfer; public class ConnectionEndpoint implements DescribedTypeConstructorRegistry.Source, ValueWriter.Registry.Source, @@ -718,13 +731,43 @@ public class ConnectionEndpoint implements DescribedTypeConstructorRegistry.Sour } } - private final Logger _logger = Logger.getLogger("FRM"); + public static interface FrameReceiptLogger + { + boolean isEnabled(); + void received(final SocketAddress remoteAddress, short channel, Object frame); + } + + + + private FrameReceiptLogger _logger = + new FrameReceiptLogger() + { + Logger _underlying = Logger.getLogger("FRM"); + + @Override + public boolean isEnabled() + { + return _underlying.isLoggable(Level.FINE); + } + + @Override + public void received(final SocketAddress remoteAddress, final short channel, final Object frame) + { + _underlying.fine("RECV[" + remoteAddress + "|" + channel + "] : " + frame); + } + + }; + + public void setLogger(final FrameReceiptLogger logger) + { + _logger = logger; + } public synchronized void receive(final short channel, final Object frame) { - if (_logger.isLoggable(Level.FINE)) + if (_logger.isEnabled()) { - _logger.fine("RECV[" + _remoteAddress + "|" + channel + "] : " + frame); + _logger.received(_remoteAddress, channel, frame); } if (frame instanceof FrameBody) { diff --git a/qpid/java/broker-plugins/amqp-1-0-protocol/src/main/java/org/apache/qpid/server/protocol/v1_0/ProtocolEngine_1_0_0_SASL.java b/qpid/java/broker-plugins/amqp-1-0-protocol/src/main/java/org/apache/qpid/server/protocol/v1_0/ProtocolEngine_1_0_0_SASL.java index 03b56bfb74..ef85e019e6 100644 --- a/qpid/java/broker-plugins/amqp-1-0-protocol/src/main/java/org/apache/qpid/server/protocol/v1_0/ProtocolEngine_1_0_0_SASL.java +++ b/qpid/java/broker-plugins/amqp-1-0-protocol/src/main/java/org/apache/qpid/server/protocol/v1_0/ProtocolEngine_1_0_0_SASL.java @@ -28,24 +28,26 @@ import java.security.Principal; import java.security.PrivilegedAction; import java.util.LinkedHashMap; import java.util.Map; -import java.util.logging.Level; -import java.util.logging.Logger; + import javax.security.auth.Subject; import javax.security.sasl.SaslException; import javax.security.sasl.SaslServer; + +import org.apache.log4j.Logger; + import org.apache.qpid.amqp_1_0.codec.FrameWriter; import org.apache.qpid.amqp_1_0.codec.ProtocolHandler; import org.apache.qpid.amqp_1_0.framing.AMQFrame; import org.apache.qpid.amqp_1_0.framing.OversizeFrameException; import org.apache.qpid.amqp_1_0.framing.SASLFrameHandler; -import org.apache.qpid.amqp_1_0.transport.SaslServerProvider; import org.apache.qpid.amqp_1_0.transport.ConnectionEndpoint; import org.apache.qpid.amqp_1_0.transport.Container; import org.apache.qpid.amqp_1_0.transport.FrameOutputHandler; +import org.apache.qpid.amqp_1_0.transport.SaslServerProvider; import org.apache.qpid.amqp_1_0.type.Binary; import org.apache.qpid.amqp_1_0.type.FrameBody; import org.apache.qpid.amqp_1_0.type.Symbol; -import org.apache.qpid.amqp_1_0.type.transport.*; +import org.apache.qpid.amqp_1_0.type.transport.AmqpError; import org.apache.qpid.amqp_1_0.type.transport.Error; import org.apache.qpid.common.QpidProperties; import org.apache.qpid.common.ServerPropertyNames; @@ -185,7 +187,20 @@ public class ProtocolEngine_1_0_0_SASL implements ServerProtocolEngine, FrameOut SubjectCreator subjectCreator = _broker.getSubjectCreator(getLocalAddress()); _endpoint = new ConnectionEndpoint(container, asSaslServerProvider(subjectCreator)); + _endpoint.setLogger(new ConnectionEndpoint.FrameReceiptLogger() + { + @Override + public boolean isEnabled() + { + return FRAME_LOGGER.isDebugEnabled(); + } + @Override + public void received(final SocketAddress remoteAddress, final short channel, final Object frame) + { + FRAME_LOGGER.debug("RECV[" + remoteAddress + "|" + channel + "] : " + frame); + } + }); Map<Symbol,Object> serverProperties = new LinkedHashMap<Symbol, Object>(); serverProperties.put(Symbol.valueOf(ServerPropertyNames.PRODUCT), QpidProperties.getProductName()); serverProperties.put(Symbol.valueOf(ServerPropertyNames.VERSION), QpidProperties.getReleaseVersion()); @@ -196,6 +211,7 @@ public class ProtocolEngine_1_0_0_SASL implements ServerProtocolEngine, FrameOut _endpoint.setRemoteAddress(getRemoteAddress()); _connection = new Connection_1_0(_broker, _endpoint, _connectionId, _port, _transport, subjectCreator); + _endpoint.setConnectionEventListener(_connection); _endpoint.setFrameOutputHandler(this); _endpoint.setSaslFrameOutput(this); @@ -262,13 +278,13 @@ public class ProtocolEngine_1_0_0_SASL implements ServerProtocolEngine, FrameOut try { _lastReadTime = System.currentTimeMillis(); - if(RAW_LOGGER.isLoggable(Level.FINE)) + if(RAW_LOGGER.isDebugEnabled()) { ByteBuffer dup = msg.duplicate(); byte[] data = new byte[dup.remaining()]; dup.get(data); Binary bin = new Binary(data); - RAW_LOGGER.fine("RECV[" + getRemoteAddress() + "] : " + bin.toString()); + RAW_LOGGER.debug("RECV[" + getRemoteAddress() + "] : " + bin.toString()); } _readBytes += msg.remaining(); switch(_state) @@ -454,9 +470,14 @@ public class ProtocolEngine_1_0_0_SASL implements ServerProtocolEngine, FrameOut synchronized (_sendLock) { _lastWriteTime = System.currentTimeMillis(); - if (FRAME_LOGGER.isLoggable(Level.FINE)) + if (FRAME_LOGGER.isDebugEnabled()) { - FRAME_LOGGER.fine("SEND[" + getRemoteAddress() + "|" + amqFrame.getChannel() + "] : " + amqFrame.getFrameBody()); + FRAME_LOGGER.debug("SEND[" + + getRemoteAddress() + + "|" + + amqFrame.getChannel() + + "] : " + + amqFrame.getFrameBody()); } _frameWriter.setValue(amqFrame); @@ -472,13 +493,13 @@ public class ProtocolEngine_1_0_0_SASL implements ServerProtocolEngine, FrameOut dup.flip(); _writtenBytes += dup.limit(); - if (RAW_LOGGER.isLoggable(Level.FINE)) + if (RAW_LOGGER.isDebugEnabled()) { ByteBuffer dup2 = dup.duplicate(); byte[] data = new byte[dup2.remaining()]; dup2.get(data); Binary bin = new Binary(data); - RAW_LOGGER.fine("SEND[" + getRemoteAddress() + "] : " + bin.toString()); + RAW_LOGGER.debug("SEND[" + getRemoteAddress() + "] : " + bin.toString()); } _sender.send(dup); |
