synapse-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From asan...@apache.org
Subject svn commit: r579098 - in /webservices/synapse/trunk/java/modules: core/src/main/java/org/apache/synapse/ core/src/main/java/org/apache/synapse/config/xml/ core/src/main/java/org/apache/synapse/mediators/ core/src/main/java/org/apache/synapse/mediators/...
Date Tue, 25 Sep 2007 07:05:07 GMT
Author: asankha
Date: Tue Sep 25 00:05:01 2007
New Revision: 579098

URL: http://svn.apache.org/viewvc?rev=579098&view=rev
Log:
Streamline and refactor logging and tracing of information at runtime - PART 1
Add service level (audit) logging depending on the service that handles messages in flight

Modified:
    webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/FaultHandler.java
    webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/SequenceMediatorFactory.java
    webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/SequenceMediatorSerializer.java
    webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/AbstractListMediator.java
    webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/AbstractMediator.java
    webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/GetPropertyFunction.java
    webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/MediatorFaultHandler.java
    webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/base/SequenceMediator.java
    webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/base/SynapseMediator.java
    webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/builtin/DropMediator.java
    webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/builtin/LogMediator.java
    webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/builtin/PropertyMediator.java
    webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/builtin/RMSequenceMediator.java
    webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/builtin/SendMediator.java
    webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/builtin/ValidateMediator.java
    webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/db/AbstractDBMediator.java
    webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/db/DBLookupMediator.java
    webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/db/DBReportMediator.java
    webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/eip/splitter/CloneMediator.java
    webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/ext/ClassMediator.java
    webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/ext/POJOCommandMediator.java
    webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/filters/FilterMediator.java
    webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/filters/InMediator.java
    webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/filters/OutMediator.java
    webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/filters/SwitchMediator.java
    webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/transform/FaultMediator.java
    webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/transform/HeaderMediator.java
    webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/transform/XSLTMediator.java
    webservices/synapse/trunk/java/modules/extensions/src/main/java/org/apache/synapse/mediators/attachment/AttachmentMediator.java
    webservices/synapse/trunk/java/modules/extensions/src/main/java/org/apache/synapse/mediators/bsf/ScriptMediator.java
    webservices/synapse/trunk/java/modules/extensions/src/main/java/org/apache/synapse/mediators/spring/SpringMediator.java
    webservices/synapse/trunk/java/modules/extensions/src/main/java/org/apache/synapse/mediators/throttle/ThrottleMediator.java
    webservices/synapse/trunk/java/modules/samples/src/main/java/samples/mediators/DiscountQuoteMediator.java

Modified: webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/FaultHandler.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/FaultHandler.java?rev=579098&r1=579097&r2=579098&view=diff
==============================================================================
--- webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/FaultHandler.java (original)
+++ webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/FaultHandler.java Tue Sep 25 00:05:01 2007
@@ -19,6 +19,9 @@
 
 package org.apache.synapse;
 
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
 import java.util.Stack;
 import java.io.StringWriter;
 import java.io.Writer;
@@ -33,9 +36,20 @@
  */
 public abstract class FaultHandler {
 
+    private static final Log log = LogFactory.getLog(FaultHandler.class);
+    private static final Log trace = LogFactory.getLog(SynapseConstants.TRACE_LOGGER);
+
     public void handleFault(MessageContext synCtx) {
 
+        boolean traceOn = synCtx.getTracingState() == SynapseConstants.TRACING_ON;
+        boolean traceOrDebugOn = traceOn || log.isDebugEnabled();
+
+        if (traceOrDebugOn) {
+            traceOrDebugWarn(traceOn, "FaultHandler executing impl: " + this.getClass().getName());
+        }
+
         try {
+            synCtx.getServiceLog().info("FaultHandler executing impl: " + this.getClass().getName());
             onFault(synCtx);
 
         } catch (SynapseException e) {
@@ -47,8 +61,16 @@
         }
     }
 
+    /**
+     * Extract and set ERROR_MESSAGE and ERROR_DETAIL to the message context from the Exception
+     * @param synCtx the message context
+     * @param e the exception encountered
+     */
     public void handleFault(MessageContext synCtx, Exception e) {
 
+        boolean traceOn = synCtx.getTracingState() == SynapseConstants.TRACING_ON;
+        boolean traceOrDebugOn = traceOn || log.isDebugEnabled();
+
         if (synCtx.getProperty(SynapseConstants.ERROR_CODE) == null) {
             synCtx.setProperty(SynapseConstants.ERROR_CODE, "00000");
         }
@@ -58,6 +80,16 @@
         }
         synCtx.setProperty(SynapseConstants.ERROR_DETAIL, getStackTrace(e));
 
+        if (traceOrDebugOn) {
+            traceOrDebugWarn(traceOn, "Fault handler - setting ERROR_MESSAGE : " +
+                synCtx.getProperty(SynapseConstants.ERROR_MESSAGE));
+            traceOrDebugWarn(traceOn, "Fault handler - setting ERROR_DETAIL : " +
+                synCtx.getProperty(SynapseConstants.ERROR_DETAIL));
+        }
+
+        synCtx.getServiceLog().warn("Fault handler - setting ERROR_MESSAGE : " +
+            synCtx.getProperty(SynapseConstants.ERROR_MESSAGE));
+
         try {
             onFault(synCtx);
 
@@ -77,10 +109,23 @@
      */
     public abstract void onFault(MessageContext synCtx);
 
+    /**
+     * Get the stack trace into a String
+     * @param aThrowable
+     * @return the stack trace as a string
+     */
     private static String getStackTrace(Throwable aThrowable) {
         final Writer result = new StringWriter();
         final PrintWriter printWriter = new PrintWriter(result);
         aThrowable.printStackTrace(printWriter);
         return result.toString();
     }
+
+    private void traceOrDebugWarn(boolean traceOn, String msg) {
+        if (traceOn) {
+            trace.warn(msg);
+        }
+        log.warn(msg);
+    }
+
 }

Modified: webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/SequenceMediatorFactory.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/SequenceMediatorFactory.java?rev=579098&r1=579097&r2=579098&view=diff
==============================================================================
--- webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/SequenceMediatorFactory.java (original)
+++ webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/SequenceMediatorFactory.java Tue Sep 25 00:05:01 2007
@@ -68,9 +68,9 @@
             String statisticsValue = statistics.getAttributeValue();
             if (statisticsValue != null) {
                 if (XMLConfigConstants.STATISTICS_ENABLE.equals(statisticsValue)) {
-                    seqMediator.setStatisticsEnable(org.apache.synapse.SynapseConstants.STATISTICS_ON);
+                    seqMediator.setStatisticsState(org.apache.synapse.SynapseConstants.STATISTICS_ON);
                 } else if (XMLConfigConstants.STATISTICS_DISABLE.equals(statisticsValue)) {
-                    seqMediator.setStatisticsEnable(org.apache.synapse.SynapseConstants.STATISTICS_OFF);
+                    seqMediator.setStatisticsState(org.apache.synapse.SynapseConstants.STATISTICS_OFF);
                 }
             }
         }
@@ -114,9 +114,9 @@
             String statisticsValue = statistics.getAttributeValue();
             if (statisticsValue != null) {
                 if (XMLConfigConstants.STATISTICS_ENABLE.equals(statisticsValue)) {
-                    seqMediator.setStatisticsEnable(org.apache.synapse.SynapseConstants.STATISTICS_ON);
+                    seqMediator.setStatisticsState(org.apache.synapse.SynapseConstants.STATISTICS_ON);
                 } else if (XMLConfigConstants.STATISTICS_DISABLE.equals(statisticsValue)) {
-                    seqMediator.setStatisticsEnable(org.apache.synapse.SynapseConstants.STATISTICS_OFF);
+                    seqMediator.setStatisticsState(org.apache.synapse.SynapseConstants.STATISTICS_OFF);
                 }
             }
         }

