You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@synapse.apache.org by in...@apache.org on 2010/02/23 10:26:19 UTC

svn commit: r915256 - in /synapse/trunk/java/modules/core/src/main/java/org/apache/synapse: aspects/statistics/ aspects/statistics/view/ core/axis2/

Author: indika
Date: Tue Feb 23 09:26:18 2010
New Revision: 915256

URL: http://svn.apache.org/viewvc?rev=915256&view=rev
Log:
add error infor logging capablity with stats

Added:
    synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/aspects/statistics/ErrorLog.java
    synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/aspects/statistics/ErrorLogFactory.java
Modified:
    synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/aspects/statistics/StatisticsLog.java
    synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/aspects/statistics/StatisticsReporter.java
    synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/aspects/statistics/StatisticsUpdateStrategy.java
    synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/aspects/statistics/view/Statistics.java
    synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/core/axis2/SynapseCallbackReceiver.java

Added: synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/aspects/statistics/ErrorLog.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/aspects/statistics/ErrorLog.java?rev=915256&view=auto
==============================================================================
--- synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/aspects/statistics/ErrorLog.java (added)
+++ synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/aspects/statistics/ErrorLog.java Tue Feb 23 09:26:18 2010
@@ -0,0 +1,81 @@
+/*
+ *  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.synapse.aspects.statistics;
+
+/**
+ * Represent the error logs    *
+ */
+public class ErrorLog {
+
+    /**
+     * alias to identify errors *
+     */
+    private String errorCode;
+
+    /**
+     * related exception *
+     */
+    private Exception exception;
+
+    /**
+     * error message
+     */
+    private String errorMessage;
+
+    /**
+     * error detail
+     */
+    private String errorDetail;
+
+    public ErrorLog(String errorCode) {
+        this.errorCode = errorCode;
+    }
+
+    public String getErrorCode() {
+        return errorCode;
+    }
+
+    public void setErrorCode(String errorCode) {
+        this.errorCode = errorCode;
+    }
+
+    public Exception getException() {
+        return exception;
+    }
+
+    public void setException(Exception exception) {
+        this.exception = exception;
+    }
+
+    public String getErrorMessage() {
+        return errorMessage;
+    }
+
+    public void setErrorMessage(String errorMessage) {
+        this.errorMessage = errorMessage;
+    }
+
+    public String getErrorDetail() {
+        return errorDetail;
+    }
+
+    public void setErrorDetail(String errorDetail) {
+        this.errorDetail = errorDetail;
+    }
+}

Added: synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/aspects/statistics/ErrorLogFactory.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/aspects/statistics/ErrorLogFactory.java?rev=915256&view=auto
==============================================================================
--- synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/aspects/statistics/ErrorLogFactory.java (added)
+++ synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/aspects/statistics/ErrorLogFactory.java Tue Feb 23 09:26:18 2010
@@ -0,0 +1,70 @@
+/*
+ *  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.synapse.aspects.statistics;
+
+import org.apache.synapse.SynapseConstants;
+import org.apache.synapse.config.SynapsePropertiesLoader;
+
+/**
+ * Creates ErrorLogs
+ */
+public class ErrorLogFactory {
+
+    private static boolean enabledErrorInfo;
+
+    static {
+        enabledErrorInfo = Boolean.parseBoolean(SynapsePropertiesLoader.getPropertyValue(
+                "synapse.detailederrorlogging.enable", "false"));
+    }
+
+    /**
+     * Create an ErrorLog from the information in the synapse MessageContext
+     *
+     * @param synCtx MessageContext instance
+     * @return <code>ErrorLog</code> instance
+     */
+    public static ErrorLog createErrorLog(org.apache.synapse.MessageContext synCtx) {
+
+        String errorCode = String.valueOf(synCtx.getProperty(SynapseConstants.ERROR_CODE));
+        ErrorLog errorLog = new ErrorLog(errorCode);
+        if (enabledErrorInfo) {
+            errorLog.setErrorMessage((String) synCtx.getProperty(SynapseConstants.ERROR_MESSAGE));
+            errorLog.setErrorDetail((String) synCtx.getProperty(SynapseConstants.ERROR_DETAIL));
+            errorLog.setException((Exception) synCtx.getProperty(SynapseConstants.ERROR_EXCEPTION));
+        }
+        return errorLog;
+    }
+
+    /**
+     * Create an ErrorLog from the information in the Axis2 MessageContext
+     *
+     * @param axisCtx Axis2 MessageContext instance
+     * @return <code>ErrorLog</code> instance
+     */
+    public static ErrorLog createErrorLog(org.apache.axis2.context.MessageContext axisCtx) {
+        String errorCode = String.valueOf(axisCtx.getProperty(SynapseConstants.ERROR_CODE));
+        ErrorLog errorLog = new ErrorLog(errorCode);
+        if (enabledErrorInfo) {
+            errorLog.setErrorMessage((String) axisCtx.getProperty(SynapseConstants.ERROR_MESSAGE));
+            errorLog.setErrorDetail((String) axisCtx.getProperty(SynapseConstants.ERROR_DETAIL));
+            errorLog.setException((Exception) axisCtx.getProperty(SynapseConstants.ERROR_EXCEPTION));
+        }
+        return errorLog;
+    }
+}

