Quantcast

cxf git commit: Revert some of the changes to logging feature and fix the issues using existing concepts

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

cxf git commit: Revert some of the changes to logging feature and fix the issues using existing concepts

Daniel  Kulp
Administrator
Repository: cxf
Updated Branches:
  refs/heads/master 265ac6e07 -> 146b00d19


Revert some of the changes to logging feature and fix the issues using existing concepts


Project: http://git-wip-us.apache.org/repos/asf/cxf/repo
Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/146b00d1
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/146b00d1
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/146b00d1

Branch: refs/heads/master
Commit: 146b00d1947058705c873dffe2ba78ad35c8b03c
Parents: 265ac6e
Author: Daniel Kulp <[hidden email]>
Authored: Thu Feb 16 16:24:05 2017 -0500
Committer: Daniel Kulp <[hidden email]>
Committed: Thu Feb 16 16:24:05 2017 -0500

----------------------------------------------------------------------
 .../apache/cxf/ext/logging/LoggingFeature.java  |   5 -
 .../cxf/ext/logging/LoggingInInterceptor.java   | 172 ++++++-------------
 .../org/apache/cxf/ext/logging/WireTapIn.java   |  10 +-
 .../java/org/apache/cxf/jaxws/ServiceImpl.java  |   2 +-
 .../ws/addr_fromjava/WSAFromJavaTest.java       |   4 +-
 5 files changed, 68 insertions(+), 125 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/146b00d1/rt/features/logging/src/main/java/org/apache/cxf/ext/logging/LoggingFeature.java
