synapse-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From asan...@apache.org
Subject svn commit: r581225 - in /webservices/synapse/trunk/java/modules: core/src/main/java/org/apache/synapse/ core/src/main/java/org/apache/synapse/config/xml/endpoints/ core/src/main/java/org/apache/synapse/endpoints/ core/src/main/java/org/apache/synapse/...
Date Tue, 02 Oct 2007 13:14:49 GMT
Author: asankha
Date: Tue Oct  2 06:14:48 2007
New Revision: 581225

URL: http://svn.apache.org/viewvc?rev=581225&view=rev
Log:
review mediators in extensions and endpoints code

Modified:
    webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/SynapseConstants.java
    webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/AddressEndpointFactory.java
    webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/AddressEndpointSerializer.java
    webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/WSDLEndpointFactory.java
    webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/WSDLEndpointSerializer.java
    webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/endpoints/AddressEndpoint.java
    webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/endpoints/WSDLEndpoint.java
    webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/endpoints/utils/EndpointDefinition.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/builtin/SendMediator.java
    webservices/synapse/trunk/java/modules/core/src/test/java/org/apache/synapse/config/xml/SendMediatorSerializationTest.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

Modified: webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/SynapseConstants.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/SynapseConstants.java?rev=581225&r1=581224&r2=581225&view=diff
==============================================================================
--- webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/SynapseConstants.java
(original)
+++ webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/SynapseConstants.java
Tue Oct  2 06:14:48 2007
@@ -200,11 +200,12 @@
     //- Endpoints processing constants -
     /** Property name to store the last endpoint through which the message has flowed */
     public static final String PROCESSED_ENDPOINT = "processed_endpoint";
+    
     /** A name to use for anonymous endpoints */
-    public static final String ANONYMOUS_ENDPOINTS = "AnonymousEndpoints";
+    public static final String ANONYMOUS_ENDPOINT = "AnonymousEndpoint";
 
     /** A name to use for anonymous sequences in the sequence stack */
-    public static final String ANONYMOUS_SEQUENCES = "AnonymousSequences";
+    public static final String ANONYMOUS_SEQUENCE = "AnonymousSequence";
     
     /** Message format values in EndpointDefinition. Used by address, wsdl endpoints */
     public static final String FORMAT_POX = "pox";

Modified: webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/AddressEndpointFactory.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/AddressEndpointFactory.java?rev=581225&r1=581224&r2=581225&view=diff
==============================================================================
--- webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/AddressEndpointFactory.java
(original)
+++ webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/AddressEndpointFactory.java
Tue Oct  2 06:14:48 2007
@@ -35,7 +35,7 @@
 /**
  * Creates AddressEndpoint using a XML configuration.
  *
- * <endpoint [name="name"]>
+ * <endpoint [name="name"] [trace="enable|disable"]>
  *   <suspendDurationOnFailue>suspend-duration</suspendDurationOnFailue>
  *   <address uri="url" [format="soap|pox"] [optimize="mtom|swa"]>
  *      .. extensibility ..
@@ -56,6 +56,15 @@
 
     private static AddressEndpointFactory instance = new AddressEndpointFactory();
 
+    /**
+     * To decide to whether statistics should have collected or not
+     */
+    private int statisticsState = SynapseConstants.STATISTICS_UNSET;
+    /**
+     * The variable that indicate tracing on or off for the current mediator
+     */
+    protected int traceState = SynapseConstants.TRACING_UNSET;
+
     private AddressEndpointFactory() {}
 
     public static AddressEndpointFactory getInstance() {
@@ -141,10 +150,10 @@
             if (statisticsValue != null) {
                 if (org.apache.synapse.config.xml.XMLConfigConstants.STATISTICS_ENABLE.equals(
                         statisticsValue)) {
-                    endpoint.setStatisticsEnable(org.apache.synapse.SynapseConstants.STATISTICS_ON);
+                    endpoint.setStatisticsState(org.apache.synapse.SynapseConstants.STATISTICS_ON);
                 } else if (org.apache.synapse.config.xml.XMLConfigConstants.STATISTICS_DISABLE.equals(
                         statisticsValue)) {
-                    endpoint.setStatisticsEnable(org.apache.synapse.SynapseConstants.STATISTICS_OFF);
+                    endpoint.setStatisticsState(org.apache.synapse.SynapseConstants.STATISTICS_OFF);
                 }
             }
         }