Modified: synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/aspects/statistics/StatisticsLog.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/aspects/statistics/StatisticsLog.java?rev=915256&r1=915255&r2=915256&view=diff
==============================================================================
--- synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/aspects/statistics/StatisticsLog.java (original)
+++ synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/aspects/statistics/StatisticsLog.java Tue Feb 23 09:26:18 2010
@@ -37,6 +37,8 @@
 
     private boolean isEndAnyLog = false;
 
+    private ErrorLog errorLog;
+
     public StatisticsLog(String id, ComponentType componentType) {
         this(id, System.currentTimeMillis(), componentType);
     }
@@ -82,4 +84,12 @@
     public boolean isEndAnyLog() {
         return isEndAnyLog;
     }
+
+    public ErrorLog getErrorLog() {
+        return errorLog;
+    }
+
+    public void setErrorLog(ErrorLog errorLog) {
+        this.errorLog = errorLog;
+    }
 }

Modified: synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/aspects/statistics/StatisticsReporter.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/aspects/statistics/StatisticsReporter.java?rev=915256&r1=915255&r2=915256&view=diff
==============================================================================
--- synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/aspects/statistics/StatisticsReporter.java (original)
+++ synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/aspects/statistics/StatisticsReporter.java Tue Feb 23 09:26:18 2010
@@ -38,11 +38,11 @@
     private static final Log log = LogFactory.getLog(StatisticsReporter.class);
 
     /**
-     * Collects statistics for the given componenet
+     * Collects statistics for the given component
      *
      * @param synCtx        Current Message through synapse
      * @param configurable  Instance that can be configured it's audit
-     * @param componentType Type of the componet need aspect
+     * @param componentType Type of the component need aspect
      */
     public static void reportForComponent(MessageContext synCtx,
                                           StatisticsConfigurable configurable,
@@ -78,8 +78,9 @@
      * Reporting a fault
      *
      * @param synCtx synCtx  Current Message through synapse
+     * @param errorLog the received error information
      */
-    public static void reportFaultForAll(MessageContext synCtx) {
+    public static void reportFaultForAll(MessageContext synCtx , ErrorLog errorLog) {
 
         StatisticsRecord statisticsRecord = StatisticsReporter.getStatisticsRecord(synCtx);
         if (statisticsRecord != null) {
@@ -90,6 +91,7 @@
                     ComponentType.ANY);
             statisticsLog.setResponse(synCtx.isResponse() || synCtx.isFaultResponse());
             statisticsLog.setFault(true);
+            statisticsLog.setErrorLog(errorLog);
             statisticsRecord.collect(statisticsLog);
         }
     }
@@ -130,7 +132,10 @@
                 StatisticsLog statisticsLog = new StatisticsLog(SynapseConstants.SYNAPSE_ASPECTS,
                         ComponentType.ANY);
                 statisticsLog.setResponse(synCtx.isResponse() || synCtx.isFaultResponse());
-                statisticsLog.setFault(isFault(synCtx));
+                if (isFault(synCtx)) {
+                    statisticsLog.setFault(true);
+                    statisticsLog.setErrorLog(ErrorLogFactory.createErrorLog(synCtx));
+                }
                 statisticsLog.setEndAnyLog(true);
                 statisticsRecord.collect(statisticsLog);
                 statisticsRecord.setEndAnyReported(true);
@@ -215,7 +220,10 @@
             String auditID = identifiable.getId();
             StatisticsLog statisticsLog = new StatisticsLog(auditID, componentType);
             statisticsLog.setResponse(synCtx.isResponse() || synCtx.isFaultResponse());
-            statisticsLog.setFault(isFault(synCtx));
+            if (isFault(synCtx)) {
+                statisticsLog.setFault(true);
+                statisticsLog.setErrorLog(ErrorLogFactory.createErrorLog(synCtx));
+            }
             return statisticsLog;
         }
         return null;

