Repository: cxf Updated Branches: refs/heads/master cf252d226 -> 09893c174
[CXF-7281] Create new Logging annotation that allows to configure all settings Project: http://git-wip-us.apache.org/repos/asf/cxf/repo Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/09893c17 Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/09893c17 Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/09893c17 Branch: refs/heads/master Commit: 09893c1747d823b3456a28fc49468ed91e456f2d Parents: cf252d2 Author: Christian Schneider <[email protected]> Authored: Mon Mar 13 16:57:59 2017 +0100 Committer: Christian Schneider <[email protected]> Committed: Mon Mar 13 17:24:03 2017 +0100 ---------------------------------------------------------------------- .../org/apache/cxf/annotations/Logging.java | 1 + .../interceptor/AbstractLoggingInterceptor.java | 1 + .../apache/cxf/interceptor/LoggingMessage.java | 1 + rt/databinding/aegis/pom.xml | 5 - rt/features/logging/README.md | 9 ++ .../ext/logging/AbstractLoggingInterceptor.java | 3 +- .../org/apache/cxf/ext/logging/Logging.java | 63 +++++++++ .../logging/LoggingBusLifecycleListener.java | 2 +- .../ext/logging/LoggingFactoryBeanListener.java | 57 +-------- .../logging/OldLoggingFactoryBeanListener.java | 128 +++++++++++++++++++ .../resources/META-INF/cxf/bus-extensions.txt | 1 + 11 files changed, 211 insertions(+), 60 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cxf/blob/09893c17/core/src/main/java/org/apache/cxf/annotations/Logging.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/cxf/annotations/Logging.java b/core/src/main/java/org/apache/cxf/annotations/Logging.java index 3300f16..2d3dd50 100644 --- a/core/src/main/java/org/apache/cxf/annotations/Logging.java +++ b/core/src/main/java/org/apache/cxf/annotations/Logging.java @@ -31,6 +31,7 @@ import org.apache.cxf.interceptor.AbstractLoggingInterceptor; /** * Enables message Logging */ +@Deprecated @Documented @Retention(RetentionPolicy.RUNTIME) @Target({ ElementType.TYPE }) http://git-wip-us.apache.org/repos/asf/cxf/blob/09893c17/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 14838e3..eebccbd 100644 --- a/core/src/main/java/org/apache/cxf/interceptor/AbstractLoggingInterceptor.java +++ b/core/src/main/java/org/apache/cxf/interceptor/AbstractLoggingInterceptor.java @@ -52,6 +52,7 @@ import org.apache.cxf.staxutils.StaxUtils; * A simple logging handler which outputs the bytes of the message to the * Logger. */ +@Deprecated public abstract class AbstractLoggingInterceptor extends AbstractPhaseInterceptor<Message> { public static final int DEFAULT_LIMIT = 48 * 1024; protected static final String BINARY_CONTENT_MESSAGE = "--- Binary Content ---"; http://git-wip-us.apache.org/repos/asf/cxf/blob/09893c17/core/src/main/java/org/apache/cxf/interceptor/LoggingMessage.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/cxf/interceptor/LoggingMessage.java b/core/src/main/java/org/apache/cxf/interceptor/LoggingMessage.java index a81bdfb..341664c 100644 --- a/core/src/main/java/org/apache/cxf/interceptor/LoggingMessage.java +++ b/core/src/main/java/org/apache/cxf/interceptor/LoggingMessage.java @@ -20,6 +20,7 @@ package org.apache.cxf.interceptor; import java.util.concurrent.atomic.AtomicInteger; +@Deprecated public final class LoggingMessage { public static final String ID_KEY = LoggingMessage.class.getName() + ".ID"; private static final AtomicInteger ID = new AtomicInteger(); http://git-wip-us.apache.org/repos/asf/cxf/blob/09893c17/rt/databinding/aegis/pom.xml ---------------------------------------------------------------------- diff --git a/rt/databinding/aegis/pom.xml b/rt/databinding/aegis/pom.xml index 96541fe..ba0ad6b 100644 --- a/rt/databinding/aegis/pom.xml +++ b/rt/databinding/aegis/pom.xml @@ -84,11 +84,6 @@ </dependency> <dependency> <groupId>org.apache.cxf</groupId> - <artifactId>cxf-rt-features-logging</artifactId> - <version>${project.version}</version> - </dependency> - <dependency> - <groupId>org.apache.cxf</groupId> <artifactId>cxf-rt-frontend-jaxws</artifactId> <version>${project.version}</version> <scope>test</scope> http://git-wip-us.apache.org/repos/asf/cxf/blob/09893c17/rt/features/logging/README.md ---------------------------------------------------------------------- diff --git a/rt/features/logging/README.md b/rt/features/logging/README.md new file mode 100644 index 0000000..46d8a39 --- /dev/null +++ b/rt/features/logging/README.md @@ -0,0 +1,9 @@ +# CXF Message logging + +See [Userguide - Message Logging](http://cxf.apache.org/docs/message-logging.html) + +## Tests + +* JAX-WS: org.apache.cxf.jaxws.logging.SOAPLoggingTest +* JAX-RS: tbd + http://git-wip-us.apache.org/repos/asf/cxf/blob/09893c17/rt/features/logging/src/main/java/org/apache/cxf/ext/logging/AbstractLoggingInterceptor.java ---------------------------------------------------------------------- diff --git a/rt/features/logging/src/main/java/org/apache/cxf/ext/logging/AbstractLoggingInterceptor.java b/rt/features/logging/src/main/java/org/apache/cxf/ext/logging/AbstractLoggingInterceptor.java index ba9b678..b4abe55 100644 --- a/rt/features/logging/src/main/java/org/apache/cxf/ext/logging/AbstractLoggingInterceptor.java +++ b/rt/features/logging/src/main/java/org/apache/cxf/ext/logging/AbstractLoggingInterceptor.java @@ -31,10 +31,11 @@ import org.apache.cxf.phase.AbstractPhaseInterceptor; public abstract class AbstractLoggingInterceptor extends AbstractPhaseInterceptor<Message> { public static final int DEFAULT_LIMIT = 48 * 1024; + public static final int DEFAULT_THRESHOLD = -1; public static final String CONTENT_SUPPRESSED = "--- Content suppressed ---"; private static final String LIVE_LOGGING_PROP = "org.apache.cxf.logging.enable"; protected int limit = DEFAULT_LIMIT; - protected long threshold = -1; + protected long threshold = DEFAULT_THRESHOLD; protected boolean logBinary; protected boolean logMultipart = true; http://git-wip-us.apache.org/repos/asf/cxf/blob/09893c17/rt/features/logging/src/main/java/org/apache/cxf/ext/logging/Logging.java ---------------------------------------------------------------------- diff --git a/rt/features/logging/src/main/java/org/apache/cxf/ext/logging/Logging.java b/rt/features/logging/src/main/java/org/apache/cxf/ext/logging/Logging.java new file mode 100644 index 0000000..97387a2 --- /dev/null +++ b/rt/features/logging/src/main/java/org/apache/cxf/ext/logging/Logging.java @@ -0,0 +1,63 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.cxf.ext.logging; + +import java.lang.annotation.Documented; +import java.lang.annotation.ElementType; +import java.lang.annotation.Inherited; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * Enables message Logging + */ +@Documented +@Retention(RetentionPolicy.RUNTIME) +@Target({ ElementType.TYPE }) +@Inherited +public @interface Logging { + /** + * The size limit at which messages are truncated in the log + */ + int limit() default AbstractLoggingInterceptor.DEFAULT_LIMIT; + + /** + * Size limit when messages are written to disk. + * -1 means do not write to disk. + */ + int inMemThresHold() default AbstractLoggingInterceptor.DEFAULT_THRESHOLD; + + /** + * For XML content, turn on pretty printing in the logs + */ + boolean pretty() default false; + + /** + * Ignore binary payloads by default + */ + boolean logBinary() default false; + + /** + * Ignore binary payloads by default + */ + boolean logMultiplart() default true; +} + http://git-wip-us.apache.org/repos/asf/cxf/blob/09893c17/rt/features/logging/src/main/java/org/apache/cxf/ext/logging/LoggingBusLifecycleListener.java ---------------------------------------------------------------------- diff --git a/rt/features/logging/src/main/java/org/apache/cxf/ext/logging/LoggingBusLifecycleListener.java b/rt/features/logging/src/main/java/org/apache/cxf/ext/logging/LoggingBusLifecycleListener.java index 98f1e74..9f47c30 100644 --- a/rt/features/logging/src/main/java/org/apache/cxf/ext/logging/LoggingBusLifecycleListener.java +++ b/rt/features/logging/src/main/java/org/apache/cxf/ext/logging/LoggingBusLifecycleListener.java @@ -24,7 +24,7 @@ import org.apache.cxf.buslifecycle.BusLifeCycleListener; import org.apache.cxf.buslifecycle.BusLifeCycleManager; /** - * + * Add LoggingFeature based on system properties */ public class LoggingBusLifecycleListener implements BusLifeCycleListener { http://git-wip-us.apache.org/repos/asf/cxf/blob/09893c17/rt/features/logging/src/main/java/org/apache/cxf/ext/logging/LoggingFactoryBeanListener.java ---------------------------------------------------------------------- diff --git a/rt/features/logging/src/main/java/org/apache/cxf/ext/logging/LoggingFactoryBeanListener.java b/rt/features/logging/src/main/java/org/apache/cxf/ext/logging/LoggingFactoryBeanListener.java index 6af2b17..6e0e66a 100644 --- a/rt/features/logging/src/main/java/org/apache/cxf/ext/logging/LoggingFactoryBeanListener.java +++ b/rt/features/logging/src/main/java/org/apache/cxf/ext/logging/LoggingFactoryBeanListener.java @@ -19,37 +19,17 @@ package org.apache.cxf.ext.logging; -import java.io.File; -import java.io.FileWriter; -import java.io.PrintWriter; -import java.net.URI; - import org.apache.cxf.Bus; - -import org.apache.cxf.annotations.Logging; -import org.apache.cxf.common.util.StringUtils; import org.apache.cxf.endpoint.Endpoint; import org.apache.cxf.endpoint.Server; -import org.apache.cxf.ext.logging.event.LogEventSender; -import org.apache.cxf.ext.logging.event.PrintWriterEventSender; import org.apache.cxf.service.factory.AbstractServiceFactoryBean; import org.apache.cxf.service.factory.FactoryBeanListener; -import org.apache.cxf.service.factory.FactoryBeanListenerManager; /** - * + * Add LoggingFeature if Logging annotation is present on class */ public class LoggingFactoryBeanListener implements FactoryBeanListener { - public LoggingFactoryBeanListener(Bus b) { - FactoryBeanListenerManager m = b.getExtension(FactoryBeanListenerManager.class); - for (FactoryBeanListener f : m.getListeners()) { - if (f.getClass().getSimpleName().equals("OldLoggingFactoryBeanListener")) { - m.removeListener(f); - } - } - } - /** {@inheritDoc}*/ public void handleEvent(Event ev, AbstractServiceFactoryBean factory, Object... args) { switch (ev) { @@ -78,44 +58,15 @@ public class LoggingFactoryBeanListener implements FactoryBeanListener { //do nothing } } - - - private LogEventSender createEventSender(String location) { - if (StringUtils.isEmpty(location)) { - return null; - } - if ("<stdout>".equals(location)) { - return new PrintWriterEventSender(System.out); - } else if ("<stderr>".equals(location)) { - return new PrintWriterEventSender(System.err); - } else if (location.startsWith("file:")) { - try { - URI uri = new URI(location); - File file = new File(uri); - PrintWriter writer = new PrintWriter(new FileWriter(file, true), true); - return new PrintWriterEventSender(writer); - } catch (Exception ex) { - //stick with default - } - } - return null; - } private void addLoggingSupport(Endpoint endpoint, Bus bus, Logging annotation) { if (annotation != null) { LoggingFeature lf = new LoggingFeature(); + lf.setInMemThreshold(annotation.inMemThresHold()); lf.setPrettyLogging(annotation.pretty()); lf.setLimit(annotation.limit()); - lf.setLogBinary(annotation.showBinary()); - - LogEventSender les = createEventSender(annotation.outLocation()); - if (les != null) { - lf.setOutSender(les); - } - les = createEventSender(annotation.inLocation()); - if (les != null) { - lf.setInSender(les); - } + lf.setLogBinary(annotation.logBinary()); + lf.setLogMultipart(annotation.logBinary()); lf.initialize(endpoint, bus); } } http://git-wip-us.apache.org/repos/asf/cxf/blob/09893c17/rt/features/logging/src/main/java/org/apache/cxf/ext/logging/OldLoggingFactoryBeanListener.java ---------------------------------------------------------------------- diff --git a/rt/features/logging/src/main/java/org/apache/cxf/ext/logging/OldLoggingFactoryBeanListener.java b/rt/features/logging/src/main/java/org/apache/cxf/ext/logging/OldLoggingFactoryBeanListener.java new file mode 100644 index 0000000..6160351 --- /dev/null +++ b/rt/features/logging/src/main/java/org/apache/cxf/ext/logging/OldLoggingFactoryBeanListener.java @@ -0,0 +1,128 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.cxf.ext.logging; + +import java.io.File; +import java.io.FileWriter; +import java.io.PrintWriter; +import java.net.URI; + +import org.apache.cxf.Bus; + +import org.apache.cxf.annotations.Logging; +import org.apache.cxf.common.util.StringUtils; +import org.apache.cxf.endpoint.Endpoint; +import org.apache.cxf.endpoint.Server; +import org.apache.cxf.ext.logging.event.LogEventSender; +import org.apache.cxf.ext.logging.event.PrintWriterEventSender; +import org.apache.cxf.service.factory.AbstractServiceFactoryBean; +import org.apache.cxf.service.factory.FactoryBeanListener; +import org.apache.cxf.service.factory.FactoryBeanListenerManager; + +/** + * + */ +@Deprecated +public class OldLoggingFactoryBeanListener implements FactoryBeanListener { + + public OldLoggingFactoryBeanListener(Bus b) { + FactoryBeanListenerManager m = b.getExtension(FactoryBeanListenerManager.class); + for (FactoryBeanListener f : m.getListeners()) { + if (f.getClass().getSimpleName().equals("OldLoggingFactoryBeanListener")) { + m.removeListener(f); + } + } + } + + /** {@inheritDoc}*/ + public void handleEvent(Event ev, AbstractServiceFactoryBean factory, Object... args) { + switch (ev) { + case ENDPOINT_SELECTED: { + Class<?> cls = (Class<?>)args[2]; + Endpoint ep = (Endpoint)args[1]; + Bus bus = factory.getBus(); + // To avoid the NPE + if (cls == null) { + return; + } + addLoggingSupport(ep, bus, cls.getAnnotation(Logging.class)); + break; + } + case SERVER_CREATED: { + Class<?> cls = (Class<?>)args[2]; + if (cls == null) { + return; + } + Server server = (Server)args[0]; + Bus bus = factory.getBus(); + addLoggingSupport(server.getEndpoint(), bus, cls.getAnnotation(Logging.class)); + break; + } + default: + //do nothing + } + } + + private LogEventSender createEventSender(String location) { + if (StringUtils.isEmpty(location)) { + return null; + } + if ("<stdout>".equals(location)) { + return new PrintWriterEventSender(System.out); + } else if ("<stderr>".equals(location)) { + return new PrintWriterEventSender(System.err); + } else if (location.startsWith("file:")) { + try { + URI uri = new URI(location); + File file = new File(uri); + PrintWriter writer = new PrintWriter(new FileWriter(file, true), true); + return new PrintWriterEventSender(writer); + } catch (Exception ex) { + //stick with default + } + } + return null; + } + + private void addLoggingSupport(Endpoint endpoint, Bus bus, Logging annotation) { + if (annotation != null) { + LoggingFeature lf = new LoggingFeature(); + lf.setPrettyLogging(annotation.pretty()); + lf.setLimit(annotation.limit()); + lf.setLogBinary(annotation.showBinary()); + + lf.setLogBinary(annotation.showBinary()); + + LogEventSender in = createEventSender(annotation.outLocation()); + if (in != null) { + lf.setOutSender(in); + } + LogEventSender out = createEventSender(annotation.inLocation()); + if (out != null) { + lf.setInSender(out); + } + + lf.initialize(endpoint, bus); + } + } + + + +} http://git-wip-us.apache.org/repos/asf/cxf/blob/09893c17/rt/features/logging/src/main/resources/META-INF/cxf/bus-extensions.txt ---------------------------------------------------------------------- diff --git a/rt/features/logging/src/main/resources/META-INF/cxf/bus-extensions.txt b/rt/features/logging/src/main/resources/META-INF/cxf/bus-extensions.txt index cf0d294..74cccca 100644 --- a/rt/features/logging/src/main/resources/META-INF/cxf/bus-extensions.txt +++ b/rt/features/logging/src/main/resources/META-INF/cxf/bus-extensions.txt @@ -1,2 +1,3 @@ org.apache.cxf.ext.logging.LoggingFactoryBeanListener::true +org.apache.cxf.ext.logging.OldLoggingFactoryBeanListener::true org.apache.cxf.ext.logging.LoggingBusLifecycleListener::true