Modified: webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/AddressEndpointSerializer.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/AddressEndpointSerializer.java?rev=581225&r1=581224&r2=581225&view=diff
==============================================================================
--- webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/AddressEndpointSerializer.java
(original)
+++ webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/AddressEndpointSerializer.java
Tue Oct  2 06:14:48 2007
@@ -135,7 +135,7 @@
 //            handleException("Invalid Endpoint. Address is required");
         }
 
-        int isEnableStatistics = endpt.getStatisticsEnable();
+        int isEnableStatistics = endpt.getStatisticsState();
         String statisticsValue = null;
         if (isEnableStatistics == org.apache.synapse.SynapseConstants.STATISTICS_ON) {
             statisticsValue = org.apache.synapse.config.xml.XMLConfigConstants.STATISTICS_ENABLE;

Modified: webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/WSDLEndpointFactory.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/WSDLEndpointFactory.java?rev=581225&r1=581224&r2=581225&view=diff
==============================================================================
--- webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/WSDLEndpointFactory.java
(original)
+++ webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/WSDLEndpointFactory.java
Tue Oct  2 06:14:48 2007
@@ -39,7 +39,7 @@
 /**
  * Creates an WSDL based endpoint from a XML configuration.
  *
- * <endpoint [name="name"]>
+ * <endpoint [name="name"] [trace="enable|disable"]>
  *    <suspendDurationOnFailue>suspend-duration</suspendDurationOnFailue>
  *    <wsdl uri="wsdl uri" service="service name" port="port name">
  *       .. extensibility ..
@@ -175,14 +175,14 @@
                     if (statisticsValue != null) {
                         if (org.apache.synapse.config.xml.XMLConfigConstants.STATISTICS_ENABLE.equals(
                                 statisticsValue)) {
-                            endpoint.setStatisticsEnable(org.apache.synapse.SynapseConstants.STATISTICS_ON);
+                            endpoint.setStatisticsState(org.apache.synapse.SynapseConstants.STATISTICS_ON);
                         } else if (org.apache.synapse.config.xml.XMLConfigConstants.STATISTICS_DISABLE.equals(
                                 statisticsValue)) {
-                            endpoint.setStatisticsEnable(org.apache.synapse.SynapseConstants.STATISTICS_OFF);
+                            endpoint.setStatisticsState(org.apache.synapse.SynapseConstants.STATISTICS_OFF);
                         }
                     }
                 }
-                wsdlEndpoint.setEndpointDefinition(endpoint);
+                wsdlEndpoint.setEndpoint(endpoint);
             } else {
                 handleException("WSDL is not specified for WSDL endpoint.");
             }

Modified: webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/WSDLEndpointSerializer.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/WSDLEndpointSerializer.java?rev=581225&r1=581224&r2=581225&view=diff
==============================================================================
--- webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/WSDLEndpointSerializer.java
(original)
+++ webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/WSDLEndpointSerializer.java
Tue Oct  2 06:14:48 2007
@@ -97,7 +97,7 @@
         // currently, we have to get QOS information from the endpoint definition and set
them as
         // special elements under the wsdl element. in future, these information should be
         // extracted from the wsdl.
-        EndpointDefinition epAddress = wsdlEndpoint.getEndpointDefinition();
+        EndpointDefinition epAddress = wsdlEndpoint.getEndpoint();
         serializeQOSInformation(epAddress, wsdlElement);
 
         endpointElement.addChild(wsdlElement);
@@ -125,7 +125,7 @@
             wsdlElement.addAttribute(fac.createOMAttribute("format", null, "soap11"));
         }        
         
-        int isEnableStatistics = endpointDefinition.getStatisticsEnable();
+        int isEnableStatistics = endpointDefinition.getStatisticsState();
         String statisticsValue = null;
         if (isEnableStatistics == org.apache.synapse.SynapseConstants.STATISTICS_ON) {
             statisticsValue = org.apache.synapse.config.xml.XMLConfigConstants.STATISTICS_ENABLE;

Modified: webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/endpoints/AddressEndpoint.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/endpoints/AddressEndpoint.java?rev=581225&r1=581224&r2=581225&view=diff
==============================================================================
--- webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/endpoints/AddressEndpoint.java
(original)
+++ webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/endpoints/AddressEndpoint.java
Tue Oct  2 06:14:48 2007
@@ -37,6 +37,7 @@
 public class AddressEndpoint extends FaultHandler implements Endpoint {
 
     private static final Log log = LogFactory.getLog(AddressEndpoint.class);
+    private static final Log trace = LogFactory.getLog(SynapseConstants.TRACE_LOGGER);
 
     /**
      * Name of the endpoint. Used for named endpoints which can be referred using the key
attribute
@@ -95,7 +96,6 @@
      * suspendOnFailDuration has elapsed, it will be set to active.
      *
      * @param synMessageContext MessageContext of the current message. This is not used here.
-     *
      * @return true if endpoint is active. false otherwise.
      */
     public boolean isActive(MessageContext synMessageContext) {
@@ -114,8 +114,7 @@
      * Sets if endpoint active or not. if endpoint is set as failed (active = false), the
recover on
      * time is calculated so that it will be activated after the recover on time.
      *
-     * @param active true if active. false otherwise.
-     *
+     * @param active            true if active. false otherwise.
      * @param synMessageContext MessageContext of the current message. This is not used here.
      */
     public synchronized void setActive(boolean active, MessageContext synMessageContext)
{
@@ -145,40 +144,54 @@
      */
     public void send(MessageContext synCtx) {
 
+        boolean traceOn = isTraceOn(synCtx);
+        boolean traceOrDebugOn = isTraceOrDebugOn(traceOn);
+
+        if (traceOrDebugOn) {
+            traceOrDebug(traceOn, "Start : Address Endpoint");
+
+            if (traceOn && trace.isTraceEnabled()) {
+                trace.trace("Message : " + synCtx);
+            }
+        }
+
         String endPointName = this.getName();
-        if(endPointName == null) {
-            endPointName = SynapseConstants.ANONYMOUS_ENDPOINTS;
+        if (endPointName == null) {
+            endPointName = SynapseConstants.ANONYMOUS_ENDPOINT;
         }
+
         // Setting Required property to collect the End Point statistics
-        boolean statisticsEnable =
-                (org.apache.synapse.SynapseConstants.STATISTICS_ON == endpoint.getStatisticsEnable());
+        boolean statisticsEnable = (SynapseConstants.STATISTICS_ON == endpoint.getStatisticsState());
         if (statisticsEnable) {
             EndPointStatisticsStack endPointStatisticsStack = null;
             Object statisticsStackObj =
-                    synCtx.getProperty(org.apache.synapse.SynapseConstants.ENDPOINT_STATS);
+                synCtx.getProperty(org.apache.synapse.SynapseConstants.ENDPOINT_STATS);
             if (statisticsStackObj == null) {
                 endPointStatisticsStack = new EndPointStatisticsStack();
                 synCtx.setProperty(org.apache.synapse.SynapseConstants.ENDPOINT_STATS,
-                        endPointStatisticsStack);
+                    endPointStatisticsStack);
             } else if (statisticsStackObj instanceof EndPointStatisticsStack) {
                 endPointStatisticsStack = (EndPointStatisticsStack) statisticsStackObj;
             }
             if (endPointStatisticsStack != null) {
                 boolean isFault = synCtx.getEnvelope().getBody().hasFault();
                 endPointStatisticsStack.put(endPointName, System.currentTimeMillis(),
-                        !synCtx.isResponse(), statisticsEnable, isFault);
+                    !synCtx.isResponse(), statisticsEnable, isFault);
             }
         }
 
         if (endpoint.getAddress() != null) {
-            if (log.isDebugEnabled()) {
-                log.debug("Sending message to endpoint :: name = " +
-                        endPointName + " resolved address = " + endpoint.getAddress());
-                log.debug("SOAPAction: " + (synCtx.getSoapAction() != null ?
-                        synCtx.getSoapAction() : "null"));
-                log.debug("WSA-Action: " + (synCtx.getWSAAction() != null ?
-                        synCtx.getWSAAction() : "null"));
-                log.debug("Body : \n" + synCtx.getEnvelope());
+            if (traceOrDebugOn) {
+                traceOrDebug(traceOn, "Sending message to endpoint : " +
+                    endPointName + " resolves to address = " + endpoint.getAddress());
+                traceOrDebug(traceOn, "SOAPAction: " + (synCtx.getSoapAction() != null ?
+                    synCtx.getSoapAction() : "null"));
+                traceOrDebug(traceOn, "WSA-Action: " + (synCtx.getWSAAction() != null ?
+                    synCtx.getWSAAction() : "null"));
+
+                if (traceOn && trace.isTraceEnabled()) {
+                    trace.trace("Envelope : \n" + synCtx.getEnvelope());
+                }
             }
         }
 
@@ -220,6 +233,42 @@
             if (!faultStack.isEmpty()) {
                 ((FaultHandler) faultStack.pop()).handleFault(synCtx);
             }
+        }
+    }
+
+    /**
+     * 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 msgCtx the current message
+     * @return true if tracing should be performed
+     */
+    protected boolean isTraceOn(MessageContext msgCtx) {
+        return
+            (endpoint.getTraceState() == SynapseConstants.TRACING_ON) ||
+            (endpoint.getTraceState() == 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);
         }
     }
 }