Modified: synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/aspects/statistics/StatisticsUpdateStrategy.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/aspects/statistics/StatisticsUpdateStrategy.java?rev=915256&r1=915255&r2=915256&view=diff
==============================================================================
--- synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/aspects/statistics/StatisticsUpdateStrategy.java (original)
+++ synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/aspects/statistics/StatisticsUpdateStrategy.java Tue Feb 23 09:26:18 2010
@@ -88,22 +88,34 @@
                             statistics = statisticsView.getInStatistics();
                         }
                         statistics.update(endLog.getTime() - startLog.getTime(), endLog.isFault());
+                        if (endLog.isFault()) {
+                            statistics.addErrorLog(endLog.getErrorLog());
+                        }
                         break;
                     }
                     case ENDPOINT: {
                         statistics = statisticsView.getInStatistics();
                         statistics.update(endLog.getTime() - startLog.getTime(), endLog.isFault());
+                        if (endLog.isFault()) {
+                            statistics.addErrorLog(endLog.getErrorLog());
+                        }
                         break;
                     }
                     case PROXYSERVICE: {
                         Statistics inStatistics = statisticsView.getInStatistics();
                         Statistics outStatistics = statisticsView.getOutStatistics();
                         inStatistics.update(endLog.getTime() - startLog.getTime(), endLog.isFault());
+                        if (endLog.isFault()) {
+                            inStatistics.addErrorLog(endLog.getErrorLog());
+                        }
                         if (!endLog.isEndAnyLog()) {
                             StatisticsLog lastLog = statisticsLogs.get(statisticsLogs.size() - 1);
                             if (lastLog != endLog) {
                                 outStatistics.update(
                                         lastLog.getTime() - endLog.getTime(), lastLog.isFault());
+                                if (lastLog.isFault()) {
+                                    outStatistics.addErrorLog(lastLog.getErrorLog());
+                                }
                             }
                         }
                         return;

Modified: synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/aspects/statistics/view/Statistics.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/aspects/statistics/view/Statistics.java?rev=915256&r1=915255&r2=915256&view=diff
==============================================================================
--- synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/aspects/statistics/view/Statistics.java (original)
+++ synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/aspects/statistics/view/Statistics.java Tue Feb 23 09:26:18 2010
@@ -18,6 +18,11 @@
  */
 package org.apache.synapse.aspects.statistics.view;
 
+import org.apache.synapse.aspects.statistics.ErrorLog;
+
+import java.util.ArrayList;
+import java.util.List;
+
 /**
  * The statistics data structure
  */
@@ -54,6 +59,10 @@
      * Identifier for this statistics , whose statistics
      */
     private String id;
+    /**
+     * List of Error log entries
+     */
+    private final List<ErrorLog> errorLogs = new ArrayList<ErrorLog>();
 
     public Statistics(String id) {
         this.id = id;
@@ -132,6 +141,16 @@
         this.id = id;
     }
 
+    public List<ErrorLog> getErrorLogs() {
+        return errorLogs;
+    }
+
+    public void addErrorLog(ErrorLog errorLog) {
+        if (errorLog != null) {
+            this.errorLogs.add(errorLog);
+        }
+    }
+
     public String toString() {
         return new StringBuffer()
                 .append("[Avg Processing Time : ").append(avgProcessingTime).append(" ]")
@@ -141,5 +160,4 @@
                 .append(" [Total Fault Response Count : ").append(faultCount).append(" ]")
                 .toString();
     }
-
 }

Modified: synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/core/axis2/SynapseCallbackReceiver.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/core/axis2/SynapseCallbackReceiver.java?rev=915256&r1=915255&r2=915256&view=diff
==============================================================================
--- synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/core/axis2/SynapseCallbackReceiver.java (original)
+++ synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/core/axis2/SynapseCallbackReceiver.java Tue Feb 23 09:26:18 2010
@@ -36,6 +36,7 @@
 import org.apache.synapse.FaultHandler;
 import org.apache.synapse.SynapseConstants;
 import org.apache.synapse.SynapseException;
+import org.apache.synapse.aspects.statistics.ErrorLogFactory;
 import org.apache.synapse.aspects.statistics.StatisticsReporter;
 import org.apache.synapse.config.SynapseConfigUtils;
 import org.apache.synapse.config.SynapseConfiguration;
@@ -162,7 +163,8 @@
         Object o = response.getProperty(SynapseConstants.SENDING_FAULT);
         if (o != null && Boolean.TRUE.equals(o)) {
 
-            StatisticsReporter.reportFaultForAll(synapseOutMsgCtx);
+            StatisticsReporter.reportFaultForAll(synapseOutMsgCtx,
+                    ErrorLogFactory.createErrorLog(response));
             // there is a sending fault. propagate the fault to fault handlers.
 
             Stack faultStack = synapseOutMsgCtx.getFaultStack();