cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject [cxf] branch 3.1.x-fixes updated: [CXF-7389] Logging 404 as FINE in other places
Date Wed, 08 Nov 2017 16:47:28 GMT
This is an automated email from the ASF dual-hosted git repository.

sergeyb pushed a commit to branch 3.1.x-fixes
in repository https://gitbox.apache.org/repos/asf/cxf.git


The following commit(s) were added to refs/heads/3.1.x-fixes by this push:
     new 641a98b  [CXF-7389] Logging 404 as FINE in other places
641a98b is described below

commit 641a98b5a5d4c88e6fb288685609290660a0d830
Author: Sergey Beryozkin <sberyozkin@gmail.com>
AuthorDate: Wed Nov 8 16:32:34 2017 +0000

    [CXF-7389] Logging 404 as FINE in other places
---
 .../apache/cxf/jaxrs/impl/WebApplicationExceptionMapper.java  | 11 ++++++++++-
 .../org/apache/cxf/jaxrs/interceptor/JAXRSInInterceptor.java  |  6 ++++--
 .../src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java  |  2 +-
 3 files changed, 15 insertions(+), 4 deletions(-)

diff --git a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/WebApplicationExceptionMapper.java
b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/WebApplicationExceptionMapper.java
index fa19168..6a06513 100644
--- a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/WebApplicationExceptionMapper.java
+++ b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/WebApplicationExceptionMapper.java
@@ -22,6 +22,7 @@ package org.apache.cxf.jaxrs.impl;
 import java.util.logging.Level;
 import java.util.logging.Logger;
 
+import javax.ws.rs.NotFoundException;
 import javax.ws.rs.WebApplicationException;
 import javax.ws.rs.core.MediaType;
 import javax.ws.rs.core.Response;
@@ -68,7 +69,7 @@ public class WebApplicationExceptionMapper
             ? buildErrorMessage(r, ex) : null; 
         if (flogger == null
             || !flogger.faultOccurred(ex, errorMessage, msg)) {
-            Level level = printStackTrace ? Level.WARNING : Level.FINE;
+            Level level = printStackTrace ? getStackTraceLogLevel(msg, r) : Level.FINE;
             LOG.log(level, ExceptionUtils.getStackTrace(ex));
         }
         
@@ -79,6 +80,14 @@ public class WebApplicationExceptionMapper
         return r;
     }
 
+    protected Level getStackTraceLogLevel(Message msg, Response r) {
+        if (r.getStatus() == 404) {
+            Level logLevel = JAXRSUtils.getExceptionLogLevel(msg, NotFoundException.class);
+            return logLevel == null ? Level.FINE : logLevel;
+        }
+        return Level.WARNING;
+    }
+
     protected String buildErrorMessage(Response r, WebApplicationException ex) {
         StringBuilder sb = new StringBuilder();
         sb.append(ERROR_MESSAGE_START).append(r.getStatus());
diff --git a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSInInterceptor.java
b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSInInterceptor.java
index a32731c..e2f9dc9 100644
--- a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSInInterceptor.java
+++ b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSInInterceptor.java
@@ -27,6 +27,7 @@ import java.util.logging.Level;
 import java.util.logging.Logger;
 
 import javax.ws.rs.HttpMethod;
+import javax.ws.rs.NotFoundException;
 import javax.ws.rs.WebApplicationException;
 import javax.ws.rs.core.MediaType;
 import javax.ws.rs.core.MultivaluedMap;
@@ -163,8 +164,9 @@ public class JAXRSInInterceptor extends AbstractPhaseInterceptor<Message>
{
                                                    BUNDLE,
                                                    message.get(Message.REQUEST_URI),
                                                    rawPath);
-            LOG.warning(errorMsg.toString());
-            Response resp = JAXRSUtils.createResponse(resources, message, errorMsg.toString(),

+            Level logLevel = JAXRSUtils.getExceptionLogLevel(message, NotFoundException.class);
+            LOG.log(logLevel == null ? Level.FINE : logLevel, errorMsg.toString());
+            Response resp = JAXRSUtils.createResponse(resources, message, errorMsg.toString(),
                     Response.Status.NOT_FOUND.getStatusCode(), false);
             throw ExceptionUtils.toNotFoundException(null, resp);
         }
diff --git a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java
index eb5bba9..77c3f06 100644
--- a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java
+++ b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java
@@ -540,7 +540,7 @@ public final class JAXRSUtils {
 
     
     
-    private static Level getExceptionLogLevel(Message message, Class<? extends WebApplicationException>
exClass) {
+    public static Level getExceptionLogLevel(Message message, Class<? extends WebApplicationException>
exClass) {
         Level logLevel = null;
         Object logLevelProp = message.get(exClass.getName() + ".log.level");
         if (logLevelProp != null) {

-- 
To stop receiving notification emails like this one, please contact
['"commits@cxf.apache.org" <commits@cxf.apache.org>'].

Mime
View raw message