Modified: webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/endpoints/WSDLEndpoint.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/endpoints/WSDLEndpoint.java?rev=581225&r1=581224&r2=581225&view=diff
==============================================================================
--- webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/endpoints/WSDLEndpoint.java
(original)
+++ webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/endpoints/WSDLEndpoint.java
Tue Oct  2 06:14:48 2007
@@ -36,12 +36,13 @@
  * not access the wsdl document at runtime to obtain endpoint information. If it is neccessary
to
  * create an endpoint using a dynamic wsdl, store the endpoint configuration in the registry
and
  * create a dynamic wsdl endpoint using that registry key.
- *
+ * <p/>
  * TODO: This should allow variuos policies to be applied on fine grained level (e.g. operations).
  */
 public class WSDLEndpoint extends FaultHandler implements Endpoint {
 
     private static final Log log = LogFactory.getLog(AddressEndpoint.class);
+    private static final Log trace = LogFactory.getLog(SynapseConstants.TRACE_LOGGER);
 
     private String name = null;
     private String wsdlURI;
@@ -63,7 +64,7 @@
 
     private boolean active = true;
     private Endpoint parentEndpoint = null;
-    private EndpointDefinition endpointDefinition = null;
+    private EndpointDefinition endpoint = null;
 
     /**
      * Sends the message through this endpoint. This method just handles statistics related
functions
@@ -76,44 +77,58 @@
      */
     public void send(MessageContext synCtx) {
 
+        boolean traceOn = isTraceOn(synCtx);
+        boolean traceOrDebugOn = isTraceOrDebugOn(traceOn);
+
+        if (traceOrDebugOn) {
+            traceOrDebug(traceOn, "Start : Address Endpoint");
+
+            if (traceOn && trace.isTraceEnabled()) {
+                trace.trace("Message : " + synCtx);
+            }
+        }
+
         String eprAddress = null;
-        if (endpointDefinition.getAddress() != null) {
-            eprAddress = endpointDefinition.getAddress().toString();
+        if (endpoint.getAddress() != null) {
+
+            eprAddress = endpoint.getAddress();
             String endPointName = this.getName();
             if (endPointName == null) {
-                endPointName = SynapseConstants.ANONYMOUS_ENDPOINTS;
+                endPointName = SynapseConstants.ANONYMOUS_ENDPOINT;
             }
+
             // Setting Required property to collect the End Point statistics
             boolean statisticsEnable =
-                    (org.apache.synapse.SynapseConstants.STATISTICS_ON
-                            == endpointDefinition.getStatisticsEnable());
+                (SynapseConstants.STATISTICS_ON == endpoint.getStatisticsState());
+            
             if (statisticsEnable) {
                 EndPointStatisticsStack endPointStatisticsStack = null;
                 Object statisticsStackObj =
-                        synCtx.getProperty(org.apache.synapse.SynapseConstants.ENDPOINT_STATS);
+                    synCtx.getProperty(org.apache.synapse.SynapseConstants.ENDPOINT_STATS);
                 if (statisticsStackObj == null) {
                     endPointStatisticsStack = new EndPointStatisticsStack();
                     synCtx.setProperty(org.apache.synapse.SynapseConstants.ENDPOINT_STATS,
-                            endPointStatisticsStack);
+                        endPointStatisticsStack);
                 } else if (statisticsStackObj instanceof EndPointStatisticsStack) {
                     endPointStatisticsStack = (EndPointStatisticsStack) statisticsStackObj;
                 }
                 if (endPointStatisticsStack != null) {
                     boolean isFault = synCtx.getEnvelope().getBody().hasFault();
                     endPointStatisticsStack.put(endPointName, System.currentTimeMillis(),
-                            !synCtx.isResponse(), statisticsEnable, isFault);
+                        !synCtx.isResponse(), statisticsEnable, isFault);
                 }
             }
-            if (log.isDebugEnabled()) {
-                log.debug("Sending message to endpoint :: name = " +
-                        endPointName + " resolved address = " + eprAddress);
-                log.debug("Sending To: " + (synCtx.getTo() != null ?
-                        synCtx.getTo().getAddress() : "null"));
-                log.debug("SOAPAction: " + (synCtx.getSoapAction() != null ?
-                        synCtx.getSoapAction() : "null"));
-                log.debug("WSA-Action: " + (synCtx.getWSAAction() != null ?
-                        synCtx.getWSAAction() : "null"));
-                log.debug("Body : \n" + synCtx.getEnvelope());
+            if (traceOrDebugOn) {
+                traceOrDebug(traceOn, "Sending message to WSDL endpoint : " +
+                    endPointName + " resolves to address = " + eprAddress);
+                traceOrDebug(traceOn, "SOAPAction: " + (synCtx.getSoapAction() != null ?
+                    synCtx.getSoapAction() : "null"));
+                traceOrDebug(traceOn, "WSA-Action: " + (synCtx.getWSAAction() != null ?
+                    synCtx.getWSAAction() : "null"));
+
+                if (traceOn && trace.isTraceEnabled()) {
+                    trace.trace("Envelope : \n" + synCtx.getEnvelope());
+                }
             }
 
             // register this as the immediate fault handler for this message.
@@ -122,7 +137,7 @@
             // add this as the last endpoint to process this message. it is used by statistics
code.
             synCtx.setProperty(SynapseConstants.PROCESSED_ENDPOINT, this);
 
-            synCtx.getEnvironment().send(endpointDefinition, synCtx);
+            synCtx.getEnvironment().send(endpoint, synCtx);
         }
     }
 
@@ -197,7 +212,6 @@
      * suspendOnFailDuration has elapsed, it will be set to active.
      *
      * @param synMessageContext MessageContext of the current message. This is not used here.
-     *
      * @return true if endpoint is active. false otherwise.
      */
     public boolean isActive(MessageContext synMessageContext) {
@@ -215,8 +229,7 @@
      * Sets if endpoint active or not. if endpoint is set as failed (active = false), the
recover on
      * time is calculated so that it will be activated after the recover on time.
      *
-     * @param active true if active. false otherwise.
-     *
+     * @param active            true if active. false otherwise.
      * @param synMessageContext MessageContext of the current message. This is not used here.
      */
     public void setActive(boolean active, MessageContext synMessageContext) {
@@ -236,11 +249,47 @@
         this.parentEndpoint = parentEndpoint;
     }
 
-    public EndpointDefinition getEndpointDefinition() {
-        return endpointDefinition;
+    public EndpointDefinition getEndpoint() {
+        return endpoint;
+    }
+
+    public void setEndpoint(EndpointDefinition endpoint) {
+        this.endpoint = endpoint;
     }
 
-    public void setEndpointDefinition(EndpointDefinition endpointDefinition) {
-        this.endpointDefinition = endpointDefinition;
+    /**
+     * 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 msgCtx the current message
+     * @return true if tracing should be performed
+     */
+    protected boolean isTraceOn(MessageContext msgCtx) {
+        return
+            (endpoint.getTraceState() == SynapseConstants.TRACING_ON) ||
+            (endpoint.getTraceState() == 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);
+        }
     }
 }

Modified: webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/endpoints/utils/EndpointDefinition.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/endpoints/utils/EndpointDefinition.java?rev=581225&r1=581224&r2=581225&view=diff
==============================================================================
--- webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/endpoints/utils/EndpointDefinition.java
(original)
+++ webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/endpoints/utils/EndpointDefinition.java
Tue Oct  2 06:14:48 2007
@@ -66,7 +66,10 @@
     private int timeoutAction = SynapseConstants.NONE;
 
     /** To decide to whether statistics should have collected or not */
-    private int statisticsEnable = SynapseConstants.STATISTICS_UNSET;
+    private int statisticsState = SynapseConstants.STATISTICS_UNSET;
+
+    /** The variable that indicate tracing on or off for the current mediator */
+    private int traceState = SynapseConstants.TRACING_UNSET;
 
     /**
      * This should return the absolute EPR address referenced by the named endpoint. This
may be possibly computed.
@@ -232,16 +235,24 @@
      *
      * @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
+     * @param statisticsState
      */
-    public void setStatisticsEnable(int statisticsEnable) {
-        this.statisticsEnable = statisticsEnable;
+    public void setStatisticsState(int statisticsState) {
+        this.statisticsState = statisticsState;
+    }
+
+    public int getTraceState() {
+        return traceState;
+    }
+
+    public void setTraceState(int traceState) {
+        this.traceState = traceState;
     }
 }

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=581225&r1=581224&r2=581225&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 Oct  2 06:14:48 2007
@@ -94,7 +94,7 @@
                     sequenceStack = new SequenceStatisticsStack();
                     synCtx.setProperty(SynapseConstants.SEQUENCE_STATS, sequenceStack);
                 }
-                String seqName = (name == null ? SynapseConstants.ANONYMOUS_SEQUENCES : name);
+                String seqName = (name == null ? SynapseConstants.ANONYMOUS_SEQUENCE : name);
                 boolean isFault = synCtx.getEnvelope().getBody().hasFault();
                 sequenceStack.put(seqName, System.currentTimeMillis(),
                         !synCtx.isResponse(), statsOn, isFault);

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=581225&r1=581224&r2=581225&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 Oct  2 06:14:48 2007
@@ -68,12 +68,15 @@
                 StringBuffer sb = new StringBuffer();
                 sb.append("Sending " + (synCtx.isResponse() ? "response" : "request")
                     + " message using implicit message properties..");
-                sb.append("Sending To: " + (synCtx.getTo() != null ?
+                sb.append("\nSending To: " + (synCtx.getTo() != null ?
                         synCtx.getTo().getAddress() : "null"));
-                sb.append("SOAPAction: " + (synCtx.getWSAAction() != null ?
+                sb.append("\nSOAPAction: " + (synCtx.getWSAAction() != null ?
                         synCtx.getWSAAction() : "null"));
-                sb.append("Body : \n" + synCtx.getEnvelope());
                 traceOrDebug(traceOn, sb.toString());
+            }
+
+            if (traceOn && trace.isTraceEnabled()) {
+                trace.trace("Envelope : " + synCtx.getEnvelope());
             }
 
             if (synCtx.isResponse()) {

Modified: webservices/synapse/trunk/java/modules/core/src/test/java/org/apache/synapse/config/xml/SendMediatorSerializationTest.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/core/src/test/java/org/apache/synapse/config/xml/SendMediatorSerializationTest.java?rev=581225&r1=581224&r2=581225&view=diff
==============================================================================
--- webservices/synapse/trunk/java/modules/core/src/test/java/org/apache/synapse/config/xml/SendMediatorSerializationTest.java
(original)
+++ webservices/synapse/trunk/java/modules/core/src/test/java/org/apache/synapse/config/xml/SendMediatorSerializationTest.java
Tue Oct  2 06:14:48 2007
@@ -30,7 +30,6 @@
 import javax.xml.stream.XMLStreamReader;
 import javax.xml.stream.XMLInputFactory;
 import javax.xml.stream.XMLStreamException;
-import java.util.ArrayList;
 import java.util.List;
 import java.io.StringReader;
 
@@ -114,8 +113,8 @@
 
         assertEquals(
                 "Addressing information is not serialized properly",
-                ep1.getEndpointDefinition().isAddressingOn(),
-                ep2.getEndpointDefinition().isAddressingOn());
+                ep1.getEndpoint().isAddressingOn(),
+                ep2.getEndpoint().isAddressingOn());
     }
 
     public void testSimpleLoadbalanceSendSerialization() {

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=581225&r1=581224&r2=581225&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 Oct  2 06:14:48 2007
@@ -143,19 +143,22 @@
      * @return the boolean result from the script invocation
      */
     public boolean mediate(MessageContext synCtx) {
-        if (log.isDebugEnabled()) {
-            log.debug("Script Mediator - mediate() # Language : " + language +
-                    (key == null ? " inline script" : " script with key : " + key) +
-                    " function : " + function);
+
+        boolean traceOn = isTraceOn(synCtx);
+        boolean traceOrDebugOn = isTraceOrDebugOn(traceOn);
+
+        if (traceOrDebugOn) {
+            traceOrDebug(traceOn, "Start : Script mediator");
+
+            if (traceOn && trace.isTraceEnabled()) {
+                trace.trace("Message : " + synCtx);
+            }
         }
 
-        boolean shouldTrace = shouldTrace(synCtx.getTracingState());
-
-        if (shouldTrace) {
-            trace.trace("Start : Script mediator # Language : " + language +
-                    (key == null ? " inline script" : " script with key : " + key) +
-                    " function : " + function);
-            trace.trace("Invoking inline script for current message : " + synCtx.getEnvelope());
+        if (traceOrDebugOn) {
+            traceOrDebug(traceOn, "Scripting language : " + language + " source " +
+                (key == null ? ": specified inline " : " loaded with key : " + key) +
+                (function != null ? " function : " + function : ""));
         }
 
         boolean returnValue;
@@ -168,9 +171,12 @@
             }
         }
 
-        if (shouldTrace) {
+        if (traceOn && trace.isTraceEnabled()) {
             trace.trace("Result message after execution of script : " + synCtx.getEnvelope());
-            trace.trace("End : Script mediator " + returnValue);
+        }
+
+        if (traceOrDebugOn) {
+            traceOrDebug(traceOn, "End : Script mediator " + returnValue);
         }
 
         return returnValue;
@@ -193,9 +199,10 @@
             }
 
         } catch (ScriptException e) {
-            handleException("The Script engine returned an error executing the " +
-                (key == null ? "inline " : "external ") + language + " script" +
-                (key != null? " : " + key : ""), e);
+            handleException("The script engine returned an error executing the " +
+                (key == null ? "inlined " : "external ") + language + " script" +
+                (key != null? " : " + key : "") +
+                (function != null ? " function " + function : ""), e, synCtx);
             returnValue = false;
         }
         return returnValue;
@@ -244,14 +251,20 @@
      */
     protected void initInlineScript() {
         try {
-
             initScriptEngine();
 
             if (scriptEngine instanceof Compilable) {
+                if (log.isDebugEnabled()) {
+                    log.debug("Script engine supports Compilable interface, compiling script
code..");
+                }
                 compiledScript = ((Compilable)scriptEngine).compile(scriptSourceCode);
             } else {
                 // do nothing. If the script enging doesn't support Compilable then
                 // the inline script will be evaluated on each invocation
+                if (log.isDebugEnabled()) {
+                    log.debug("Script engine does not support the Compilable interface, "
+
+                        "inlined script would be evaluated on each invocation..");
+                }
             }
 
         } catch (ScriptException e) {
@@ -307,14 +320,20 @@
     }
 
     protected void initScriptEngine() {
+        if (log.isDebugEnabled()) {
+            log.debug("Initializing script mediator for language : " + language);
+        }
+
         ScriptEngineManager manager = new ScriptEngineManager();
         this.scriptEngine = manager.getEngineByExtension(language);
         if (scriptEngine == null) {
-            throw new SynapseException("No script engine found for language: " + language);
+            handleException("No script engine found for language: " + language);
         }
         xmlHelper = XMLHelper.getArgHelper(scriptEngine);
 
         this.multiThreadedEngine = scriptEngine.getFactory().getParameter("THREADING") !=
null;
+        log.debug("Script mediator for language : " + language +
+            " supports multithreading? : " + multiThreadedEngine);
     }
 
     public String getLanguage() {
@@ -333,9 +352,8 @@
         return scriptSourceCode;
     }
 
-    private void handleException(String msg, Exception e) {
-        log.error(msg, e);
-        throw new SynapseException(msg, e);
+    private void handleException(String msg) {
+        log.error(msg);
+        throw new SynapseException(msg);
     }
-
 }

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=581225&r1=581224&r2=581225&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 Oct  2 06:14:48 2007
@@ -58,21 +58,28 @@
 
     public boolean mediate(MessageContext synCtx) {
 
-        boolean shouldTrace = shouldTrace(synCtx.getTracingState());
-        if (shouldTrace) {
-            trace.trace("Start : Spring mediator");
+        boolean traceOn = isTraceOn(synCtx);
+        boolean traceOrDebugOn = isTraceOrDebugOn(traceOn);
+
+        if (traceOrDebugOn) {
+            traceOrDebug(traceOn, "Start : Spring mediator");
+
+            if (traceOn && trace.isTraceEnabled()) {
+                trace.trace("Message : " + synCtx);
+            }
         }
+
         Entry entry = synCtx.getConfiguration().getEntryDefinition(configKey);
 
         // if the configKey refers to a dynamic property
         if (entry != null && entry.isDynamic()) {
             if (!entry.isCached() || entry.isExpired()) {
-                buildAppContext(synCtx);
+                buildAppContext(synCtx, traceOrDebugOn, traceOn);
             }
         // if the property is not a DynamicProperty, we will create an ApplicationContext
only once
         } else {
             if (appContext == null) {
-                buildAppContext(synCtx);
+                buildAppContext(synCtx, traceOrDebugOn, traceOn);
             }
         }
 
@@ -81,44 +88,45 @@
             Object o = appContext.getBean(beanName);    
             if (o != null && Mediator.class.isAssignableFrom(o.getClass())) {
                 Mediator m = (Mediator) o;
-                if (shouldTrace) {
-                    trace.trace("Loaded mediator from bean : " + beanName + " executing...");
+                if (traceOrDebugOn) {
+                    traceOrDebug(traceOn, "Loaded mediator from bean : " + beanName + " executing...");
                 }
                 return m.mediate(synCtx);
 
             } else {
-                if (shouldTrace) {
-                    trace.trace("Unable to load mediator from bean : " + beanName);
+                if (traceOrDebugOn) {
+                    traceOrDebug(traceOn, "Unable to load mediator from bean : " + beanName);
                 }
                 handleException("Could not load bean named : " + beanName +
-                    " from the Spring configuration with key : " + configKey);
+                    " from the Spring configuration with key : " + configKey, synCtx);
             }
         } else {
-            handleException("Cannot reference Spring application context with key : " + configKey);
+            handleException("Cannot reference application context with key : " + configKey,
synCtx);
         }
-        if (shouldTrace) {
-            trace.trace("End : Spring mediator");
+
+        if (traceOrDebugOn) {
+            traceOrDebug(traceOn, "End : Spring mediator");
         }
         return true;
     }
 
-    private synchronized void buildAppContext(MessageContext synCtx) {
-        if (log.isDebugEnabled()) {
-            log.debug("Creating Spring ApplicationContext from property key : " + configKey);
+    private synchronized void buildAppContext(MessageContext synCtx,
+        boolean traceOrDebugOn, boolean traceOn) {
+
+        if (traceOrDebugOn) {
+            traceOrDebug(traceOn, "Creating Spring ApplicationContext from key : " + configKey);
         }
         GenericApplicationContext appContext = new GenericApplicationContext();
         XmlBeanDefinitionReader xbdr = new XmlBeanDefinitionReader(appContext);
         xbdr.setValidating(false);
-        xbdr.loadBeanDefinitions(new InputStreamResource(
-            Util.getStreamSource(
-                    synCtx.getEntry(configKey)).getInputStream()));
+        xbdr.loadBeanDefinitions(
+            new InputStreamResource(
+                Util.getStreamSource(synCtx.getEntry(configKey)).getInputStream()));
         appContext.refresh();
+        if (traceOrDebugOn) {
+            traceOrDebug(traceOn, "Spring ApplicationContext from key : " + configKey + "
created");
+        }
         this.appContext = appContext;
-    }
-
-    private void handleException(String msg) {
-        log.error(msg);
-        throw new SynapseException(msg);
     }
 
     public void setBeanName(String beanName) {



---------------------------------------------------------------------
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