Modified: webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/SequenceMediatorSerializer.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/SequenceMediatorSerializer.java?rev=579098&r1=579097&r2=579098&view=diff
==============================================================================
--- webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/SequenceMediatorSerializer.java (original)
+++ webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/SequenceMediatorSerializer.java Tue Sep 25 00:05:01 2007
@@ -45,7 +45,7 @@
 
     public OMElement serializeAnonymousSequence(OMElement parent, SequenceMediator mediator) {
         OMElement sequence = fac.createOMElement("sequence", synNS);
-        int isEnableStatistics = mediator.getStatisticsEnable();
+        int isEnableStatistics = mediator.getStatisticsState();
         String statisticsValue = null;
         if (isEnableStatistics == org.apache.synapse.SynapseConstants.STATISTICS_ON) {
             statisticsValue = XMLConfigConstants.STATISTICS_ENABLE;
@@ -87,7 +87,7 @@
 
         } else {
 
-            int isEnableStatistics = mediator.getStatisticsEnable();
+            int isEnableStatistics = mediator.getStatisticsState();
             String statisticsValue = null;
             if (isEnableStatistics == org.apache.synapse.SynapseConstants.STATISTICS_ON) {
                 statisticsValue = XMLConfigConstants.STATISTICS_ENABLE;

Modified: webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/AbstractListMediator.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/AbstractListMediator.java?rev=579098&r1=579097&r2=579098&view=diff
==============================================================================
--- webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/AbstractListMediator.java (original)
+++ webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/AbstractListMediator.java Tue Sep 25 00:05:01 2007
@@ -19,8 +19,6 @@
 
 package org.apache.synapse.mediators;
 
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
 import org.apache.synapse.ManagedLifecycle;
 import org.apache.synapse.Mediator;
 import org.apache.synapse.MessageContext;
@@ -31,31 +29,40 @@
 import java.util.List;
 
 /**
- * This class implements the base functionality of a List mediator
+ * This is the base class for all List mediators
  *
  * @see ListMediator
  */
-public abstract class AbstractListMediator extends AbstractMediator implements ListMediator, ManagedLifecycle {
-
-    private static final Log log = LogFactory.getLog(AbstractListMediator.class);
+public abstract class AbstractListMediator extends AbstractMediator
+    implements ListMediator, ManagedLifecycle {
 
+    /** the list of child mediators held. These are executed sequentially */
     protected List mediators = new ArrayList();
 
     public boolean mediate(MessageContext synCtx) {
+
+        int parentsEffectiveTraceState = synCtx.getTracingState();
+        // if I have been explicitly asked to enable or disable tracing, set it to the message
+        // to pass it on; else, do nothing -> i.e. let the parents state flow
+        setEffectiveTraceState(synCtx);
+        int myEffectiveTraceState = synCtx.getTracingState();
+
         try {
-            if (log.isDebugEnabled()) {
-                log.debug("Implicit Sequence <" + getType() + "> :: mediate()");
+            if (isTraceOrDebugOn(isTraceOn(synCtx))) {
+                traceOrDebug(isTraceOn(synCtx), "Sequence <" + getType() + "> :: mediate()");
             }
-            saveAndSetTraceState(synCtx);
+
             for (Iterator it = mediators.iterator(); it.hasNext();) {
                 Mediator m = (Mediator) it.next();
+
+                // ensure correct trace state after each invocation of a mediator
+                synCtx.setTracingState(myEffectiveTraceState);
                 if (!m.mediate(synCtx)) {
                     return false;
                 }
             }
-        }
-        finally {
-            restoreTracingState(synCtx);
+        } finally {
+            synCtx.setTracingState(parentsEffectiveTraceState);
         }
         return true;
     }
@@ -83,26 +90,38 @@
     public Mediator removeChild(int pos) {
         return (Mediator) mediators.remove(pos);
     }
-    
+
+    /**
+     * Initialize child mediators recursively
+     * @param se synapse environment
+     */
     public void init(SynapseEnvironment se) {
         if (log.isDebugEnabled()) {
-            log.debug("init");
+            log.debug("Initializing child mediators");
         }
+
         for (Iterator it = mediators.iterator(); it.hasNext();) {
             Mediator m = (Mediator) it.next();
+
             if (m instanceof ManagedLifecycle) {
-            	((ManagedLifecycle)m).init(se);
+            	((ManagedLifecycle) m).init(se);
             }
         } 
     }
+
+    /**
+     * Destroy child mediators recursively
+     */
     public void destroy() {
         if (log.isDebugEnabled()) {
-            log.debug("destroy");
+            log.debug("Destroying child mediators");
         }
+
         for (Iterator it = mediators.iterator(); it.hasNext();) {
             Mediator m = (Mediator) it.next();
+
             if (m instanceof ManagedLifecycle) {
-            	((ManagedLifecycle)m).destroy();
+            	((ManagedLifecycle) m).destroy();
             }
         } 
     }

Modified: webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/AbstractMediator.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/AbstractMediator.java?rev=579098&r1=579097&r2=579098&view=diff
==============================================================================
--- webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/AbstractMediator.java (original)
+++ webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/AbstractMediator.java Tue Sep 25 00:05:01 2007
@@ -22,22 +22,34 @@
 import org.apache.synapse.SynapseConstants;
 import org.apache.synapse.Mediator;
 import org.apache.synapse.MessageContext;
+import org.apache.synapse.SynapseException;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 
 /**
- * This class is an abstract Mediator, that defines the logging and debugging
+ * This is the superclass of all mediators, and defines common logging, tracing other aspects
+ * for all mediators who extend from this.
  * elements of a mediator class.
  */
 public abstract class AbstractMediator implements Mediator {
 
-    /** The parent tracing state */
-     protected  int parentTraceState = SynapseConstants.TRACING_UNSET;
+    /** the standard log for mediators, will assign the logger for the actual subclass */
+    protected static Log log;
+    /** The runtime trace log for mediators */
+    protected static final Log trace = LogFactory.getLog(SynapseConstants.TRACE_LOGGER);
 
-    /** State of tracing for the current mediator */
+    /** State of tracing for this mediator */
      protected int traceState = SynapseConstants.TRACING_UNSET;
 
     /**
+     * A constructor that makes subclasses pick up the correct logger
+     */
+    protected AbstractMediator() {
+        log = LogFactory.getLog(this.getClass());
+    }
+
+    /**
      * Returns the class name of the mediator
-     *
      * @return the class name of the mediator
      */
     public String getType() {
@@ -51,8 +63,7 @@
 
     /**
      * Returns the tracing state
-     *
-     * @return int
+     * @return the tracing state for this mediator (see SynapseConstants)
      */
     public int getTraceState() {
         return traceState;
@@ -60,41 +71,152 @@
 
     /**
      * Set the tracing state variable
-     *
-     * @param traceState
+     * @param traceState the new tracing state for this mediator (see SynapseConstants)
      */
     public void setTraceState(int traceState) {
         this.traceState = traceState;
     }
 
     /**
-     * This method is used to save previous tracing state and set next the tracing state for a child
-     * mediator
+     * This method is used to save previous tracing state and set next the tracing
+     * state for a child mediator
      *
      * @param synCtx current message
      */
-    public void saveAndSetTraceState(MessageContext synCtx) {
-        parentTraceState = synCtx.getTracingState();
-        synCtx.setTracingState(traceState);
+    public void setEffectiveTraceState(MessageContext synCtx) {
+        // if I have been explicitly asked to enable or disable tracing, use it and pass it on
+        // else, do nothing -> i.e. let the parents state flow
+        if (traceState != SynapseConstants.TRACING_UNSET) {
+            synCtx.setTracingState(traceState);
+        }
     }
 
     /**
-     * This method is used to restore parent tracing state back
-     * @param synCtx the current message
+     * Should this mediator perform tracing? True if its explicitly asked to
+     * trace, or its parent has been asked to trace and it does not reject it
+     * @param parentTraceState parents trace state
+     * @return true if tracing should be performed
      */
-    public void restoreTracingState(MessageContext synCtx){
-        synCtx.setTracingState(parentTraceState);
+    public boolean shouldTrace(int parentTraceState){
+        return
+            (traceState == SynapseConstants.TRACING_ON) ||
+            (traceState == SynapseConstants.TRACING_UNSET &&
+                parentTraceState == SynapseConstants.TRACING_ON);
     }
 
     /**
      * Should this mediator perform tracing? True if its explicitly asked to
      * trace, or its parent has been asked to trace and it does not reject it
-     * @param parentTraceState parents trace state
+     * @param msgCtx the current message
      * @return true if tracing should be performed
      */
-    public boolean shouldTrace(int parentTraceState){
-        return (traceState == SynapseConstants.TRACING_ON) ||
-                (traceState == SynapseConstants.TRACING_UNSET &&
-                parentTraceState == SynapseConstants.TRACING_ON);
+    protected boolean isTraceOn(MessageContext msgCtx) {
+        return
+            (traceState == SynapseConstants.TRACING_ON) ||
+            (traceState == SynapseConstants.TRACING_UNSET &&
+                msgCtx.getTracingState() == SynapseConstants.TRACING_ON);
+    }
+
+    /**
+     * Is tracing or debug logging on?
+     * @param isTraceOn is tracing known to be on?
+     * @return true, if either tracing or debug logging is on
+     */
+    protected boolean isTraceOrDebugOn(boolean isTraceOn) {
+        return isTraceOn || log.isDebugEnabled();
+    }
+
+    /**
+     * Perform Trace and Debug logging of a message @INFO (trace) and DEBUG (log)
+     * @param traceOn is runtime trace on for this message?
+     * @param msg the message to log/trace
+     */
+    protected void traceOrDebug(boolean traceOn, String msg) {
+        if (traceOn) {
+            trace.info(msg);
+        }
+        if (log.isDebugEnabled()) {
+            log.debug(msg);
+        }
+    }
+
+    /**
+     * Perform Trace and Debug logging of a message @WARN
+     * @param traceOn is runtime trace on for this message?
+     * @param msg the message to log/trace
+     */
+    protected void traceOrDebugWarn(boolean traceOn, String msg) {
+        if (traceOn) {
+            trace.warn(msg);
+        }
+        if (log.isDebugEnabled()) {
+            log.warn(msg);
+        }
+    }
+
+    /**
+     * Perform an audit log message to all logs @ INFO. Writes to the general log, the service log
+     * and the trace log (of trace is on)
+     * @param msg the log message
+     * @param msgContext the message context
+     */
+    protected void auditLog(String msg, MessageContext msgContext) {
+        log.info(msg);
+        if (msgContext.getServiceLog() != null) {
+            msgContext.getServiceLog().info(msg);
+        }
+        if (shouldTrace(msgContext.getTracingState())) {
+            trace.info(msg);
+        }
+    }
+
+    /**
+     * Perform an error log message to all logs @ ERROR. Writes to the general log, the service log
+     * and the trace log (of trace is on) and throws a SynapseException
+     * @param msg the log message
+     * @param msgContext the message context
+     */
+    protected void handleException(String msg, MessageContext msgContext) {
+        log.error(msg);
+        if (msgContext.getServiceLog() != null) {
+            msgContext.getServiceLog().error(msg);
+        }
+        if (shouldTrace(msgContext.getTracingState())) {
+            trace.error(msg);
+        }
+        throw new SynapseException(msg);
+    }
+
+    /**
+     * Write an audit entry at WARN and trace and standard logs @WARN
+     * @param msg the message to log
+     * @param msgContext message context
+     */
+    protected void auditWarn(String msg, MessageContext msgContext) {
+        log.warn(msg);
+        if (msgContext.getServiceLog() != null) {
+            msgContext.getServiceLog().warn(msg);
+        }
+        if (shouldTrace(msgContext.getTracingState())) {
+            trace.warn(msg);
+        }
+    }
+
+    /**
+     * Perform an error log message to all logs @ ERROR. Writes to the general log, the service log
+     * and the trace log (of trace is on) and throws a SynapseException
+     * @param msg the log message
+     * @param e an Exception encountered
+     * @param msgContext the message context
+     */
+    protected void handleException(String msg, Exception e, MessageContext msgContext) {
+        log.error(msg, e);
+        if (msgContext.getServiceLog() != null) {
+            msgContext.getServiceLog().error(msg, e);
+        }
+        if (shouldTrace(msgContext.getTracingState())) {
+            trace.error(msg, e);
+        }
+        throw new SynapseException(msg, e);
     }
 }

Modified: webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/GetPropertyFunction.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/GetPropertyFunction.java?rev=579098&r1=579097&r2=579098&view=diff
==============================================================================
--- webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/GetPropertyFunction.java (original)
+++ webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/GetPropertyFunction.java Tue Sep 25 00:05:01 2007
@@ -42,6 +42,7 @@
 public class GetPropertyFunction implements Function {
 
     private static final Log log = LogFactory.getLog(GetPropertyFunction.class);
+    private static final Log trace = LogFactory.getLog(SynapseConstants.TRACE_LOGGER);
 
     /** Synapse Message context*/
     private MessageContext synCtx = null;
@@ -64,61 +65,72 @@
      * @throws FunctionCallException
      */
     public Object call(Context context, List args) throws FunctionCallException {
-        
-        if (args == null) {
-            if (log.isDebugEnabled()) {
-                log.debug("Property key value for lookup was not specified");
-            }
-            return null;
-        }
-        int size = args.size();
-        if (size == 0) {
-            if (log.isDebugEnabled()) {
-                log.debug("Property key value for lookup was not specified");
+
+        boolean traceOn = synCtx.getTracingState() == SynapseConstants.TRACING_ON;
+        boolean traceOrDebugOn = traceOn || log.isDebugEnabled();
+
+        if (args == null || args.size() == 0) {
+            if (traceOrDebugOn) {
+                traceOrDebug(traceOn, "Property key value for lookup is not specified");
             }
             return null;
-        } else if (size == 1) {
-            return evaluate(XMLConfigConstants.SCOPE_DEFAULT, args.get(0), context.getNavigator());
-        } else if (size == 2) {
-            return evaluate(args.get(0), args.get(1), context.getNavigator());
+
         } else {
-            String msg = "Invalid arguments for synapse:get-property(prop-name) 0r  " +
-                    "synapse:get-property(scope,prop-name) XPath function ";
-            if (log.isDebugEnabled()) {
-                log.debug(msg);
+            int size = args.size();
+            if (size == 1) {
+                return evaluate(
+                    XMLConfigConstants.SCOPE_DEFAULT, args.get(0), context.getNavigator());
+
+            } else if (size == 2) {
+                return evaluate(args.get(0), args.get(1), context.getNavigator());
+
+            } else {
+
+                String msg = "Invalid arguments for synapse:get-property(prop-name) 0r  " +
+                    "synapse:get-property(scope, prop-name) XPath function ";
+                if (traceOn) {
+                    trace.error(msg);
+                }
+                log.error(msg);
+                throw new FunctionCallException(msg);
             }
-            throw new FunctionCallException(msg);
         }
     }
 
     /**
-     * Returns the string value of the property using arg. one as key and arg. two as scope
+     * Returns the string value of the property using arg one as key and arg two as scope
      *
-     * @param scopeObject scope will decide from where property will pick (axis2,transport,default(synapse))
+     * @param scopeObject scope will decide from where property will be picked up from
+     *        i.e. axis2, transport, default/synapse
      * @param keyObject the key of the property
-     * @param navigator obect model which can navigating around
-     * @return The String value of property using arg. one as key and arg. two as scope
+     * @param navigator object model which can be used for navigation around
+     * @return The String value of property using arg one as key and arg two as scope
      */
     public Object evaluate(Object scopeObject, Object keyObject, Navigator navigator) {
+
+        boolean traceOn = synCtx.getTracingState() == SynapseConstants.TRACING_ON;
+        boolean traceOrDebugOn = traceOn || log.isDebugEnabled();
+
         if (synCtx == null) {
-            if (log.isDebugEnabled()) {
-                log.debug("Synapse context has not been set for the XPath extension function" +
-                        "'synapse:get-property(prop-name)'");
+            if (traceOrDebugOn) {
+                traceOrDebug(traceOn, "Synapse message context has not been set for the " +
+                    "XPath extension function 'synapse:get-property(prop-name)'");
             }
             return null;
-
         }
+
         String scope = StringFunction.evaluate(scopeObject, navigator);
         String key = StringFunction.evaluate(keyObject, navigator);
 
         if (key == null || "".equals(key)) {
-            if (log.isDebugEnabled()) {
-                log.debug("property-name should be provided when executing " +
-                        "synapse:get-property(scope,prop-name)" +
-                        " or synapse:get-property(prop-name) Xpath function");
+            if (traceOrDebugOn) {
+                traceOrDebug(traceOn,
+                    "property-name should be provided when executing synapse:get-property" +
+                    "(scope,prop-name) or synapse:get-property(prop-name) Xpath function");
             }
             return null;
         }
+        
         if (XMLConfigConstants.SCOPE_DEFAULT.equals(scope)) {
 
             if (SynapseConstants.HEADER_TO.equals(key)) {
@@ -159,27 +171,44 @@
                     return synCtx.getEntry(key);
                 }
             }
-        } else if (XMLConfigConstants.SCOPE_AXIS2.equals(scope) && synCtx instanceof Axis2MessageContext) {
+
+        } else if (XMLConfigConstants.SCOPE_AXIS2.equals(scope)
+            && synCtx instanceof Axis2MessageContext) {
+
             org.apache.axis2.context.MessageContext axis2MessageContext
-                    = ((Axis2MessageContext) synCtx).getAxis2MessageContext();
-            return axis2MessageContext.getConfigurationContext().getProperty(key);
+                = ((Axis2MessageContext) synCtx).getAxis2MessageContext();
+            return axis2MessageContext.getProperty(key);
+
         } else if (XMLConfigConstants.SCOPE_TRANSPORT.equals(scope)
-                && synCtx instanceof Axis2MessageContext) {
+            && synCtx instanceof Axis2MessageContext) {
+
             org.apache.axis2.context.MessageContext axis2MessageContext
-                    = ((Axis2MessageContext) synCtx).getAxis2MessageContext();
+                = ((Axis2MessageContext) synCtx).getAxis2MessageContext();
             Object headers = axis2MessageContext.getProperty(
-                    org.apache.axis2.context.MessageContext.TRANSPORT_HEADERS);
+                org.apache.axis2.context.MessageContext.TRANSPORT_HEADERS);
+
             if (headers != null && headers instanceof Map) {
                 Map headersMap = (HashMap) headers;
                 return headersMap.get(key);
             }
+
         } else {
-            if (log.isDebugEnabled()) {
-                log.debug("Invalid scope : '" + scope + "' has been set for the " +
-                        "synapse:get-property(scope,prop-name) XPath function");
+            if (traceOrDebugOn) {
+                traceOrDebug(traceOn, "Invalid scope : '" + scope + "' has been set for the " +
+                    "synapse:get-property(scope,prop-name) XPath function");
             }
         }
         return null;
     }
+
+    private void traceOrDebug(boolean traceOn, String msg) {
+        if (traceOn) {
+            trace.info(msg);
+        }
+        if (log.isDebugEnabled()) {
+            log.debug(msg);
+        }
+    }
+
 }
 

Modified: webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/MediatorFaultHandler.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/MediatorFaultHandler.java?rev=579098&r1=579097&r2=579098&view=diff
==============================================================================
--- webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/MediatorFaultHandler.java (original)
+++ webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/MediatorFaultHandler.java Tue Sep 25 00:05:01 2007
@@ -19,10 +19,8 @@
 
 package org.apache.synapse.mediators;
 
-import org.apache.synapse.FaultHandler;
-import org.apache.synapse.SynapseException;
-import org.apache.synapse.Mediator;
-import org.apache.synapse.MessageContext;
+import org.apache.synapse.*;
+import org.apache.synapse.mediators.base.SequenceMediator;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
@@ -36,6 +34,7 @@
 public class MediatorFaultHandler extends FaultHandler {
 
     private static final Log log = LogFactory.getLog(MediatorFaultHandler.class);
+    private static final Log trace = LogFactory.getLog(SynapseConstants.TRACE_LOGGER);
 
     /**
      * This holds the fault sequence for the mediator fault handler
@@ -60,9 +59,23 @@
      * @see org.apache.synapse.FaultHandler#handleFault(org.apache.synapse.MessageContext)
      */
     public void onFault(MessageContext synCtx) throws SynapseException {
-        if (log.isDebugEnabled()) {
-            log.debug("MediatorFaultHandler :: handleFault");
+
+        boolean traceOn = synCtx.getTracingState() == SynapseConstants.TRACING_ON;
+        boolean traceOrDebugOn = traceOn || log.isDebugEnabled();
+
+        String name = null;
+        if (faultMediator instanceof SequenceMediator) {
+            name = ((SequenceMediator) faultMediator).getName();
+        }
+        if (name == null) {
+            name = faultMediator.getClass().getName();
         }
+
+        if (traceOrDebugOn) {
+            traceOrDebugWarn(traceOn, "Executing fault handler mediator : " + name);
+        }
+
+        synCtx.getServiceLog().warn("Executing fault sequence mediator : " + name);
         this.faultMediator.mediate(synCtx);
     }
 
@@ -72,7 +85,6 @@
      * @return Mediator specifying the fault sequence for mediator fault handler
      */
     public Mediator getFaultMediator() {
-
         return faultMediator;
     }
 
@@ -82,7 +94,14 @@
      * @param faultMediator Mediator specifying the fault sequence to be used by the handler
      */
     public void setFaultMediator(Mediator faultMediator) {
-
         this.faultMediator = faultMediator;
     }
+
+    private void traceOrDebugWarn(boolean traceOn, String msg) {
+        if (traceOn) {
+            trace.warn(msg);
+        }
+        log.warn(msg);
+    }
+
 }

Modified: webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/base/SequenceMediator.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/base/SequenceMediator.java?rev=579098&r1=579097&r2=579098&view=diff
==============================================================================
--- webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/base/SequenceMediator.java (original)
+++ webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/base/SequenceMediator.java Tue Sep 25 00:05:01 2007
@@ -19,12 +19,9 @@
 
 package org.apache.synapse.mediators.base;
 
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
 import org.apache.synapse.Mediator;
 import org.apache.synapse.SynapseConstants;
 import org.apache.synapse.MessageContext;
-import org.apache.synapse.SynapseException;
 import org.apache.synapse.mediators.AbstractListMediator;
 import org.apache.synapse.mediators.MediatorFaultHandler;
 import org.apache.synapse.statistics.StatisticsUtils;
@@ -44,11 +41,9 @@
  */
 public class SequenceMediator extends AbstractListMediator {
 
-    private static final Log log = LogFactory.getLog(SequenceMediator.class);
-    private static final Log trace = LogFactory.getLog(SynapseConstants.TRACE_LOGGER);
     /** The name of the this sequence */
     private String name = null;
-    /** The local registry key which is used to pick a sequnce definition*/
+    /** The local registry key which is used to pick a sequence definition*/
     private String key = null;
     /** The name of the error handler which is used to handle error during the mediation */
     private String errorHandler = null;
@@ -58,7 +53,7 @@
     private String registryKey = null;
 
     /** To decide to whether statistics should have collected or not  */
-    private int statisticsEnable = SynapseConstants.STATISTICS_UNSET;
+    private int statisticsState = SynapseConstants.STATISTICS_UNSET;
 
     /**
      * If this mediator refers to another named Sequence, execute that. Else
@@ -73,20 +68,24 @@
      */
     public boolean mediate(MessageContext synCtx) {
 
-        if (log.isDebugEnabled()) {
-            log.debug("Sequence mediator <" + (name == null ? "anonymous" : name) + "> :: mediate()");
-        }
-        boolean shouldTrace = shouldTrace(synCtx.getTracingState());
-        if (shouldTrace) {
-            trace.trace("Start : Sequence <" + (name == null ? "anonymous" : name) + ">");
+        boolean statsOn = isStatsOn(synCtx);
+        boolean traceOn = isTraceOn(synCtx);
+        boolean traceOrDebugOn = isTraceOrDebugOn(traceOn);
+
+        if (traceOrDebugOn) {
+            traceOrDebug(traceOn, "Start : Sequence <" + (name == null ? "anonymous" : name) + ">");
         }
+
         if (key == null) {
+
+            // The onError sequence for handling errors which may occur during the
+            // mediation through this sequence
+            Mediator errorHandlerMediator = null;
+
             // Setting Required property to collect the sequence statistics
-            boolean isStatisticsEnable
-                    = (org.apache.synapse.SynapseConstants.STATISTICS_ON == statisticsEnable);
-            if (isStatisticsEnable) {
-                StatisticsStack sequenceStack
-                        = (StatisticsStack) synCtx.getProperty(SynapseConstants.SEQUENCE_STATISTICS_STACK);
+            if (statsOn) {
+                StatisticsStack sequenceStack = (StatisticsStack)
+                    synCtx.getProperty(SynapseConstants.SEQUENCE_STATISTICS_STACK);
                 if (sequenceStack == null) {
                     sequenceStack = new SequenceStatisticsStack();
                     synCtx.setProperty(SynapseConstants.SEQUENCE_STATISTICS_STACK, sequenceStack);
@@ -94,76 +93,77 @@
                 String seqName = (name == null ? SynapseConstants.ANONYMOUS_SEQUENCES : name);
                 boolean isFault = synCtx.getEnvelope().getBody().hasFault();
                 sequenceStack.put(seqName, System.currentTimeMillis(),
-                        !synCtx.isResponse(), isStatisticsEnable, isFault);
+                        !synCtx.isResponse(), statsOn, isFault);
             }
             try {
-                // The Mediator for handling error which occur during the mediation through this
-                // sequence
-                Mediator errorHandlerMediator = null;
+
                 // push the errorHandler sequence into the current message as the fault handler
                 if (errorHandler != null) {
-                    if (log.isDebugEnabled()) {
-                        log.debug("Setting the onError handler which has named as " +
-                                errorHandler + " for the sequence ");
-                    }
-                    if (shouldTrace) {
-                        trace.trace("Setting the onError handler which has named as " +
-                                errorHandler + " for the sequence ");
-                    }
                     errorHandlerMediator = synCtx.getSequence(errorHandler);
-                    synCtx.pushFaultHandler(
-                            new MediatorFaultHandler(errorHandlerMediator));
+
+                    if (errorHandlerMediator != null) {
+                        if (traceOrDebugOn) {
+                            traceOrDebug(traceOn, "Setting the onError handler : " +
+                                errorHandler + " for the sequence : " + name);
+                        }
+                        synCtx.pushFaultHandler(
+                                new MediatorFaultHandler(errorHandlerMediator));
+                    } else {
+                        auditWarn("onError handler : " + errorHandler + " for sequence : " +
+                            name + " cannot be found", synCtx);
+                    }
                 }
-                boolean result = super.mediate(synCtx);
+
+                return super.mediate(synCtx);
+
+            } finally {
+
+                // if we pushed an error handler, pop it from the fault stack before we exit
                 if (errorHandlerMediator != null) {
-                    // pop our error handler from the fault stack before we exit, if we have pushed it
                     Stack faultStack = synCtx.getFaultStack();
                     if (faultStack != null && !faultStack.isEmpty()) {
                         Object o = faultStack.peek();
+
                         if (o instanceof MediatorFaultHandler &&
-                                errorHandlerMediator.equals(
-                                        ((MediatorFaultHandler) o).getFaultMediator())) {
+                            errorHandlerMediator.equals(
+                                ((MediatorFaultHandler) o).getFaultMediator())) {
                             faultStack.pop();
                         }
                     }
                 }
-                return result;
 
-            } finally {
                 //If this sequence is finished it's task normally
-                if (isStatisticsEnable) {
+                if (statsOn) {
                     StatisticsUtils.processSequenceStatistics(synCtx);
                 }
                 //If this sequence is a IN or OUT sequence of a proxy service
                 StatisticsUtils.processProxyServiceStatistics(synCtx);
-                if (shouldTrace) {
-                    trace.trace("End : Sequence <" + (name == null ? "anonymous" : name) + ">");
+
+                if (traceOrDebugOn) {
+                    traceOrDebug(traceOn,
+                        "End : Sequence <" + (name == null ? "anonymous" : name) + ">");
                 }
             }
 
         } else {
+
             Mediator m = synCtx.getSequence(key);
             if (m == null) {
-                if (shouldTrace) {
-                    trace.trace("Sequence named " + key + " cannot be found.");
-                }
-                handleException("Sequence named " + key + " cannot be found.");
+                handleException("Sequence named " + key + " cannot be found", synCtx);
+
             } else {
-                if (shouldTrace) {
-                    trace.trace("Executing sequence named " + key);
-                }
-                if (log.isDebugEnabled()) {
-                    log.debug("Executing sequence named " + key);
+                if (traceOrDebugOn) {
+                    traceOrDebug(traceOn, "Executing sequence named " + key);
                 }
                 return m.mediate(synCtx);
             }
         }
+
         return false;
     }
 
-    private void handleException(String msg) {
-        log.error(msg);
-        throw new SynapseException(msg);
+    private boolean isStatsOn(MessageContext synCtx) {
+        return SynapseConstants.STATISTICS_ON == statisticsState;
     }
 
     /**
@@ -220,17 +220,17 @@
      *
      * @return Returns the int value that indicate statistics is enabled or not.
      */
-    public int getStatisticsEnable() {
-        return statisticsEnable;
+    public int getStatisticsState() {
+        return statisticsState;
     }
 
     /**
      * To set the statistics enable variable value
      *
-     * @param statisticsEnable  To indicate statistics collecting state
+     * @param statisticsState  To indicate statistics collecting state
      */
-    public void setStatisticsEnable(int statisticsEnable) {
-        this.statisticsEnable = statisticsEnable;
+    public void setStatisticsState(int statisticsState) {
+        this.statisticsState = statisticsState;
     }
 
     /**

Modified: webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/base/SynapseMediator.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/base/SynapseMediator.java?rev=579098&r1=579097&r2=579098&view=diff
==============================================================================
--- webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/base/SynapseMediator.java (original)
+++ webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/base/SynapseMediator.java Tue Sep 25 00:05:01 2007
@@ -39,9 +39,6 @@
  */
 public class SynapseMediator extends AbstractListMediator {
 
-    private static final Log log = LogFactory.getLog(SynapseMediator.class);
-    private static final Log trace = LogFactory.getLog(SynapseConstants.TRACE_LOGGER);
-
     /**
      * Perform the mediation specified by the rule set
      *

Modified: webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/builtin/DropMediator.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/builtin/DropMediator.java?rev=579098&r1=579097&r2=579098&view=diff
==============================================================================
--- webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/builtin/DropMediator.java (original)
+++ webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/builtin/DropMediator.java Tue Sep 25 00:05:01 2007
@@ -31,9 +31,6 @@
  */
 public class DropMediator extends AbstractMediator {
 
-    private static final Log log = LogFactory.getLog(DropMediator.class);
-    private static final Log trace = LogFactory.getLog(SynapseConstants.TRACE_LOGGER);
-
     /**
      * Halts further mediation of the current message by returning false.
      *

Modified: webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/builtin/LogMediator.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/builtin/LogMediator.java?rev=579098&r1=579097&r2=579098&view=diff
==============================================================================
--- webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/builtin/LogMediator.java (original)
+++ webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/builtin/LogMediator.java Tue Sep 25 00:05:01 2007
@@ -43,9 +43,6 @@
  */
 public class LogMediator extends AbstractMediator {
 
-    private static final Log log = LogFactory.getLog(LogMediator.class);
-    private static final Log trace = LogFactory.getLog(SynapseConstants.TRACE_LOGGER);
-
     /** Log levels ,according to the  log level ,the information going to log  will  be changed */
     public static final int CUSTOM = 0;
     public static final int SIMPLE = 1;

Modified: webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/builtin/PropertyMediator.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/builtin/PropertyMediator.java?rev=579098&r1=579097&r2=579098&view=diff
==============================================================================
--- webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/builtin/PropertyMediator.java (original)
+++ webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/builtin/PropertyMediator.java Tue Sep 25 00:05:01 2007
@@ -56,8 +56,6 @@
     public static final int ACTION_REMOVE = 1;
     /** Set the property (ACTION_SET) or remove it (ACTION_REMOVE). Defaults to ACTION_SET */
     private int action = ACTION_SET;
-    private static final Log log = LogFactory.getLog(PropertyMediator.class);
-    private static final Log trace = LogFactory.getLog(SynapseConstants.TRACE_LOGGER);
 
     /**
      * Sets a property into the current (local) Synapse Context or into the Axis Message Context

Modified: webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/builtin/RMSequenceMediator.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/builtin/RMSequenceMediator.java?rev=579098&r1=579097&r2=579098&view=diff
==============================================================================
--- webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/builtin/RMSequenceMediator.java (original)
+++ webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/builtin/RMSequenceMediator.java Tue Sep 25 00:05:01 2007
@@ -41,9 +41,6 @@
 
 public class RMSequenceMediator extends AbstractMediator {
 
-    private static Log log = LogFactory.getLog(RMSequenceMediator.class);
-    private static final Log trace = LogFactory.getLog(SynapseConstants.TRACE_LOGGER);
-
     private AXIOMXPath correlation = null;
     private AXIOMXPath lastMessage = null;
     private Boolean single = null;

Modified: webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/builtin/SendMediator.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/builtin/SendMediator.java?rev=579098&r1=579097&r2=579098&view=diff
==============================================================================
--- webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/builtin/SendMediator.java (original)
+++ webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/builtin/SendMediator.java Tue Sep 25 00:05:01 2007
@@ -39,9 +39,6 @@
  * */
 public class SendMediator extends AbstractMediator {
 
-    private static final Log log = LogFactory.getLog(SendMediator.class);
-    private static final Log trace = LogFactory.getLog(SynapseConstants.TRACE_LOGGER);
-
     private Endpoint endpoint = null;
 
     /**

Modified: webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/builtin/ValidateMediator.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/builtin/ValidateMediator.java?rev=579098&r1=579097&r2=579098&view=diff
==============================================================================
--- webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/builtin/ValidateMediator.java (original)
+++ webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/builtin/ValidateMediator.java Tue Sep 25 00:05:01 2007
@@ -61,9 +61,6 @@
  */
 public class ValidateMediator extends AbstractListMediator {
 
-    private static final Log log = LogFactory.getLog(ValidateMediator.class);
-    private static final Log trace = LogFactory.getLog(SynapseConstants.TRACE_LOGGER);
-
     /**
      * A list of property keys, referring to the schemas to be used for the validation
      */

Modified: webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/db/AbstractDBMediator.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/db/AbstractDBMediator.java?rev=579098&r1=579097&r2=579098&view=diff
==============================================================================
--- webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/db/AbstractDBMediator.java (original)
+++ webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/db/AbstractDBMediator.java Tue Sep 25 00:05:01 2007
@@ -23,6 +23,7 @@
 import org.apache.synapse.ManagedLifecycle;
 import org.apache.synapse.MessageContext;
 import org.apache.synapse.SynapseConstants;
+import org.apache.synapse.SynapseException;
 import org.apache.synapse.config.xml.AbstractDBMediatorFactory;
 import org.apache.synapse.core.SynapseEnvironment;
 import org.apache.synapse.core.axis2.Axis2MessageContext;
@@ -32,20 +33,16 @@
 
 import javax.xml.namespace.QName;
 import javax.sql.DataSource;
-import java.sql.SQLException;
-import java.sql.Connection;
-import java.sql.PreparedStatement;
-import java.sql.Types;
+import java.sql.*;
+import java.sql.Date;
 import java.util.*;
+import java.math.BigDecimal;
 
 /**
  * This abstract DB mediator will perform common DB connection pooling etc. for all DB mediators
  */
 public abstract class AbstractDBMediator extends AbstractMediator implements ManagedLifecycle {
 
-    private static final Log log = LogFactory.getLog(AbstractDBMediator.class);
-    private static final Log trace = LogFactory.getLog(SynapseConstants.TRACE_LOGGER);
-
     /** Hold JDBC properties */
     protected Map dataSourceProps = new HashMap();
     /** The DataSource to get DB connections */
@@ -53,33 +50,57 @@
     /** Statements */
     List statementList = new ArrayList();
 
-    /** For logging purposes refer to*/
-    private String url;
-
+    /**
+     * Initializes the mediator. Does nothing right now. If DataSource lookup is supported, could
+     * do the IC lookup here
+     * @param se the Synapse environment reference
+     */
     public void init(SynapseEnvironment se) {
-        url = (String) dataSourceProps.get(AbstractDBMediatorFactory.URL_Q);
+        // do nothing
     }
 
+    /**
+     * Destroys the mediator. If we are using our custom DataSource, then shut down the connections
+     */
     public void destroy() {
         try {
-            ((BasicDataSource) getDataSource()).close();
-            log.info("");
+            if (getDataSource() instanceof BasicDataSource) {
+                ((BasicDataSource) getDataSource()).close();
+            }
+            log.info("Successfully shut down DB connection pool for URL : " + getDSName());
         } catch (SQLException e) {
-            log.warn("Error shutting down DB connection pool for URL : " + url);
+            log.warn("Error shutting down DB connection pool for URL : " + getDSName());
         }
     }
 
+    /**
+     * Process each SQL statement against the current message
+     * @param synCtx the current message
+     * @return true, always
+     */
     public boolean mediate(MessageContext synCtx) {
-        boolean shouldTrace = shouldTrace(synCtx.getTracingState());
-        
         for (Iterator iter = statementList.iterator(); iter.hasNext(); ) {
             processStatement((Statement) iter.next(), synCtx);
         }
         return true;
     }
 
+    /**
+     * Subclasses must specify how each SQL statement is processed
+     * @param query the SQL statement
+     * @param msgCtx current message
+     */
     abstract protected void processStatement(Statement query, MessageContext msgCtx);
 
+    /**
+     * Return the name or (hopefully) unique connection URL specific to the DataSource being used
+     * This is used for logging purposes only
+     * @return a unique name or URL to refer to the DataSource being used
+     */
+    protected String getDSName() {
+        return (String) dataSourceProps.get(AbstractDBMediatorFactory.URL_Q);
+    }
+
     public DataSource getDataSource() {
         return dataSource;
     }
@@ -116,6 +137,14 @@
      * @throws SQLException
      */
     protected PreparedStatement getPreparedStatement(Statement stmnt, MessageContext msgCtx) throws SQLException {
+
+        boolean shouldTrace = shouldTrace(msgCtx.getTracingState());
+        Log serviceLog = msgCtx.getServiceLog();
+
+        if (shouldTrace) {
+            trace.info("Getting a connection from DataSource " + getDSName() +
+                " and preparing statement : " + stmnt.getRawStatement());
+        }
         Connection con = getDataSource().getConnection();
         PreparedStatement ps = con.prepareStatement(stmnt.getRawStatement());
 
@@ -126,25 +155,99 @@
         for (Iterator pi = params.iterator(); pi.hasNext(); ) {
 
             Statement.Parameter param = (Statement.Parameter) pi.next();
+            String value = (param.getPropertyName() != null ?
+                (String) msgCtx.getProperty(param.getPropertyName()) :
+                Axis2MessageContext.getStringValue(param.getXpath(), msgCtx));
+
+            if (shouldTrace) {
+                trace.debug("Setting as parameter : " + column + " value : " + value +
+                    " as JDBC Type : " + param.getType() + "(see java.sql.Types for valid types)");
+            }
+
             switch (param.getType()) {
-                case Types.VARCHAR: {
-                    ps.setString(column++,
-                        param.getPropertyName() != null ?
-                            (String) msgCtx.getProperty(param.getPropertyName()) :
-                            Axis2MessageContext.getStringValue(param.getXpath(), msgCtx));
+                // according to J2SE 1.5 /docs/guide/jdbc/getstart/mapping.html
+                case Types.CHAR:
+                case Types.VARCHAR:
+                case Types.LONGVARCHAR: {
+                    ps.setString(column++, value);
+                    break;
+                }
+                case Types.NUMERIC:
+                case Types.DECIMAL: {
+                    ps.setBigDecimal(column++, new BigDecimal(value));
+                    break;
+                }
+                case Types.BIT: {
+                    ps.setBoolean(column++, Boolean.parseBoolean(value));
+                    break;
+                }
+                case Types.TINYINT: {
+                    ps.setByte(column++, Byte.parseByte(value));
+                    break;
+                }
+                case Types.SMALLINT: {
+                    ps.setShort(column++, Short.parseShort(value));
                     break;
                 }
                 case Types.INTEGER: {
-                    ps.setInt(column++,
-                        Integer.parseInt(param.getPropertyName() != null ?
-                            (String) msgCtx.getProperty(param.getPropertyName()) :
-                            Axis2MessageContext.getStringValue(param.getXpath(), msgCtx)));
+                    ps.setInt(column++, Integer.parseInt(value));
+                    break;
+                }
+                case Types.BIGINT: {
+                    ps.setLong(column++, Long.parseLong(value));
+                    break;
+                }
+                case Types.REAL: {
+                    ps.setFloat(column++, Float.parseFloat(value));
+                    break;
+                }
+                case Types.FLOAT: {
+                    ps.setDouble(column++, Double.parseDouble(value));
                     break;
                 }
+                case Types.DOUBLE: {
+                    ps.setDouble(column++, Double.parseDouble(value));
+                    break;
+                }
+                // skip BINARY, VARBINARY and LONGVARBINARY
+                case Types.DATE: {
+                    ps.setDate(column++, Date.valueOf(value));
+                    break;
+                }
+                case Types.TIME: {
+                    ps.setTime(column++, Time.valueOf(value));
+                    break;
+                }
+                case Types.TIMESTAMP: {
+                    ps.setTimestamp(column++, Timestamp.valueOf(value));
+                    break;
+                }
+                // skip CLOB, BLOB, ARRAY, DISTINCT, STRUCT, REF, JAVA_OBJECT
                 default: {
-                    // todo handle this
+                    String msg = "Trying to set an un-supported JDBC Type : " + param.getType() +
+                        " against column : " + column + " and statement : " + stmnt.getRawStatement() +
+                        " used by a DB mediator against DataSource : " + getDSName() +
+                        " (see java.sql.Types for valid type values)";
+
+                    log.error(msg);
+                    if (serviceLog != null) {
+                        msgCtx.getServiceLog().error(msg);
+                    }
+                    if (shouldTrace) {
+                        trace.error(msg);
+                    }
+                    throw new SynapseException(msg);
                 }
             }
+        }
+
+        if (log.isDebugEnabled()) {
+            log.debug("Successfully prepared statement : " + stmnt.getRawStatement() +
+                "against DataSource : " + getDSName());
+        }
+        if (serviceLog != null && serviceLog.isDebugEnabled()) {
+            serviceLog.debug("Successfully prepared statement : " + stmnt.getRawStatement() +
+                "against DataSource : " + getDSName());
         }
         return ps;
     }

Modified: webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/db/DBLookupMediator.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/db/DBLookupMediator.java?rev=579098&r1=579097&r2=579098&view=diff
==============================================================================
--- webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/db/DBLookupMediator.java (original)
+++ webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/db/DBLookupMediator.java Tue Sep 25 00:05:01 2007
@@ -20,9 +20,6 @@
 package org.apache.synapse.mediators.db;
 
 import org.apache.synapse.MessageContext;
-import org.apache.synapse.core.axis2.Axis2MessageContext;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
 
 import java.sql.*;
 import java.util.*;
@@ -32,21 +29,11 @@
  */
 public class DBLookupMediator extends AbstractDBMediator {
 
-    private static final Log log = LogFactory.getLog(DBLookupMediator.class);
-
-    /** Result cache */
-    Map cacheMap = new HashMap();
-
     protected void processStatement(Statement stmnt, MessageContext msgCtx) {
 
-/*
-        // if available in cache, serve from cache and return
-        String result = (String) cacheMap.get(attName);
-        if (result != null) {
-            msgCtx.setProperty(attName, result);
-            return;
-        }
-*/
+        boolean traceOn = isTraceOn(msgCtx);
+        boolean traceOrDebugOn = isTraceOrDebugOn(traceOn);
+
         // execute the prepared statement, and extract the first result row and
         // set as message context properties, any results that have been specified
         try {
@@ -54,8 +41,14 @@
             ResultSet rs = ps.executeQuery();
 
             if (rs.next()) {
+                if (traceOrDebugOn) {
+                    traceOrDebug(traceOn,
+                        "Processing the first row returned : " + stmnt.getRawStatement());
+                }
+
                 Iterator propNameIter = stmnt.getResultsMap().keySet().iterator();
                 while (propNameIter.hasNext()) {
+
                     String propName = (String) propNameIter.next();
                     String columnStr = (String) stmnt.getResultsMap().get(propName);
 
@@ -68,18 +61,29 @@
                     }
 
                     if (obj != null) {
+                        if (traceOrDebugOn) {
+                            traceOrDebug(traceOn, "Column : " + columnStr +
+                                " returned value : " + obj +
+                                " Setting this as the message property : " + propName);
+                        }
                         msgCtx.setProperty(propName, obj.toString());
-                        cacheMap.put(propName, obj.toString());
                     } else {
-                        // todo handle this
+                        if (traceOrDebugOn) {
+                            traceOrDebugWarn(traceOn, "Column : " + columnStr +
+                                " returned null Skip setting message property : " + propName);
+                        }
                     }
                 }
             } else {
-                // todo
+                if (traceOrDebugOn) {
+                    traceOrDebug(traceOn, "Statement : "
+                        + stmnt.getRawStatement() + " returned 0 rows");
+                }
             }
+            
         } catch (SQLException e) {
-            // todo handle this
-            e.printStackTrace();
+            handleException("Error executing statement : " + stmnt.getRawStatement() +
+                " against DataSource : " + getDSName() + " :: " + e.getMessage(), e, msgCtx);
         }
     }
 

Modified: webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/db/DBReportMediator.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/db/DBReportMediator.java?rev=579098&r1=579097&r2=579098&view=diff
==============================================================================
--- webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/db/DBReportMediator.java (original)
+++ webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/db/DBReportMediator.java Tue Sep 25 00:05:01 2007
@@ -21,29 +21,37 @@
 
 import org.apache.synapse.mediators.db.Statement;
 import org.apache.synapse.MessageContext;
-import org.apache.synapse.core.axis2.Axis2MessageContext;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
 
-import java.util.*;
 import java.sql.*;
 
+/**
+ * A mediator that writes (i.e. inserts one row) to a table using message information
+ */
 public class DBReportMediator extends AbstractDBMediator {
 
-    private static final Log log = LogFactory.getLog(DBReportMediator.class);
-
     protected void processStatement(Statement stmnt, MessageContext msgCtx) {
 
+        boolean traceOn = isTraceOn(msgCtx);
+        boolean traceOrDebugOn = isTraceOrDebugOn(traceOn);
+
         try {
             PreparedStatement ps = getPreparedStatement(stmnt, msgCtx);
-            if (ps.executeUpdate() > 0) {
-                if (log.isDebugEnabled()) {
-                    log.debug("Added a row to the table");
+            int count = ps.executeUpdate();
+
+            if (count > 0) {
+                if (traceOrDebugOn) {
+                    traceOrDebug(traceOn,
+                        "Inserted " + count + " row/s using statement : " + stmnt.getRawStatement());
+                }
+            } else {
+                if (traceOrDebugOn) {
+                    traceOrDebug(traceOn,
+                        "No rows were inserted for statement : " + stmnt.getRawStatement());
                 }
             }
         } catch (SQLException e) {
-            // todo handle this
-            e.printStackTrace();
+            handleException("Error execuring insert statement : " + stmnt.getRawStatement() +
+                "against DataSource : " + getDSName() + " :: " + e.getMessage(), e, msgCtx);
         }
     }
 }

Modified: webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/eip/splitter/CloneMediator.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/eip/splitter/CloneMediator.java?rev=579098&r1=579097&r2=579098&view=diff
==============================================================================
--- webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/eip/splitter/CloneMediator.java (original)
+++ webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/eip/splitter/CloneMediator.java Tue Sep 25 00:05:01 2007
@@ -36,11 +36,6 @@
 public class CloneMediator extends AbstractMediator {
 
     /**
-     * This will hold the logger which is used for logging purposes
-     */
-    private static final Log log = LogFactory.getLog(CloneMediator.class);
-
-    /**
      * This variable specifies whether to continue the parent message
      * (i.e. message which is sbjuected to cloning) or not
      */

Modified: webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/ext/ClassMediator.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/ext/ClassMediator.java?rev=579098&r1=579097&r2=579098&view=diff
==============================================================================
--- webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/ext/ClassMediator.java (original)
+++ webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/ext/ClassMediator.java Tue Sep 25 00:05:01 2007
@@ -37,10 +37,6 @@
  */
 public class ClassMediator extends AbstractMediator implements ManagedLifecycle {
 
-	private static final Log log = LogFactory.getLog(ClassMediator.class);
-
-	private static final Log trace = LogFactory.getLog(SynapseConstants.TRACE_LOGGER);
-
 	private Mediator mediator = null;
 
     private List properties = new ArrayList();

Modified: webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/ext/POJOCommandMediator.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/ext/POJOCommandMediator.java?rev=579098&r1=579097&r2=579098&view=diff
==============================================================================
--- webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/ext/POJOCommandMediator.java (original)
+++ webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/ext/POJOCommandMediator.java Tue Sep 25 00:05:01 2007
@@ -43,16 +43,6 @@
 public class POJOCommandMediator extends AbstractMediator {
 
     /**
-     * This will hold the log variable to be used for logging
-     */
-    private static final Log log = LogFactory.getLog(POJOCommandMediator.class);
-
-    /**
-     * This will hold the trace object to be used for tracing
-     */
-    private static final Log trace = LogFactory.getLog(SynapseConstants.TRACE_LOGGER);
-
-    /**
      * This will hold the command object to be executed
      */
     private Class command = null;

Modified: webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/filters/FilterMediator.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/filters/FilterMediator.java?rev=579098&r1=579097&r2=579098&view=diff
==============================================================================
--- webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/filters/FilterMediator.java (original)
+++ webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/filters/FilterMediator.java Tue Sep 25 00:05:01 2007
@@ -37,8 +37,6 @@
  */
 public class FilterMediator extends AbstractListMediator implements org.apache.synapse.mediators.FilterMediator {
 
-    private static final Log log = LogFactory.getLog(FilterMediator.class);
-    private static final Log trace = LogFactory.getLog(SynapseConstants.TRACE_LOGGER);
     private AXIOMXPath source = null;
     private Pattern regex = null;
     private AXIOMXPath xpath = null;

Modified: webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/filters/InMediator.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/filters/InMediator.java?rev=579098&r1=579097&r2=579098&view=diff
==============================================================================
--- webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/filters/InMediator.java (original)
+++ webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/filters/InMediator.java Tue Sep 25 00:05:01 2007
@@ -33,9 +33,6 @@
  */
 public class InMediator extends AbstractListMediator implements org.apache.synapse.mediators.FilterMediator {
 
-    private static final Log log = LogFactory.getLog(InMediator.class);
-    private static final Log trace = LogFactory.getLog(SynapseConstants.TRACE_LOGGER);
-
     /**
      * Executes the list of sub/child mediators, if the filter condition is satisfied
      *

Modified: webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/filters/OutMediator.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/filters/OutMediator.java?rev=579098&r1=579097&r2=579098&view=diff
==============================================================================
--- webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/filters/OutMediator.java (original)
+++ webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/filters/OutMediator.java Tue Sep 25 00:05:01 2007
@@ -33,9 +33,6 @@
  */
 public class OutMediator extends AbstractListMediator implements org.apache.synapse.mediators.FilterMediator {
 
-    private static final Log log = LogFactory.getLog(OutMediator.class);
-    private static final Log trace = LogFactory.getLog(SynapseConstants.TRACE_LOGGER);
-
     /**
      * Executes the list of sub/child mediators, if the filter condition is satisfied
      *

Modified: webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/filters/SwitchMediator.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/filters/SwitchMediator.java?rev=579098&r1=579097&r2=579098&view=diff
==============================================================================
--- webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/filters/SwitchMediator.java (original)
+++ webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/filters/SwitchMediator.java Tue Sep 25 00:05:01 2007
@@ -20,9 +20,6 @@
 package org.apache.synapse.mediators.filters;
 
 import org.apache.axiom.om.xpath.AXIOMXPath;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.synapse.SynapseConstants;
 import org.apache.synapse.MessageContext;
 import org.apache.synapse.config.xml.SwitchCase;
 import org.apache.synapse.core.axis2.Axis2MessageContext;
@@ -40,9 +37,6 @@
  */
 public class SwitchMediator extends AbstractMediator {
 
-    private static final Log log = LogFactory.getLog(SwitchMediator.class);
-    private static final Log trace = LogFactory.getLog(SynapseConstants.TRACE_LOGGER);
-
     /** The XPath expression specifying the source element to apply the switch case expressions against   */
     private AXIOMXPath source = null;
     /** The list of switch cases    */
@@ -58,58 +52,63 @@
      */
     public boolean mediate(MessageContext synCtx) {
 
-        if (log.isDebugEnabled()) {
-            log.debug("Switch mediator :: mediate()");
-        }
-        boolean shouldTrace = shouldTrace(synCtx.getTracingState());
-        if (shouldTrace) {
-            trace.trace("Start : Switch mediator");
+        int parentsEffectiveTraceState = synCtx.getTracingState();
+        // if I have been explicitly asked to enable or disable tracing, set it to the message
+        // to pass it on; else, do nothing -> i.e. let the parents state flow
+        setEffectiveTraceState(synCtx);
+        int myEffectiveTraceState = synCtx.getTracingState();
+
+        boolean traceOn = isTraceOn(synCtx);
+        boolean traceOrDebugOn = isTraceOrDebugOn(traceOn);
+
+        if (traceOn && trace.isTraceEnabled()) {
+            trace.trace("Evaluating XPath : " + source + " against message " + synCtx);
         }
+
         String sourceText = Axis2MessageContext.getStringValue(source, synCtx);
-        if (log.isDebugEnabled()) {
-            log.debug("Applying switch case regex patterns against evaluated source value : " +
-                    sourceText);
+
+        if (traceOrDebugOn) {
+            traceOrDebug(traceOn, "XPath : " + source + " evaluates to : " + sourceText);
         }
+
         try {
-            saveAndSetTraceState(synCtx);
-            if (shouldTrace) {
-                trace.trace("Source Value : " + sourceText);
-                trace.trace("Start Case mediator list");
-            }
-            if (sourceText != null && !cases.isEmpty()) {
+            if ((sourceText == null || cases.isEmpty()) && defaultCase != null) {
+                if (traceOrDebugOn) {
+                    traceOrDebug(traceOn, "Source XPath evaluated to : null or no switch " +
+                        "cases found. Executing the default case");
+                }
+
+                return defaultCase.mediate(synCtx);
+
+            } else {
                 for (Iterator iter = cases.iterator(); iter.hasNext();) {
                     SwitchCase swCase = (SwitchCase) iter.next();
+
                     if (swCase != null) {
                         if (swCase.matches(sourceText)) {
-                            if (shouldTrace) {
-                                trace.trace("Executing case for : " + swCase.getRegex());
+                            if (traceOrDebugOn) {
+                                traceOrDebug(traceOn, "Run matching case : " + swCase.getRegex());
                             }
                             return swCase.mediate(synCtx);
                         }
                     }
                 }
-                if (shouldTrace) {
-                    trace.trace("End Case mediator list");
-                }
-            } else {
-                if (log.isDebugEnabled()) {
-                    log.debug("Source has been evaluated to Null...Default Case will be run");
-                }
-            }
-            if (defaultCase != null) {
-                if (log.isDebugEnabled()) {
-                    log.debug("Executing default case");
-                }
-                if (shouldTrace) {
-                    trace.trace("Executing default case");
+
+                if (defaultCase != null) {
+                    // if any of the switch cases did not match
+                    if (traceOrDebugOn) {
+                        traceOrDebug(traceOn, "None of the switch cases matched. Executing default");
+                    }
+                    return defaultCase.mediate(synCtx);
+                } else {
+                    if (traceOrDebugOn) {
+                        traceOrDebug(traceOn, "None of the switch cases matched. No default case");
+                    }
                 }
-                return defaultCase.mediate(synCtx);
             }
+
         } finally {
-            restoreTracingState(synCtx);
-            if (shouldTrace) {
-                trace.trace("End : Switch mediator");
-            }
+            synCtx.setTracingState(parentsEffectiveTraceState);
         }
         return true;
     }

Modified: webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/transform/FaultMediator.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/transform/FaultMediator.java?rev=579098&r1=579097&r2=579098&view=diff
==============================================================================
--- webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/transform/FaultMediator.java (original)
+++ webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/transform/FaultMediator.java Tue Sep 25 00:05:01 2007
@@ -47,8 +47,6 @@
  */
 public class FaultMediator extends AbstractMediator {
 
-    private static final Log log = LogFactory.getLog(FaultMediator.class);
-    private static final Log trace = LogFactory.getLog(SynapseConstants.TRACE_LOGGER);
     public static final String WSA_ACTION = "Action";
     /** Make a SOAP 1.1 fault */
     public static final int SOAP11 = 1;

Modified: webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/transform/HeaderMediator.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/transform/HeaderMediator.java?rev=579098&r1=579097&r2=579098&view=diff
==============================================================================
--- webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/transform/HeaderMediator.java (original)
+++ webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/transform/HeaderMediator.java Tue Sep 25 00:05:01 2007
@@ -46,8 +46,6 @@
  */
 public class HeaderMediator extends AbstractMediator {
 
-    private static final Log log = LogFactory.getLog(HeaderMediator.class);
-    private static final Log trace = LogFactory.getLog(SynapseConstants.TRACE_LOGGER);
     public static final int ACTION_SET = 0;
     public static final int ACTION_REMOVE = 1;
 

Modified: webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/transform/XSLTMediator.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/transform/XSLTMediator.java?rev=579098&r1=579097&r2=579098&view=diff
==============================================================================
--- webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/transform/XSLTMediator.java (original)
+++ webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/transform/XSLTMediator.java Tue Sep 25 00:05:01 2007
@@ -76,9 +76,6 @@
  */
 public class XSLTMediator extends AbstractMediator {
 
-    private static final Log log = LogFactory.getLog(XSLTMediator.class);
-    private static final Log trace = LogFactory.getLog(SynapseConstants.TRACE_LOGGER);
-
     /**
      * The feature for which deciding swiching between DOM and Stream during the
      * transformation process

Modified: webservices/synapse/trunk/java/modules/extensions/src/main/java/org/apache/synapse/mediators/attachment/AttachmentMediator.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/extensions/src/main/java/org/apache/synapse/mediators/attachment/AttachmentMediator.java?rev=579098&r1=579097&r2=579098&view=diff
==============================================================================
--- webservices/synapse/trunk/java/modules/extensions/src/main/java/org/apache/synapse/mediators/attachment/AttachmentMediator.java (original)
+++ webservices/synapse/trunk/java/modules/extensions/src/main/java/org/apache/synapse/mediators/attachment/AttachmentMediator.java Tue Sep 25 00:05:01 2007
@@ -28,8 +28,6 @@
 
 public class AttachmentMediator extends AbstractMediator {
 
-	private static final Log log = LogFactory.getLog(AttachmentMediator.class);
-	
 	public static final int BASE64_TO_MTOM = 0;
 	public static final int MTOM_TO_BASE64 = 1;
 	public static final int SwA_TO_BASE64 = 2;

Modified: webservices/synapse/trunk/java/modules/extensions/src/main/java/org/apache/synapse/mediators/bsf/ScriptMediator.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/extensions/src/main/java/org/apache/synapse/mediators/bsf/ScriptMediator.java?rev=579098&r1=579097&r2=579098&view=diff
==============================================================================
--- webservices/synapse/trunk/java/modules/extensions/src/main/java/org/apache/synapse/mediators/bsf/ScriptMediator.java (original)
+++ webservices/synapse/trunk/java/modules/extensions/src/main/java/org/apache/synapse/mediators/bsf/ScriptMediator.java Tue Sep 25 00:05:01 2007
@@ -53,9 +53,6 @@
  */
 public class ScriptMediator extends AbstractMediator {
 
-    private static final Log log = LogFactory.getLog(ScriptMediator.class);
-    private static final Log trace = LogFactory.getLog(SynapseConstants.TRACE_LOGGER);
-
     /**
      * The name of the variable made available to the scripting language to access the message
      */

Modified: webservices/synapse/trunk/java/modules/extensions/src/main/java/org/apache/synapse/mediators/spring/SpringMediator.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/extensions/src/main/java/org/apache/synapse/mediators/spring/SpringMediator.java?rev=579098&r1=579097&r2=579098&view=diff
==============================================================================
--- webservices/synapse/trunk/java/modules/extensions/src/main/java/org/apache/synapse/mediators/spring/SpringMediator.java (original)
+++ webservices/synapse/trunk/java/modules/extensions/src/main/java/org/apache/synapse/mediators/spring/SpringMediator.java Tue Sep 25 00:05:01 2007
@@ -43,9 +43,6 @@
  */
 public class SpringMediator extends AbstractMediator {
 
-    private static final Log log = LogFactory.getLog(SpringMediator.class);
-    private static final Log trace = LogFactory.getLog(SynapseConstants.TRACE_LOGGER);
-
     /**
      * The Spring bean ref to be used
      */

Modified: webservices/synapse/trunk/java/modules/extensions/src/main/java/org/apache/synapse/mediators/throttle/ThrottleMediator.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/extensions/src/main/java/org/apache/synapse/mediators/throttle/ThrottleMediator.java?rev=579098&r1=579097&r2=579098&view=diff
==============================================================================
--- webservices/synapse/trunk/java/modules/extensions/src/main/java/org/apache/synapse/mediators/throttle/ThrottleMediator.java (original)
+++ webservices/synapse/trunk/java/modules/extensions/src/main/java/org/apache/synapse/mediators/throttle/ThrottleMediator.java Tue Sep 25 00:05:01 2007
@@ -41,8 +41,6 @@
 
 public class ThrottleMediator extends AbstractMediator {
 
-    private static final Log log = LogFactory.getLog(ThrottleMediator.class);
-    private static final Log trace = LogFactory.getLog(SynapseConstants.TRACE_LOGGER);
     /** The key for getting policy value - key refer to registry entry  */
     private String policyKey = null;
     /** InLine policy object - XML   */

Modified: webservices/synapse/trunk/java/modules/samples/src/main/java/samples/mediators/DiscountQuoteMediator.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/samples/src/main/java/samples/mediators/DiscountQuoteMediator.java?rev=579098&r1=579097&r2=579098&view=diff
==============================================================================
--- webservices/synapse/trunk/java/modules/samples/src/main/java/samples/mediators/DiscountQuoteMediator.java (original)
+++ webservices/synapse/trunk/java/modules/samples/src/main/java/samples/mediators/DiscountQuoteMediator.java Tue Sep 25 00:05:01 2007
@@ -21,6 +21,7 @@
 
 import org.apache.synapse.MessageContext;
 import org.apache.synapse.Mediator;
+import org.apache.synapse.mediators.AbstractMediator;
 import org.apache.axiom.om.OMElement;
 import org.apache.axiom.om.OMAbstractFactory;
 import org.apache.axiom.om.OMFactory;
@@ -30,7 +31,7 @@
 
 import javax.xml.namespace.QName;
 
-public class DiscountQuoteMediator implements Mediator {
+public class DiscountQuoteMediator extends AbstractMediator {
 
     private static final Log log = LogFactory.getLog(DiscountQuoteMediator.class);
 



---------------------------------------------------------------------
To unsubscribe, e-mail: synapse-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: synapse-dev-help@ws.apache.org


Mime
View raw message