Repository: cxf Updated Branches: refs/heads/3.1.x-fixes da7b9bf9b -> 45bdda848
[CXF-7000] Updating only core AbstractLoggingInterceptor to check if the logging is required at a given point of time, with thanks to Ingo Weiss Project: http://git-wip-us.apache.org/repos/asf/cxf/repo Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/45bdda84 Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/45bdda84 Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/45bdda84 Branch: refs/heads/3.1.x-fixes Commit: 45bdda8482aa38509cf62283c159bce347894e24 Parents: da7b9bf Author: Sergey Beryozkin <[email protected]> Authored: Fri Aug 19 11:02:32 2016 +0100 Committer: Sergey Beryozkin <[email protected]> Committed: Fri Aug 19 11:04:10 2016 +0100 ---------------------------------------------------------------------- .../cxf/interceptor/AbstractLoggingInterceptor.java | 10 ++++++++++ .../apache/cxf/interceptor/LoggingOutInterceptorTest.java | 7 +++++++ 2 files changed, 17 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cxf/blob/45bdda84/core/src/main/java/org/apache/cxf/interceptor/AbstractLoggingInterceptor.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/cxf/interceptor/AbstractLoggingInterceptor.java b/core/src/main/java/org/apache/cxf/interceptor/AbstractLoggingInterceptor.java index 0a0beb1..73912b7 100644 --- a/core/src/main/java/org/apache/cxf/interceptor/AbstractLoggingInterceptor.java +++ b/core/src/main/java/org/apache/cxf/interceptor/AbstractLoggingInterceptor.java @@ -36,6 +36,7 @@ import javax.xml.stream.XMLStreamWriter; import javax.xml.transform.stream.StreamSource; import org.apache.cxf.common.logging.LogUtils; +import org.apache.cxf.common.util.PropertyUtils; import org.apache.cxf.common.util.StringUtils; import org.apache.cxf.endpoint.Endpoint; import org.apache.cxf.io.CachedOutputStream; @@ -55,6 +56,7 @@ public abstract class AbstractLoggingInterceptor extends AbstractPhaseIntercepto protected static final String BINARY_CONTENT_MESSAGE = "--- Binary Content ---"; protected static final String MULTIPART_CONTENT_MESSAGE = "--- Multipart Content ---"; private static final String MULTIPART_CONTENT_MEDIA_TYPE = "multipart"; + private static final String LIVE_LOGGING_PROP = "org.apache.cxf.logging.enable"; private static final List<String> BINARY_CONTENT_MEDIA_TYPES; static { BINARY_CONTENT_MEDIA_TYPES = new ArrayList<String>(); @@ -78,9 +80,17 @@ public abstract class AbstractLoggingInterceptor extends AbstractPhaseIntercepto super(id, phase); } + protected static boolean isLoggingDisabledNow(Message message) throws Fault { + Object liveLoggingProp = message.getContextualProperty(LIVE_LOGGING_PROP); + return liveLoggingProp != null && PropertyUtils.isFalse(liveLoggingProp); + } + protected abstract Logger getLogger(); Logger getMessageLogger(Message message) { + if (isLoggingDisabledNow(message)) { + return null; + } Endpoint ep = message.getExchange().getEndpoint(); if (ep == null || ep.getEndpointInfo() == null) { return getLogger(); http://git-wip-us.apache.org/repos/asf/cxf/blob/45bdda84/core/src/test/java/org/apache/cxf/interceptor/LoggingOutInterceptorTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/cxf/interceptor/LoggingOutInterceptorTest.java b/core/src/test/java/org/apache/cxf/interceptor/LoggingOutInterceptorTest.java index 832f738..88019e0 100644 --- a/core/src/test/java/org/apache/cxf/interceptor/LoggingOutInterceptorTest.java +++ b/core/src/test/java/org/apache/cxf/interceptor/LoggingOutInterceptorTest.java @@ -24,6 +24,7 @@ import java.io.OutputStream; import java.io.PrintWriter; import java.io.StringWriter; import java.io.Writer; +import java.util.HashMap; import java.util.logging.Logger; import org.apache.cxf.common.logging.LogUtils; @@ -32,9 +33,11 @@ import org.apache.cxf.io.CachedOutputStream; import org.apache.cxf.message.ExchangeImpl; import org.apache.cxf.message.Message; import org.apache.cxf.message.MessageImpl; +import org.apache.cxf.service.model.BindingInfo; import org.apache.cxf.service.model.EndpointInfo; import org.easymock.EasyMock; import org.easymock.IMocksControl; + import org.junit.After; import org.junit.Assert; import org.junit.Before; @@ -153,6 +156,10 @@ public class LoggingOutInterceptorTest extends Assert { Endpoint endpoint = control.createMock(Endpoint.class); EndpointInfo endpointInfo = control.createMock(EndpointInfo.class); EasyMock.expect(endpoint.getEndpointInfo()).andReturn(endpointInfo).anyTimes(); + BindingInfo bindingInfo = control.createMock(BindingInfo.class); + EasyMock.expect(endpointInfo.getBinding()).andReturn(bindingInfo).anyTimes(); + EasyMock.expect(endpointInfo.getProperties()).andReturn(new HashMap<String, Object>()).anyTimes(); + EasyMock.expect(bindingInfo.getProperties()).andReturn(new HashMap<String, Object>()).anyTimes(); control.replay(); Message message = new MessageImpl();