----------------------------------------------------------------------
diff --git a/rt/features/logging/src/main/java/org/apache/cxf/ext/logging/LoggingFeature.java b/rt/features/logging/src/main/java/org/apache/cxf/ext/logging/LoggingFeature.java
index 77287df..473dbe7 100644
--- a/rt/features/logging/src/main/java/org/apache/cxf/ext/logging/LoggingFeature.java
+++ b/rt/features/logging/src/main/java/org/apache/cxf/ext/logging/LoggingFeature.java
@@ -49,13 +49,11 @@ public class LoggingFeature extends AbstractFeature {
     private LogEventSender sender;
     private LoggingInInterceptor in;
     private LoggingOutInterceptor out;
-    private WireTapIn wireTapIn;
     private PrettyLoggingFilter prettyFilter;
 
     public LoggingFeature() {
         this.sender = new Slf4jEventSender();
         prettyFilter = new PrettyLoggingFilter(sender);
-        wireTapIn = new WireTapIn();
         in = new LoggingInInterceptor(prettyFilter);
         out = new LoggingOutInterceptor(prettyFilter);
     }
@@ -63,7 +61,6 @@ public class LoggingFeature extends AbstractFeature {
     @Override
     protected void initializeProvider(InterceptorProvider provider, Bus bus) {
 
-        provider.getInInterceptors().add(wireTapIn);
         provider.getInInterceptors().add(in);
         provider.getInFaultInterceptors().add(in);
 
@@ -74,13 +71,11 @@ public class LoggingFeature extends AbstractFeature {
     public void setLimit(int limit) {
         in.setLimit(limit);
         out.setLimit(limit);
-        wireTapIn.setLimit(limit);
     }
 
     public void setInMemThreshold(long inMemThreshold) {
         in.setInMemThreshold(inMemThreshold);
         out.setInMemThreshold(inMemThreshold);
-        wireTapIn.setThreshold(inMemThreshold);
     }
 
     public void setSender(LogEventSender sender) {

http://git-wip-us.apache.org/repos/asf/cxf/blob/146b00d1/rt/features/logging/src/main/java/org/apache/cxf/ext/logging/LoggingInInterceptor.java
----------------------------------------------------------------------
diff --git a/rt/features/logging/src/main/java/org/apache/cxf/ext/logging/LoggingInInterceptor.java b/rt/features/logging/src/main/java/org/apache/cxf/ext/logging/LoggingInInterceptor.java
index a3f3ee4..da2afa1 100644
--- a/rt/features/logging/src/main/java/org/apache/cxf/ext/logging/LoggingInInterceptor.java
+++ b/rt/features/logging/src/main/java/org/apache/cxf/ext/logging/LoggingInInterceptor.java
@@ -18,171 +18,111 @@
  */
 package org.apache.cxf.ext.logging;
 
-import java.io.InputStream;
+import java.io.IOException;
 import java.io.PrintWriter;
-import java.io.Reader;
-import java.io.SequenceInputStream;
+import java.nio.charset.StandardCharsets;
+import java.util.ArrayList;
 import java.util.Collection;
-import java.util.Collections;
 
 import org.apache.cxf.common.injection.NoJSR250Annotations;
 import org.apache.cxf.common.util.StringUtils;
 import org.apache.cxf.ext.logging.event.DefaultLogEventMapper;
-import org.apache.cxf.ext.logging.event.EventType;
 import org.apache.cxf.ext.logging.event.LogEvent;
 import org.apache.cxf.ext.logging.event.LogEventSender;
 import org.apache.cxf.ext.logging.event.PrintWriterEventSender;
 import org.apache.cxf.ext.logging.slf4j.Slf4jEventSender;
-import org.apache.cxf.helpers.IOUtils;
 import org.apache.cxf.interceptor.Fault;
 import org.apache.cxf.io.CachedOutputStream;
 import org.apache.cxf.io.CachedWriter;
-import org.apache.cxf.io.DelegatingInputStream;
 import org.apache.cxf.message.Message;
 import org.apache.cxf.phase.AbstractPhaseInterceptor;
 import org.apache.cxf.phase.Phase;
 import org.apache.cxf.phase.PhaseInterceptor;
 
 /**
- *
+ *
  */
 @NoJSR250Annotations
 public class LoggingInInterceptor extends AbstractLoggingInterceptor {
-    class SendLogEventInterceptor extends AbstractPhaseInterceptor<Message> {
-        SendLogEventInterceptor() {
-            super(Phase.PRE_INVOKE);
+    class LoggingInFaultInterceptor extends AbstractPhaseInterceptor<Message> {
+        LoggingInFaultInterceptor() {
+            super(Phase.RECEIVE);
         }
         @Override
         public void handleMessage(Message message) throws Fault {
-            LogEvent event = message.get(LogEvent.class);
-            if (event != null) {
-                DefaultLogEventMapper mapper = new DefaultLogEventMapper();
-                mapper.setEpInfo(message, event);
-                event.setType(mapper.getEventType(message));
-                message.remove(LogEvent.class);
-                sender.send(event);
-            }
+        }
+        @Override
+        public void handleFault(Message message) throws Fault {
+            LoggingInInterceptor.this.handleMessage(message);
         }
     }
-
+    
+    
     public LoggingInInterceptor() {
         this(new Slf4jEventSender());
     }
+    public LoggingInInterceptor(LogEventSender sender) {
+        super(Phase.PRE_INVOKE, sender);
+    }
     public LoggingInInterceptor(PrintWriter writer) {
         this(new PrintWriterEventSender(writer));
     }
-    public LoggingInInterceptor(LogEventSender sender) {
-        super(Phase.RECEIVE, sender);
-    }
     public Collection<PhaseInterceptor<? extends Message>> getAdditionalInterceptors() {
-        return Collections.singleton(new SendLogEventInterceptor());
+        Collection<PhaseInterceptor<? extends Message>> ret = new ArrayList<>();
+        ret.add(new WireTapIn(limit, threshold));
+        ret.add(new LoggingInFaultInterceptor());
+        return ret;
     }
 
-
-    public void handleFault(Message message) {
-        LogEvent event = message.get(LogEvent.class);
-        if (event != null) {
-            DefaultLogEventMapper mapper = new DefaultLogEventMapper();
-            mapper.setEpInfo(message, event);
-            event.setType(EventType.FAULT_IN);
-            message.remove(LogEvent.class);
-            sender.send(event);
-        }
-    }
     public void handleMessage(Message message) throws Fault {
-        LogEvent event = message.get(LogEvent.class);
-        if (event == null) {
-            createExchangeId(message);
-            event = new DefaultLogEventMapper().map(message);
-            if (shouldLogContent(event)) {
-                addContent(message, event);
-            } else {
-                event.setPayload(AbstractLoggingInterceptor.CONTENT_SUPPRESSED);
-            }
-            // at this point, we have the payload.  However, we may not have the endpoint yet. Delay sending
-            // the event till a little bit later
-            message.put(LogEvent.class, event);
-        }
-    }
-
-    private void addContent(Message message, final LogEvent event) {
-        InputStream is = message.getContent(InputStream.class);
-        if (is != null) {
-            logInputStream(message, is, event);
+        createExchangeId(message);
+        final LogEvent event = new DefaultLogEventMapper().map(message);
+        if (shouldLogContent(event)) {
+            addContent(message, event);
         } else {
-            Reader reader = message.getContent(Reader.class);
-            if (reader != null) {
-                logReader(message, reader, event);
-            }
+            event.setPayload(AbstractLoggingInterceptor.CONTENT_SUPPRESSED);
         }
+        sender.send(event);
     }
 
-    protected void logInputStream(Message message, InputStream is, LogEvent event) {
-        CachedOutputStream bos = new CachedOutputStream();
-        if (threshold > 0) {
-            bos.setThreshold(threshold);
-        }
-        String encoding = event.getEncoding();
+    private void addContent(Message message, final LogEvent event) {
         try {
-            // use the appropriate input stream and restore it later
-            InputStream bis = is instanceof DelegatingInputStream
-                ? ((DelegatingInputStream)is).getInputStream() : is;
-
-
-            //only copy up to the limit since that's all we need to log
-            //we can stream the rest
-            IOUtils.copyAtLeast(bis, bos, limit == -1 ? Integer.MAX_VALUE : limit);
-            bos.flush();
-            bis = new SequenceInputStream(bos.getInputStream(), bis);
-
-            // restore the delegating input stream or the input stream
-            if (is instanceof DelegatingInputStream) {
-                ((DelegatingInputStream)is).setInputStream(bis);
+            CachedOutputStream cos = message.getContent(CachedOutputStream.class);
+            if (cos != null) {
+                handleOutputStream(event, message, cos);
             } else {
-                message.setContent(InputStream.class, bis);
+                CachedWriter writer = message.getContent(CachedWriter.class);
+                if (writer != null) {
+                    handleWriter(event, writer);
+                }
             }
-
-            if (bos.getTempFile() != null) {
-                //large thing on disk...
-                event.setFullContentFile(bos.getTempFile());
-            }
-            if (bos.size() > limit && limit != -1) {
-                event.setTruncated(true);
-            }
-
-            StringBuilder builder = new StringBuilder(limit);
-            if (StringUtils.isEmpty(encoding)) {
-                bos.writeCacheTo(builder, limit);
-            } else {
-                bos.writeCacheTo(builder, encoding, limit);
-            }
-            bos.close();
-            event.setPayload(builder.toString());
-        } catch (Exception e) {
+        } catch (IOException e) {
             throw new Fault(e);
         }
     }
 
-    protected void logReader(Message message, Reader reader, LogEvent event) {
-        try {
-            CachedWriter writer = new CachedWriter();
-            IOUtils.copyAndCloseInput(reader, writer);
-            message.setContent(Reader.class, writer.getReader());
-
-            if (writer.getTempFile() != null) {
-                //large thing on disk...
-                event.setFullContentFile(writer.getTempFile());
-            }
-            if (writer.size() > limit && limit != -1) {
-                event.setTruncated(true);
-            }
-            int max = writer.size() > limit ? (int)limit : (int)writer.size();
-            StringBuilder b = new StringBuilder(max);
-            writer.writeCacheTo(b);
-            event.setPayload(b.toString());
-        } catch (Exception e) {
-            throw new Fault(e);
+    private void handleOutputStream(final LogEvent event, Message message, CachedOutputStream cos) throws IOException {
+        String encoding = (String)message.get(Message.ENCODING);
+        if (StringUtils.isEmpty(encoding)) {
+            encoding = StandardCharsets.UTF_8.name();
         }
+        StringBuilder payload = new StringBuilder();
+        cos.writeCacheTo(payload, encoding, limit);
+        cos.close();
+        event.setPayload(payload.toString());
+        boolean isTruncated = cos.size() > limit && limit != -1;
+        event.setTruncated(isTruncated);
+        event.setFullContentFile(cos.getTempFile());
+    }
+
+    private void handleWriter(final LogEvent event, CachedWriter writer) throws IOException {
+        boolean isTruncated = writer.size() > limit && limit != -1;
+        StringBuilder payload = new StringBuilder();
+        writer.writeCacheTo(payload, limit);
+        event.setPayload(payload.toString());
+        event.setTruncated(isTruncated);
+        event.setFullContentFile(writer.getTempFile());
     }
 
+
 }

http://git-wip-us.apache.org/repos/asf/cxf/blob/146b00d1/rt/features/logging/src/main/java/org/apache/cxf/ext/logging/WireTapIn.java
----------------------------------------------------------------------
diff --git a/rt/features/logging/src/main/java/org/apache/cxf/ext/logging/WireTapIn.java b/rt/features/logging/src/main/java/org/apache/cxf/ext/logging/WireTapIn.java
index f7d4d66..60fc44e 100644
--- a/rt/features/logging/src/main/java/org/apache/cxf/ext/logging/WireTapIn.java
+++ b/rt/features/logging/src/main/java/org/apache/cxf/ext/logging/WireTapIn.java
@@ -33,6 +33,8 @@ import org.apache.cxf.phase.AbstractPhaseInterceptor;
 import org.apache.cxf.phase.Phase;
 
 public class WireTapIn extends AbstractPhaseInterceptor<Message> {
+    private static final String WIRE_TAP_STARTED = WireTapIn.class.getName() + ".Started";
+    
     private long threshold = -1;
     private int limit = AbstractLoggingInterceptor.DEFAULT_LIMIT;
 
@@ -42,12 +44,18 @@ public class WireTapIn extends AbstractPhaseInterceptor<Message> {
      *
      * @param logMessageContent the log message content
      */
-    public WireTapIn() {
+    public WireTapIn(int limit, long threshold) {
         super(Phase.RECEIVE);
+        this.limit = limit;
+        this.threshold = threshold;
     }
 
     @Override
     public void handleMessage(final Message message) throws Fault {
+        if (message.containsKey(WIRE_TAP_STARTED)) {
+            return;
+        }
+        message.put(WIRE_TAP_STARTED, Boolean.TRUE);
         try {
             InputStream is = message.getContent(InputStream.class);
             if (is != null) {

http://git-wip-us.apache.org/repos/asf/cxf/blob/146b00d1/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/ServiceImpl.java
----------------------------------------------------------------------
diff --git a/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/ServiceImpl.java b/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/ServiceImpl.java
index dee7ce5..4ebc8ac 100644
--- a/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/ServiceImpl.java
+++ b/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/ServiceImpl.java
@@ -130,7 +130,7 @@ public class ServiceImpl extends ServiceDelegate {
         }
     }
 
-    void initialize(Bus b, URL url, WebServiceFeature ... f) {
+    final void initialize(Bus b, URL url, WebServiceFeature ... f) {
         if (b == null) {
             b = BusFactory.getThreadDefaultBus(true);
         }

http://git-wip-us.apache.org/repos/asf/cxf/blob/146b00d1/systests/ws-specs/src/test/java/org/apache/cxf/systest/ws/addr_fromjava/WSAFromJavaTest.java
----------------------------------------------------------------------
diff --git a/systests/ws-specs/src/test/java/org/apache/cxf/systest/ws/addr_fromjava/WSAFromJavaTest.java b/systests/ws-specs/src/test/java/org/apache/cxf/systest/ws/addr_fromjava/WSAFromJavaTest.java
index 6a3eb9f..2ab8a04 100644
--- a/systests/ws-specs/src/test/java/org/apache/cxf/systest/ws/addr_fromjava/WSAFromJavaTest.java
+++ b/systests/ws-specs/src/test/java/org/apache/cxf/systest/ws/addr_fromjava/WSAFromJavaTest.java
@@ -131,8 +131,8 @@ public class WSAFromJavaTest extends AbstractWSATestBase {
             assert false;
         }
 
-        assertTrue(output.toString().indexOf("http://cxf.apache.org/input") != -1);
-        assertTrue(input.toString().indexOf("http://cxf.apache.org/fault3") != -1);
+        assertTrue(output.toString(), output.toString().indexOf("http://cxf.apache.org/input") != -1);
+        assertTrue(input.toString(), input.toString().indexOf("http://cxf.apache.org/fault3") != -1);
     }
 
     @Test

Loading...