You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by bi...@apache.org on 2012/09/30 16:08:02 UTC
svn commit: r1392027 -
/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/WebApplicationExceptionMapper.java
Author: bimargulies
Date: Sun Sep 30 14:08:02 2012
New Revision: 1392027
URL: http://svn.apache.org/viewvc?rev=1392027&view=rev
Log:
CXF-4528: change the logging severity in WebApplicationExceptionMapper when
the app has a FaultListener that actually asked for logging.
Modified:
cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/WebApplicationExceptionMapper.java
Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/WebApplicationExceptionMapper.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/WebApplicationExceptionMapper.java?rev=1392027&r1=1392026&r2=1392027&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/WebApplicationExceptionMapper.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/WebApplicationExceptionMapper.java Sun Sep 30 14:08:02 2012
@@ -23,7 +23,6 @@ import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.logging.Level;
import java.util.logging.Logger;
-
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.Response;
import javax.ws.rs.ext.ExceptionMapper;
@@ -33,6 +32,13 @@ import org.apache.cxf.logging.FaultListe
import org.apache.cxf.message.Message;
import org.apache.cxf.phase.PhaseInterceptorChain;
+/**
+ * Default exception mapper for {@link WebApplicationException}.
+ * This class interacts with {@link FaultListener}. If the service has a {@link FaultListener},
+ * then this mapper calls it to determine whether to log the exception. In theory, {@link FaultListener}
+ * objects could take other actions, but since they cannot produce a {@link Response}, they
+ * are practically limited to controlling logging.
+ */
public class WebApplicationExceptionMapper
implements ExceptionMapper<WebApplicationException> {
@@ -55,17 +61,26 @@ public class WebApplicationExceptionMapp
}
if (flogger != null || LOG.isLoggable(Level.FINE)) {
String errorMessage = buildErrorMessage(r, ex);
-
- boolean doDefault =
- flogger != null ? flogger.faultOccurred(ex, errorMessage, msg) : true;
- if (doDefault && LOG.isLoggable(Level.FINE)) {
- LOG.log(Level.FINE, errorMessage, ex);
+
+ if (flogger != null) {
+ if (flogger.faultOccurred(ex, errorMessage, msg)) {
+ LOG.log(Level.INFO, errorMessage, ex);
+ }
+ } else {
+ if (LOG.isLoggable(Level.FINE)) {
+ LOG.log(Level.FINE, errorMessage, ex);
+ /*
+ * only print a stack trace if we are logging FINE.
+ * If there is a listener, let it print the stack trace if
+ * wants one.
+ */
+ if (printStackTrace) {
+ LOG.fine(getStackTrace(ex));
+ }
+ }
}
}
- if (printStackTrace) {
- LOG.warning(getStackTrace(ex));
- }
-
+
return r;
}
@@ -89,7 +104,12 @@ public class WebApplicationExceptionMapp
ex.printStackTrace(new PrintWriter(sw));
return sw.toString();
}
-
+
+ /**
+ * Control whether this mapper logs backtraces. If there is no {@link FaultListener},
+ * and this is <tt>true</tt>, this mapper will log the stack trace at FINE.
+ * @param printStackTrace whether to log stack trace.
+ */
public void setPrintStackTrace(boolean printStackTrace) {
this.printStackTrace = printStackTrace;
}