synapse-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sami...@apache.org
Subject svn commit: r399670 - in /incubator/synapse/trunk/scratch/synapse2/modules/core/src/org/apache/synapse: ./ api/ config/ mediators/ mediators/base/ mediators/builtin/ mediators/ext/ mediators/filters/ mediators/transform/
Date Thu, 04 May 2006 11:32:52 GMT
Author: saminda
Date: Thu May  4 04:32:21 2006
New Revision: 399670

URL: http://svn.apache.org/viewcvs?rev=399670&view=rev
Log:
Mainly fixes Javadocs and adds some more features...

Added:
    incubator/synapse/trunk/scratch/synapse2/modules/core/src/org/apache/synapse/Util.java
    incubator/synapse/trunk/scratch/synapse2/modules/core/src/org/apache/synapse/mediators/transform/TransformMediator.java
      - copied, changed from r399252, incubator/synapse/trunk/scratch/synapse2/modules/core/src/org/apache/synapse/mediators/transform/XSLTMediator.java
Removed:
    incubator/synapse/trunk/scratch/synapse2/modules/core/src/org/apache/synapse/config/ServiceMediatorFactory.java
    incubator/synapse/trunk/scratch/synapse2/modules/core/src/org/apache/synapse/mediators/ext/ServiceMediator.java
    incubator/synapse/trunk/scratch/synapse2/modules/core/src/org/apache/synapse/mediators/transform/XSLTMediator.java
Modified:
    incubator/synapse/trunk/scratch/synapse2/modules/core/src/org/apache/synapse/Constants.java
    incubator/synapse/trunk/scratch/synapse2/modules/core/src/org/apache/synapse/HeaderType.java
    incubator/synapse/trunk/scratch/synapse2/modules/core/src/org/apache/synapse/SynapseContext.java
    incubator/synapse/trunk/scratch/synapse2/modules/core/src/org/apache/synapse/SynapseException.java
    incubator/synapse/trunk/scratch/synapse2/modules/core/src/org/apache/synapse/SynapseMessage.java
    incubator/synapse/trunk/scratch/synapse2/modules/core/src/org/apache/synapse/api/FilterMediator.java
    incubator/synapse/trunk/scratch/synapse2/modules/core/src/org/apache/synapse/api/ListMediator.java
    incubator/synapse/trunk/scratch/synapse2/modules/core/src/org/apache/synapse/api/Mediator.java
    incubator/synapse/trunk/scratch/synapse2/modules/core/src/org/apache/synapse/config/HeaderMediatorFactory.java
    incubator/synapse/trunk/scratch/synapse2/modules/core/src/org/apache/synapse/config/LogMediatorFactory.java
    incubator/synapse/trunk/scratch/synapse2/modules/core/src/org/apache/synapse/mediators/AbstractListMediator.java
    incubator/synapse/trunk/scratch/synapse2/modules/core/src/org/apache/synapse/mediators/AbstractMediator.java
    incubator/synapse/trunk/scratch/synapse2/modules/core/src/org/apache/synapse/mediators/MediatorProperty.java
    incubator/synapse/trunk/scratch/synapse2/modules/core/src/org/apache/synapse/mediators/base/SequenceMediator.java
    incubator/synapse/trunk/scratch/synapse2/modules/core/src/org/apache/synapse/mediators/base/SynapseMediator.java
    incubator/synapse/trunk/scratch/synapse2/modules/core/src/org/apache/synapse/mediators/builtin/DropMediator.java
    incubator/synapse/trunk/scratch/synapse2/modules/core/src/org/apache/synapse/mediators/builtin/LogMediator.java
    incubator/synapse/trunk/scratch/synapse2/modules/core/src/org/apache/synapse/mediators/builtin/SendMediator.java
    incubator/synapse/trunk/scratch/synapse2/modules/core/src/org/apache/synapse/mediators/ext/ClassMediator.java
    incubator/synapse/trunk/scratch/synapse2/modules/core/src/org/apache/synapse/mediators/filters/FilterMediator.java
    incubator/synapse/trunk/scratch/synapse2/modules/core/src/org/apache/synapse/mediators/transform/FaultMediator.java
    incubator/synapse/trunk/scratch/synapse2/modules/core/src/org/apache/synapse/mediators/transform/HeaderMediator.java

Modified: incubator/synapse/trunk/scratch/synapse2/modules/core/src/org/apache/synapse/Constants.java
URL: http://svn.apache.org/viewcvs/incubator/synapse/trunk/scratch/synapse2/modules/core/src/org/apache/synapse/Constants.java?rev=399670&r1=399669&r2=399670&view=diff
==============================================================================
--- incubator/synapse/trunk/scratch/synapse2/modules/core/src/org/apache/synapse/Constants.java (original)
+++ incubator/synapse/trunk/scratch/synapse2/modules/core/src/org/apache/synapse/Constants.java Thu May  4 04:32:21 2006
@@ -17,18 +17,17 @@
 
 import javax.xml.namespace.QName;
 
-
 /**
  * <p> Global constants for the Synapse project
  */
 public interface Constants {
 
-
     String CLASSMEDIATOR = "classmediator";
 
     QName MEDIATE_OPERATION_NAME = new QName("mediate");
 
     String MEDIATOR_RESPONSE_PROPERTY = "synapse.mediator.response";
+
     String MEDIATOR_SYNAPSE_CTX_PROPERTY = "synapse.mediator.environment";
 
     String ISRESPONSE_PROPERTY = "synapse.isresponse";
@@ -43,15 +42,12 @@
     String ADD_ADDRESSING = "synapse.send.useaddressing";
 
     // for security supporting
-
     String SECURITY_QOS = "synapse_security";
+
     String ADDRESSING_PROCESSED_CONFIGURATION_CONTEXT = "addressing_processed_configurationContext";
 
     // addressing properites handling
-
     String ENGAGE_ADDRESSING_IN_MESSAGE = "__ENGAGE_ADDRESSING_IN_MESSAGE__";
 
     String ENGAGE_ADDRESSING_OUT_BOUND_MESSAGE = "__ENGAGE_ADDRESSING_OUT_BOUND_MESSAGE__";
-
-
 }

Modified: incubator/synapse/trunk/scratch/synapse2/modules/core/src/org/apache/synapse/HeaderType.java
URL: http://svn.apache.org/viewcvs/incubator/synapse/trunk/scratch/synapse2/modules/core/src/org/apache/synapse/HeaderType.java?rev=399670&r1=399669&r2=399670&view=diff
==============================================================================
--- incubator/synapse/trunk/scratch/synapse2/modules/core/src/org/apache/synapse/HeaderType.java (original)
+++ incubator/synapse/trunk/scratch/synapse2/modules/core/src/org/apache/synapse/HeaderType.java Thu May  4 04:32:21 2006
@@ -17,19 +17,29 @@
 package org.apache.synapse;
 
 import org.apache.axis2.addressing.EndpointReference;
+import org.apache.axiom.soap.SOAPHeaderBlock;
 
 /**
- * <p> This class encapsulates access to headers. It has a set of "logical names" (e.g. strings)
- * Once you have set the logical name you can read and write that header on a SynapseMessage
- * It is used by the RegexProcessor and the HeaderProcessor classes.
+ * This is a convenience class used to manipulate common headers. The convenience string names this defines could be
+ * used to configure the header mediator. Once an instance of this class exists, it could be given a value and
+ * a synapse message instance, and asked to set given value as the header value to the given message. i.e. setHeader()
+ *
+ * Support for additional headers may be added later
  */
 public class HeaderType {
 
-    private final static int TO = 1, FROM = 2, FAULT = 3, ACTION = 4,
-        REPLYTO = 5;
+    private final static int TO = 1, FROM = 2, FAULT = 3, ACTION = 4, REPLYTO = 5;
 
-    public final static String STRTO = "to", STRFROM = "from",
-        STRFAULT = "faultto", STRACTION = "action", STRREPLYTO = "replyto";
+    /** Refers the To header */
+    public final static String STRTO = "To";
+    /** Refers the From header */
+    public final static String STRFROM = "From";
+    /** Refers the FaultTo header */
+    public final static String STRFAULT = "FaultTo";
+    /** Refers the Action header */
+    public final static String STRACTION = "Action";
+    /** Refers the ReplyTo header */
+    public final static String STRREPLYTO = "ReplyTo";
 
     private int headerType = 0;
 
@@ -45,25 +55,7 @@
         else if (header.equalsIgnoreCase(STRREPLYTO))
             headerType = REPLYTO;
         else
-            throw new SynapseException("Unknown header : " + header);
-    }
-
-    public String getHeaderType() {
-        switch (headerType) {
-
-            case TO:
-                return STRTO;
-            case FROM:
-                return STRFROM;
-            case FAULT:
-                return STRFAULT;
-            case ACTION:
-                return STRACTION;
-            case REPLYTO:
-                return STRREPLYTO;
-
-        }
-        return null;
+            throw new SynapseException("Unknown header type : " + header);
     }
 
     public String getHeader(SynapseMessage sm) {
@@ -98,7 +90,21 @@
         return null;
     }
 
-    public void setHeader(SynapseMessage sm, String value) {
+    /**
+     * Removed the header indicated by this header type from the given message
+     * @param synMsg the current message from which the header should be removed
+     */
+    public void removeHeader(SynapseMessage synMsg) {
+        //TODO This is not yet implemented - revisit later
+        System.err.println("Unimplemented functionality - Needs to be fixed");
+    }
+
+    /**
+     * Sets the given value into the message's indicated header
+     * @param synMsg the current message on which to set the header
+     * @param value the value to be set
+     */
+    public void setHeader(SynapseMessage synMsg, String value) {
         switch (headerType) {
             case 0: {
                 throw new SynapseException(
@@ -107,22 +113,21 @@
 
             case TO: {
 
-                sm.setTo(new EndpointReference(value));
+                synMsg.setTo(new EndpointReference(value));
                 break;
             }
             case FROM: {
-                sm.setFrom(new EndpointReference(value));
+                synMsg.setFrom(new EndpointReference(value));
                 break;
             }
             case REPLYTO: {
-                sm.setReplyTo(new EndpointReference(value));
+                synMsg.setReplyTo(new EndpointReference(value));
                 break;
             }
             case ACTION: {
-                sm.setWSAAction(value);
+                synMsg.setWSAAction(value);
                 break;
             }
-
         }
     }
 }

Modified: incubator/synapse/trunk/scratch/synapse2/modules/core/src/org/apache/synapse/SynapseContext.java
URL: http://svn.apache.org/viewcvs/incubator/synapse/trunk/scratch/synapse2/modules/core/src/org/apache/synapse/SynapseContext.java?rev=399670&r1=399669&r2=399670&view=diff
==============================================================================
--- incubator/synapse/trunk/scratch/synapse2/modules/core/src/org/apache/synapse/SynapseContext.java (original)
+++ incubator/synapse/trunk/scratch/synapse2/modules/core/src/org/apache/synapse/SynapseContext.java Thu May  4 04:32:21 2006
@@ -20,34 +20,29 @@
 
 
 /**
- * The Synapse Environment is available to mediators through the SynapseMessage. It
+ * The Synapse Context is available to mediators through the SynapseMessage. It
  * allows one to call to the underlying SOAP engine (such as Axis2) where required.
  * e.g. send message, get classloader etc. It also holds a reference to the current
  * SynapseConfiguration.
  */
 public interface SynapseContext {
 
-    /*
-    * This method injects a new message into the Synapse engine
-    * It is used in a couple of ways. Firstly, this is how, for example,
-    * Axis2 kicks messages into Synapse to start with.
-    * <p>
-    * Also mediators can use this to send messages that they want to be mediated by Synapse
-    * <p>For example if you want to send a copy of a message somewhere, you can clone it and then
-    * injectMessage()
-    */
+    /**
+     * This method injects a new message into the Synapse engine. This is used by
+     * the underlying SOAP engine to inject messages into Synapse for mediation.
+     * e.g. The SynapseMessageReceiver used by Axis2 invokes this to inject new messages
+     */
     public void injectMessage(SynapseMessage smc);
 
-    /*
-     * Mediators that wish to load classes should use the ClassLoader given here
+    /**
+     * Mediators may get access to the relevant classloader through this
      */
     public ClassLoader getClassLoader();
 
     /**
-     * This method allows you send messages on. As opposed to injectMessage send message does not
-     * process these through Synapse.
+     * This method allows a message to be sent through the underlying SOAP engine.
      * <p/>
-     * This will send request messages on, and send response messages back to the client
+     * This will send request messages on (forward), and send the response messages back to the client
      */
     public void send(SynapseMessage smc);
 
@@ -59,7 +54,8 @@
     public SynapseConfiguration getConfiguration();
 
     /**
-     * Set or replace the Synapse Configuration instance to be used
+     * Set or replace the Synapse Configuration instance to be used. May be used to
+     * programatically change the configuration at runtime etc.
      *
      * @param cfg The new synapse configuration instance
      */

Modified: incubator/synapse/trunk/scratch/synapse2/modules/core/src/org/apache/synapse/SynapseException.java
URL: http://svn.apache.org/viewcvs/incubator/synapse/trunk/scratch/synapse2/modules/core/src/org/apache/synapse/SynapseException.java?rev=399670&r1=399669&r2=399670&view=diff
==============================================================================
--- incubator/synapse/trunk/scratch/synapse2/modules/core/src/org/apache/synapse/SynapseException.java (original)
+++ incubator/synapse/trunk/scratch/synapse2/modules/core/src/org/apache/synapse/SynapseException.java Thu May  4 04:32:21 2006
@@ -24,17 +24,14 @@
 
     public SynapseException(String string) {
         super(string);
-
     }
 
     public SynapseException(String msg, Throwable e) {
         super(msg, e);
-
     }
 
     public SynapseException(Throwable t) {
         super(t);
-
     }
 
 }

Modified: incubator/synapse/trunk/scratch/synapse2/modules/core/src/org/apache/synapse/SynapseMessage.java
URL: http://svn.apache.org/viewcvs/incubator/synapse/trunk/scratch/synapse2/modules/core/src/org/apache/synapse/SynapseMessage.java?rev=399670&r1=399669&r2=399670&view=diff
==============================================================================
--- incubator/synapse/trunk/scratch/synapse2/modules/core/src/org/apache/synapse/SynapseMessage.java (original)
+++ incubator/synapse/trunk/scratch/synapse2/modules/core/src/org/apache/synapse/SynapseMessage.java Thu May  4 04:32:21 2006
@@ -22,7 +22,7 @@
 import org.apache.axis2.addressing.RelatesTo;
 
 /**
- * <p> The core definition of a message flowing thru Synapse.
+ * <p> This interface defines a message flowing through Synapse
  * <p> The aim of this is to capture the Message Addressing Properties
  * (aka Message Information Headers) and the SOAP Envelope.
  * The core To/From/FaultTo/ReplyTo/MessageID/RelatesTo stuff is here. <p>
@@ -33,6 +33,19 @@
  */
 public interface SynapseMessage {
 
+    /**
+     * Get the SOAP envelope of this message
+     * @return the SOAP envelope of the message
+     */
+    public SOAPEnvelope getEnvelope();
+
+    /**
+     * Sets the given envelope as the current SOAPEnvelope for this message
+     * @param envelope the envelope to be set
+     * @throws AxisFault on exception
+     */
+    public void setEnvelope(SOAPEnvelope envelope) throws AxisFault;
+
     public EndpointReference getFaultTo();
 
     public void setFaultTo(EndpointReference reference);
@@ -41,10 +54,6 @@
 
     public void setFrom(EndpointReference reference);
 
-    public SOAPEnvelope getEnvelope();
-
-    public void setEnvelope(SOAPEnvelope envelope) throws AxisFault;
-
     public String getMessageID();
 
     public void setMessageID(String string);
@@ -61,37 +70,109 @@
 
     public void setTo(EndpointReference reference);
 
+    /**
+     * Sets the WSAAction
+     * @param actionURI the WSAAction
+     */
     public void setWSAAction(String actionURI);
 
+    /**
+     * Returns the WSAAction
+     * @return the WSAAction
+     */
     public String getWSAAction();
 
+    /**
+     * Get the value of a custom property set on the message instance
+     * @param key key to look up property
+     * @return value for the given key
+     */
     public Object getProperty(String key);
 
+    /**
+     * Set a custom property with the given name on the message instance
+     * @param key key to be used
+     * @param value value to be saved
+     */
     public void setProperty(String key, Object value);
 
+    /**
+     * Returns the SOAPAction of the message
+     * @return the SOAPAction
+     */
     public String getSoapAction();
 
+    /**
+     * Set the SOAPAction
+     * @param string the SOAP Action
+     */
     public void setSoapAction(String string);
 
+    /**
+     * If this message using MTOM?
+     * @return true if using MTOM
+     */
     public boolean isDoingMTOM();
 
+    /**
+     * Marks as using MTOM
+     * @param b true to mark as using MTOM
+     */
     public void setDoingMTOM(boolean b);
 
+    /**
+     * Is this message over REST?
+     * @return true if over REST
+     */
     public boolean isDoingREST();
 
+    /**
+     * Marks this message as over REST
+     * @param b true to mark as REST
+     */
     public void setDoingREST(boolean b);
 
+    /**
+     * Is this message a SOAP 1.1 message?
+     * @return true if this is a SOAP 1.1 message
+     */
     public boolean isSOAP11();
 
+    /**
+     * Mark this message as a response or not.
+     * @see org.apache.synapse.SynapseMessage#isResponse()
+     * @param b true to set this as a response
+     */
     public void setResponse(boolean b);
 
+    /**
+     * Is this message a response to a synchronous message sent out through Synapse?
+     * @return true if this message is a response message
+     */
     public boolean isResponse();
 
+    /**
+     * Marks this message as a fault response
+     * @see org.apache.synapse.SynapseMessage#isFaultResponse()
+     * @param b true to mark this as a fault response
+     */
     public void setFaultResponse(boolean b);
 
+    /**
+     * Is this message a response to a fault message?
+     * @return true if this is a response to a fault message
+     */
     public boolean isFaultResponse();
 
+    /**
+     * Return a reference to the SynapseContext
+     * @return the SynapseContext
+     */
     public SynapseContext getSynapseContext();
 
+    /**
+     * Set the reference to the SynapseContext
+     * @param env the SynapseContext
+     */
     public void setSynapseContext(SynapseContext env);
 }

Added: incubator/synapse/trunk/scratch/synapse2/modules/core/src/org/apache/synapse/Util.java
URL: http://svn.apache.org/viewcvs/incubator/synapse/trunk/scratch/synapse2/modules/core/src/org/apache/synapse/Util.java?rev=399670&view=auto
==============================================================================
--- incubator/synapse/trunk/scratch/synapse2/modules/core/src/org/apache/synapse/Util.java (added)
+++ incubator/synapse/trunk/scratch/synapse2/modules/core/src/org/apache/synapse/Util.java Thu May  4 04:32:21 2006
@@ -0,0 +1,70 @@
+/*
+* Copyright 2004,2005 The Apache Software Foundation.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+*      http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package org.apache.synapse;
+
+import org.apache.axiom.om.xpath.AXIOMXPath;
+import org.apache.axiom.om.impl.llom.OMElementImpl;
+import org.apache.axiom.om.impl.llom.OMTextImpl;
+import org.apache.commons.logging.LogFactory;
+import org.apache.commons.logging.Log;
+import org.jaxen.JaxenException;
+
+import java.util.Iterator;
+import java.util.List;
+
+/**
+ * Holds utility methods used by Synapse
+ */
+public class Util {
+
+    private static final Log log = LogFactory.getLog(Util.class);
+
+    /**
+     * Evaluates the given XPath expression against the SOAPEnvelope of the
+     * current message and returns a String representation of the result
+     * @param xpath the expression to evaluate
+     * @param synMsg the source message which holds the SOAP envelope
+     * @return a String representation of the result of evaluation
+     */
+    public static String getStringValue(AXIOMXPath xpath, SynapseMessage synMsg) {
+
+        try {
+            Object result = xpath.evaluate(synMsg.getEnvelope());
+            StringBuffer textValue = new StringBuffer();
+
+            if (result instanceof List) {
+                Iterator iter = ((List) result).iterator();
+                while (iter.hasNext()) {
+                    Object o = iter.next();
+                    if (o instanceof OMTextImpl) {
+                        textValue.append(((OMTextImpl) o).getText());
+                    } else if (o instanceof OMElementImpl) {
+                        textValue.append(((OMElementImpl) o).getText());
+                    }
+                }
+            } else {
+                textValue.append(result.toString());
+            }
+            return textValue.toString();
+
+        } catch (JaxenException je) {
+            String msg = "Evaluation of the XPath expression " + xpath.toString() + " resulted in an error";
+            log.error(msg);
+            throw new SynapseException(msg);
+        }
+    }
+
+}

Modified: incubator/synapse/trunk/scratch/synapse2/modules/core/src/org/apache/synapse/api/FilterMediator.java
URL: http://svn.apache.org/viewcvs/incubator/synapse/trunk/scratch/synapse2/modules/core/src/org/apache/synapse/api/FilterMediator.java?rev=399670&r1=399669&r2=399670&view=diff
==============================================================================
--- incubator/synapse/trunk/scratch/synapse2/modules/core/src/org/apache/synapse/api/FilterMediator.java (original)
+++ incubator/synapse/trunk/scratch/synapse2/modules/core/src/org/apache/synapse/api/FilterMediator.java Thu May  4 04:32:21 2006
@@ -3,9 +3,18 @@
 import org.apache.synapse.SynapseMessage;
 
 /**
- * The filter mediator is a list mediator, which executes the given list of mediators
+ * The filter mediator is a list mediator, which executes the given (sub) list of mediators
  * if the specified condition is satisfied
+ *
+ * @see FilterMediator#test(org.apache.synapse.SynapseMessage)
  */
 public interface FilterMediator extends ListMediator {
+
+    /**
+     * Should return true if the sub/child mediators should execute. i.e. if the filter
+     * condition is satisfied
+     * @param sm the current message flowing through
+     * @return true if the configured filter condition evaluates to true
+     */
     public boolean test(SynapseMessage sm);
 }

Modified: incubator/synapse/trunk/scratch/synapse2/modules/core/src/org/apache/synapse/api/ListMediator.java
URL: http://svn.apache.org/viewcvs/incubator/synapse/trunk/scratch/synapse2/modules/core/src/org/apache/synapse/api/ListMediator.java?rev=399670&r1=399669&r2=399670&view=diff
==============================================================================
--- incubator/synapse/trunk/scratch/synapse2/modules/core/src/org/apache/synapse/api/ListMediator.java (original)
+++ incubator/synapse/trunk/scratch/synapse2/modules/core/src/org/apache/synapse/api/ListMediator.java Thu May  4 04:32:21 2006
@@ -22,13 +22,37 @@
  */
 public interface ListMediator extends Mediator {
 
+    /**
+     * Appends the specified mediator to the end of this mediator's (children) list
+     * @param m the mediator to be added
+     * @return true (as per the general contract of the Collection.add method)
+     */
     public boolean addChild(Mediator m);
 
+    /**
+     * Returns the mediator at the specified position
+     * @param pos index of mediator to return
+     * @return the mediator at the specified position in this list
+     */
     public Mediator getChild(int pos);
 
+    /**
+     * Removes the first occurrence in this list of the specified mediator
+     * @param m mediator to be removed from this list, if present
+     * @return true if this list contained the specified mediator
+     */
     public boolean removeChild(Mediator m);
 
+    /**
+     * Removes the mediator at the specified position in this list
+     * @param pos the index of the mediator to remove
+     * @return the mediator previously at the specified position
+     */
     public Mediator removeChild(int pos);
 
+    /**
+     * Return the list of mediators of this List mediator instance
+     * @return the child/sub mediator list
+     */
     public List getList();
 }

Modified: incubator/synapse/trunk/scratch/synapse2/modules/core/src/org/apache/synapse/api/Mediator.java
URL: http://svn.apache.org/viewcvs/incubator/synapse/trunk/scratch/synapse2/modules/core/src/org/apache/synapse/api/Mediator.java?rev=399670&r1=399669&r2=399670&view=diff
==============================================================================
--- incubator/synapse/trunk/scratch/synapse2/modules/core/src/org/apache/synapse/api/Mediator.java (original)
+++ incubator/synapse/trunk/scratch/synapse2/modules/core/src/org/apache/synapse/api/Mediator.java Thu May  4 04:32:21 2006
@@ -19,10 +19,25 @@
 
 /**
  * All Synapse mediators must implement this Mediator interface. As a message passes
- * through the synapse system, each mediator's mediate() method is invoked.
+ * through the synapse system, each mediator's mediate() method is invoked in the
+ * sequence/order defined in the SynapseConfiguration.
  */
 public interface Mediator {
+
+    /**
+     * Invokes the mediator passing the current message for mediation. Each
+     * mediator performs its mediation action, and returns true if mediation
+     * should continue, or false if further mediation should be aborted.
+     *
+     * @param smc the current message for mediation
+     * @return true if further mediation should continue
+     */
     public boolean mediate(SynapseMessage smc);
 
+    /**
+     * This is used for debugging purposes and exposes the type of the current
+     * mediator for logging and debugging purposes
+     * @return a String representation of the mediator type
+     */
     public String getType();
 }

Modified: incubator/synapse/trunk/scratch/synapse2/modules/core/src/org/apache/synapse/config/HeaderMediatorFactory.java
URL: http://svn.apache.org/viewcvs/incubator/synapse/trunk/scratch/synapse2/modules/core/src/org/apache/synapse/config/HeaderMediatorFactory.java?rev=399670&r1=399669&r2=399670&view=diff
==============================================================================
--- incubator/synapse/trunk/scratch/synapse2/modules/core/src/org/apache/synapse/config/HeaderMediatorFactory.java (original)
+++ incubator/synapse/trunk/scratch/synapse2/modules/core/src/org/apache/synapse/config/HeaderMediatorFactory.java Thu May  4 04:32:21 2006
@@ -25,6 +25,8 @@
 import org.apache.synapse.mediators.transform.HeaderMediator;
 import org.apache.axiom.om.OMElement;
 import org.apache.axiom.om.OMAttribute;
+import org.apache.axiom.om.xpath.AXIOMXPath;
+import org.jaxen.JaxenException;
 
 /**
  *
@@ -63,8 +65,16 @@
 
         if (value != null && value.getAttributeValue() != null) {
             headerMediator.setValue(value.getAttributeValue());
+
         } else if (exprn != null && exprn.getAttributeValue() != null) {
-            headerMediator.setExpression(exprn.getAttributeValue());
+            try {
+                headerMediator.setExpression(new AXIOMXPath(exprn.getAttributeValue()));
+            } catch (JaxenException je) {
+                String msg = "Invalid XPath expression : " + exprn.getAttributeValue();
+                log.error(msg);
+                throw new SynapseException(msg, je);
+            }
+            
         } else {
             String msg = "Invalid attribute value for the attribute 'expression' or 'value'";
             log.error(msg);

Modified: incubator/synapse/trunk/scratch/synapse2/modules/core/src/org/apache/synapse/config/LogMediatorFactory.java
URL: http://svn.apache.org/viewcvs/incubator/synapse/trunk/scratch/synapse2/modules/core/src/org/apache/synapse/config/LogMediatorFactory.java?rev=399670&r1=399669&r2=399670&view=diff
==============================================================================
--- incubator/synapse/trunk/scratch/synapse2/modules/core/src/org/apache/synapse/config/LogMediatorFactory.java (original)
+++ incubator/synapse/trunk/scratch/synapse2/modules/core/src/org/apache/synapse/config/LogMediatorFactory.java Thu May  4 04:32:21 2006
@@ -25,6 +25,8 @@
 import org.apache.synapse.mediators.MediatorProperty;
 import org.apache.axiom.om.OMElement;
 import org.apache.axiom.om.OMAttribute;
+import org.apache.axiom.om.xpath.AXIOMXPath;
+import org.jaxen.JaxenException;
 
 import java.util.Iterator;
 
@@ -51,6 +53,7 @@
 
         LogMediator logMediator = new LogMediator();
 
+        // Set the high level set of properties to be logged (i.e. log level)
         OMAttribute level = elem.getAttribute(new QName(Constants.NULL_NAMESPACE, "level"));
         if (level != null) {
             if (SIMPLE.equals(level)) {
@@ -64,6 +67,13 @@
             }
         }
 
+        // check if a custom seperator has been supplied, if so use it
+        OMAttribute seperator = elem.getAttribute(new QName(Constants.NULL_NAMESPACE, "seperator"));
+        if (seperator != null) {
+            logMediator.setSeperator(seperator.getAttributeValue());
+        }
+
+        // parse custom properties and set them into the mediator
         Iterator iter = elem.getChildrenWithName(new QName(Constants.NULL_NAMESPACE, "property"));
         while (iter.hasNext()) {
 
@@ -93,12 +103,21 @@
                 }
 
             } else if (attExpr != null) {
+
                 if (attExpr.getAttributeValue() == null || attExpr.getAttributeValue().trim().length() == 0) {
                     String msg = "Property attribute expression (if specified) is required for a Log property";
                     log.error(msg);
                     throw new SynapseException(msg);
+
                 } else {
-                    prop.setExpression(attValue.getAttributeValue());
+                    try {
+                        prop.setExpression(new AXIOMXPath(attExpr.getAttributeValue()));
+
+                    } catch (JaxenException e) {
+                        String msg = "Invalid XPapth expression : " + attExpr.getAttributeValue();
+                        log.error(msg);
+                        throw new SynapseException(msg, e);
+                    }
                 }
 
             } else {

Modified: incubator/synapse/trunk/scratch/synapse2/modules/core/src/org/apache/synapse/mediators/AbstractListMediator.java
URL: http://svn.apache.org/viewcvs/incubator/synapse/trunk/scratch/synapse2/modules/core/src/org/apache/synapse/mediators/AbstractListMediator.java?rev=399670&r1=399669&r2=399670&view=diff
==============================================================================
--- incubator/synapse/trunk/scratch/synapse2/modules/core/src/org/apache/synapse/mediators/AbstractListMediator.java (original)
+++ incubator/synapse/trunk/scratch/synapse2/modules/core/src/org/apache/synapse/mediators/AbstractListMediator.java Thu May  4 04:32:21 2006
@@ -24,6 +24,11 @@
 import java.util.Iterator;
 import java.util.List;
 
+/**
+ * This class implements the base functionality of a List mediator
+ *
+ * @see ListMediator
+ */
 public abstract class AbstractListMediator extends AbstractMediator implements ListMediator {
 
     protected List mediators = new ArrayList();

Modified: incubator/synapse/trunk/scratch/synapse2/modules/core/src/org/apache/synapse/mediators/AbstractMediator.java
URL: http://svn.apache.org/viewcvs/incubator/synapse/trunk/scratch/synapse2/modules/core/src/org/apache/synapse/mediators/AbstractMediator.java?rev=399670&r1=399669&r2=399670&view=diff
==============================================================================
--- incubator/synapse/trunk/scratch/synapse2/modules/core/src/org/apache/synapse/mediators/AbstractMediator.java (original)
+++ incubator/synapse/trunk/scratch/synapse2/modules/core/src/org/apache/synapse/mediators/AbstractMediator.java Thu May  4 04:32:21 2006
@@ -19,10 +19,18 @@
 import org.apache.commons.logging.LogFactory;
 import org.apache.synapse.api.Mediator;
 
+/**
+ * This class is an abstract Mediator, that defines the logging and debugging
+ * elements of a mediator class.
+ */
 public abstract class AbstractMediator implements Mediator {
 
     protected final Log log = LogFactory.getLog(getClass());
 
+    /**
+     * Returns the class name of the mediator
+     * @return the class name of the mediator
+     */
     public String getType() {
         return getClass().getSimpleName();
     }

Modified: incubator/synapse/trunk/scratch/synapse2/modules/core/src/org/apache/synapse/mediators/MediatorProperty.java
URL: http://svn.apache.org/viewcvs/incubator/synapse/trunk/scratch/synapse2/modules/core/src/org/apache/synapse/mediators/MediatorProperty.java?rev=399670&r1=399669&r2=399670&view=diff
==============================================================================
--- incubator/synapse/trunk/scratch/synapse2/modules/core/src/org/apache/synapse/mediators/MediatorProperty.java (original)
+++ incubator/synapse/trunk/scratch/synapse2/modules/core/src/org/apache/synapse/mediators/MediatorProperty.java Thu May  4 04:32:21 2006
@@ -16,9 +16,17 @@
 package org.apache.synapse.mediators;
 
 import org.apache.synapse.config.Constants;
+import org.apache.synapse.Util;
+import org.apache.synapse.SynapseMessage;
+import org.apache.axiom.om.xpath.AXIOMXPath;
 
 import javax.xml.namespace.QName;
 
+/**
+ * A mediator property is a name-value or name-expression pair which could be supplied
+ * for certain mediators. If expressions are supplied they are evaluated at the runtime
+ * against the current message into literal String values.
+ */
 public class MediatorProperty {
 
     public static final QName PROPERTY_Q  = new QName(Constants.SYNAPSE_NAMESPACE, "property");
@@ -28,7 +36,7 @@
 
     private String name;
     private String value;
-    private String expression;
+    private AXIOMXPath expression;
 
     public MediatorProperty() {}
 
@@ -48,16 +56,16 @@
         this.value = value;
     }
 
-    public String getExpression() {
+    public AXIOMXPath getExpression() {
         return expression;
     }
 
-    public void setExpression(String expression) {
+    public void setExpression(AXIOMXPath expression) {
         this.expression = expression;
     }
 
-    public String getEvaluatedExpression() {
-        return expression;  //TODO later use XPath xtention eval
+    public String getEvaluatedExpression(SynapseMessage synMsg) {
+        return Util.getStringValue(expression, synMsg);
     }
 
 }

Modified: incubator/synapse/trunk/scratch/synapse2/modules/core/src/org/apache/synapse/mediators/base/SequenceMediator.java
URL: http://svn.apache.org/viewcvs/incubator/synapse/trunk/scratch/synapse2/modules/core/src/org/apache/synapse/mediators/base/SequenceMediator.java?rev=399670&r1=399669&r2=399670&view=diff
==============================================================================
--- incubator/synapse/trunk/scratch/synapse2/modules/core/src/org/apache/synapse/mediators/base/SequenceMediator.java (original)
+++ incubator/synapse/trunk/scratch/synapse2/modules/core/src/org/apache/synapse/mediators/base/SequenceMediator.java Thu May  4 04:32:21 2006
@@ -31,7 +31,11 @@
 
     /**
      * If this mediator refers to another named Sequence, execute that. Else
-     * execute the list of mediators (children) contained within this.
+     * execute the list of mediators (children) contained within this. If a referenced
+     * named sequence mediator instance cannot be found at runtime, an exception is
+     * thrown. This may occur due to invalid configuration of an erroneous runtime
+     * change of the synapse configuration. It is the responsibility of the
+     * SynapseConfiguration builder to ensure that dead references are not present.
      *
      * @param synMsg the synapse message
      * @return as per standard mediator result
@@ -40,6 +44,7 @@
         log.debug(getType() + " mediate()");
         if (ref == null) {
             return super.mediate(synMsg);
+
         } else {
             Mediator m = synMsg.getSynapseContext().getConfiguration().getNamedMediator(ref);
             if (m == null) {

Modified: incubator/synapse/trunk/scratch/synapse2/modules/core/src/org/apache/synapse/mediators/base/SynapseMediator.java
URL: http://svn.apache.org/viewcvs/incubator/synapse/trunk/scratch/synapse2/modules/core/src/org/apache/synapse/mediators/base/SynapseMediator.java?rev=399670&r1=399669&r2=399670&view=diff
==============================================================================
--- incubator/synapse/trunk/scratch/synapse2/modules/core/src/org/apache/synapse/mediators/base/SynapseMediator.java (original)
+++ incubator/synapse/trunk/scratch/synapse2/modules/core/src/org/apache/synapse/mediators/base/SynapseMediator.java Thu May  4 04:32:21 2006
@@ -21,7 +21,11 @@
 /**
  * The SynapseMediator is the "mainmediator" of the synapse engine. It is
  * given each message on arrival at the synapse engine. The synapse configuration
- * holds a reference to this special mediator instance.
+ * holds a reference to this special mediator instance. The SynapseMediator
+ * holds the list of mediators supplied within the <rules> element of an XML
+ * based Synapse configuration
+ *
+ * @see org.apache.synapse.config.SynapseConfiguration#getMainMediator()
  */
 public class SynapseMediator extends AbstractListMediator {
 }

Modified: incubator/synapse/trunk/scratch/synapse2/modules/core/src/org/apache/synapse/mediators/builtin/DropMediator.java
URL: http://svn.apache.org/viewcvs/incubator/synapse/trunk/scratch/synapse2/modules/core/src/org/apache/synapse/mediators/builtin/DropMediator.java?rev=399670&r1=399669&r2=399670&view=diff
==============================================================================
--- incubator/synapse/trunk/scratch/synapse2/modules/core/src/org/apache/synapse/mediators/builtin/DropMediator.java (original)
+++ incubator/synapse/trunk/scratch/synapse2/modules/core/src/org/apache/synapse/mediators/builtin/DropMediator.java Thu May  4 04:32:21 2006
@@ -20,10 +20,15 @@
 import org.apache.synapse.mediators.AbstractMediator;
 
 /**
- * Halts further processing/mediation of the current message.
+ * Halts further processing/mediation of the current message. i.e. returns false
  */
 public class DropMediator extends AbstractMediator {
 
+    /**
+     * Halts further mediation of the current message by returning false.
+     * @param synMsg the current message
+     * @return false always
+     */
     public boolean mediate(SynapseMessage synMsg) {
         log.debug(getType() + " mediate()");
         if (synMsg.getTo() == null) {

Modified: incubator/synapse/trunk/scratch/synapse2/modules/core/src/org/apache/synapse/mediators/builtin/LogMediator.java
URL: http://svn.apache.org/viewcvs/incubator/synapse/trunk/scratch/synapse2/modules/core/src/org/apache/synapse/mediators/builtin/LogMediator.java?rev=399670&r1=399669&r2=399670&view=diff
==============================================================================
--- incubator/synapse/trunk/scratch/synapse2/modules/core/src/org/apache/synapse/mediators/builtin/LogMediator.java (original)
+++ incubator/synapse/trunk/scratch/synapse2/modules/core/src/org/apache/synapse/mediators/builtin/LogMediator.java Thu May  4 04:32:21 2006
@@ -28,7 +28,10 @@
 
 /**
  * Logs the specified message into the configured logger. The log levels specify
- * which attributes would be logged, and is configurable.
+ * which attributes would be logged, and is configurable. Additionally custom
+ * properties may be defined to the logger, where literal values or expressions
+ * could be specified for logging. The custom properties are printed into the log
+ * using the defined seperator (\n, "," etc)
  */
 public class LogMediator extends AbstractMediator {
 
@@ -41,6 +44,11 @@
     private String SEP = ", ";
     private List properties = new ArrayList();
 
+    /**
+     * Logs the current message according to the supplied semantics
+     * @param synMsg (current) message to be logged
+     * @return true always
+     */
     public boolean mediate(SynapseMessage synMsg) {
         log.debug(getType() + " mediate()");
         log.info(getLogMessage(synMsg));
@@ -71,7 +79,7 @@
     private String getSimpleLogMessage(SynapseMessage synMsg) {
         StringBuffer sb = new StringBuffer();
         if (synMsg.getTo() != null)
-            sb.append(SEP + "To: " + synMsg.getTo().getAddress());
+            sb.append("To: " + synMsg.getTo().getAddress());
         if (synMsg.getFrom() != null)
             sb.append(SEP + "From: " + synMsg.getFrom().getAddress());
         if (synMsg.getWSAAction() != null)
@@ -112,7 +120,7 @@
             while (iter.hasNext()) {
                 MediatorProperty prop = (MediatorProperty) iter.next();
                 sb.append(SEP + prop.getName() + " = " +
-                    (prop.getValue() != null ? prop.getValue() : prop.getEvaluatedExpression()));
+                    (prop.getValue() != null ? prop.getValue() : prop.getEvaluatedExpression(synMsg)));
             }
         }
     }

Modified: incubator/synapse/trunk/scratch/synapse2/modules/core/src/org/apache/synapse/mediators/builtin/SendMediator.java
URL: http://svn.apache.org/viewcvs/incubator/synapse/trunk/scratch/synapse2/modules/core/src/org/apache/synapse/mediators/builtin/SendMediator.java?rev=399670&r1=399669&r2=399670&view=diff
==============================================================================
--- incubator/synapse/trunk/scratch/synapse2/modules/core/src/org/apache/synapse/mediators/builtin/SendMediator.java (original)
+++ incubator/synapse/trunk/scratch/synapse2/modules/core/src/org/apache/synapse/mediators/builtin/SendMediator.java Thu May  4 04:32:21 2006
@@ -23,23 +23,23 @@
 /**
  * The Send mediator sends the message using the following semantics.
  * <p/>
- * This is a leaf mediator (i.e. further processing does not continue after this is invoked)
+ * This is a leaf mediator (i.e. further processing halts after this mediator completes)
  * <p/>
  * TODO support endpoints, loadbalancing and failover
  */
 public class SendMediator extends AbstractMediator {
 
     /**
-     * This is a leaf mediator. i.e. processing stops once send is invoked.
+     * This is a leaf mediator. i.e. processing stops once send is invoked,
+     * as it always returns false
      *
-     * @param synMsg
+     * @param synMsg the current message to be sent
      * @return false always as this is a leaf mediator
      */
     public boolean mediate(SynapseMessage synMsg) {
         log.debug(getType() + " mediate()");
         log.debug("Sending To: " + (synMsg.getTo() != null ? synMsg.getTo().getAddress() : "null"));
         log.debug("Body : \n" + synMsg.getEnvelope());
-        //synMsg.setProperty(Constants.ENGAGE_ADDRESSING_OUT_BOUND_MESSAGE, Boolean.TRUE);
         synMsg.getSynapseContext().send(synMsg);
         return false;
     }

Modified: incubator/synapse/trunk/scratch/synapse2/modules/core/src/org/apache/synapse/mediators/ext/ClassMediator.java
URL: http://svn.apache.org/viewcvs/incubator/synapse/trunk/scratch/synapse2/modules/core/src/org/apache/synapse/mediators/ext/ClassMediator.java?rev=399670&r1=399669&r2=399670&view=diff
==============================================================================
--- incubator/synapse/trunk/scratch/synapse2/modules/core/src/org/apache/synapse/mediators/ext/ClassMediator.java (original)
+++ incubator/synapse/trunk/scratch/synapse2/modules/core/src/org/apache/synapse/mediators/ext/ClassMediator.java Thu May  4 04:32:21 2006
@@ -27,6 +27,7 @@
  * This executes the "mediate" operation on a new instance of the specified class
  * <p/>
  * TODO add support for simple properties to be set
+ * TODO Requires refactoring and cleanup - revisit later
  */
 public class ClassMediator extends AbstractMediator {
 

Modified: incubator/synapse/trunk/scratch/synapse2/modules/core/src/org/apache/synapse/mediators/filters/FilterMediator.java
URL: http://svn.apache.org/viewcvs/incubator/synapse/trunk/scratch/synapse2/modules/core/src/org/apache/synapse/mediators/filters/FilterMediator.java?rev=399670&r1=399669&r2=399670&view=diff
==============================================================================
--- incubator/synapse/trunk/scratch/synapse2/modules/core/src/org/apache/synapse/mediators/filters/FilterMediator.java (original)
+++ incubator/synapse/trunk/scratch/synapse2/modules/core/src/org/apache/synapse/mediators/filters/FilterMediator.java Thu May  4 04:32:21 2006
@@ -21,6 +21,7 @@
 import org.apache.axiom.om.impl.llom.OMTextImpl;
 import org.apache.axiom.om.impl.llom.OMElementImpl;
 import org.apache.synapse.SynapseMessage;
+import org.apache.synapse.Util;
 import org.apache.synapse.mediators.AbstractListMediator;
 import org.jaxen.JaxenException;
 
@@ -28,7 +29,6 @@
 import java.util.List;
 import java.util.Iterator;
 
-
 /**
  * The filter mediator combines the regex and xpath filtering functionality. If an xpath
  * is set, it is evaluated; else the given regex is evaluated against the source xpath.
@@ -39,6 +39,11 @@
     private Pattern regex = null;
     private AXIOMXPath xpath = null;
 
+    /**
+     * Executes the list of sub/child mediators, if the filter condition is satisfied
+     * @param synMsg the current message
+     * @return true if filter condition fails. else returns as per List mediator semantics
+     */
     public boolean mediate(SynapseMessage synMsg) {
         log.debug(getType() + " mediate()");
         if (test(synMsg)) {
@@ -48,30 +53,21 @@
         }
     }
 
+    /**
+     * Tests the supplied condition after evaluation against the given XPath
+     * or Regex (against a source XPath). When a regular expression is supplied
+     * the source XPath is evaluated into a String value, and matched against
+     * the given regex
+     * @param synMsg the current message for evaluation of the test condition
+     * @return true if evaluation of the XPath/Regex results in true
+     */
     public boolean test(SynapseMessage synMsg) {
         try {
             if (xpath != null) {
                 return xpath.booleanValueOf(synMsg.getEnvelope());
 
             } else if (source != null && regex != null) {
-
-                Object result = source.evaluate(synMsg.getEnvelope());
-                String textValue = "";
-
-                if (result instanceof List) {
-                    Iterator iter = ((List) result).iterator();
-                    while (iter.hasNext()) {
-                        Object o = iter.next();
-                        if (o instanceof OMTextImpl) {
-                            textValue += ((OMTextImpl) o).getText();
-                        } else if (o instanceof OMElementImpl) {
-                            textValue += ((OMElementImpl) o).getText();
-                        }
-                    }
-                } else {
-                    textValue = result.toString();
-                }
-                return regex.matcher(textValue).matches();
+                return regex.matcher(Util.getStringValue(source, synMsg)).matches();
 
             } else {
                 log.error("Invalid configuration specified");
@@ -109,6 +105,4 @@
         this.xpath = xpath;
     }
 
-    //TODO name space addition support for xpath
-    // i.e. xp.addNamespace(prefix, uri);
 }

Modified: incubator/synapse/trunk/scratch/synapse2/modules/core/src/org/apache/synapse/mediators/transform/FaultMediator.java
URL: http://svn.apache.org/viewcvs/incubator/synapse/trunk/scratch/synapse2/modules/core/src/org/apache/synapse/mediators/transform/FaultMediator.java?rev=399670&r1=399669&r2=399670&view=diff
==============================================================================
--- incubator/synapse/trunk/scratch/synapse2/modules/core/src/org/apache/synapse/mediators/transform/FaultMediator.java (original)
+++ incubator/synapse/trunk/scratch/synapse2/modules/core/src/org/apache/synapse/mediators/transform/FaultMediator.java Thu May  4 04:32:21 2006
@@ -30,19 +30,20 @@
 import javax.xml.namespace.QName;
 
 /**
- * <p/> This returns a fault in response to this message
+ * This transforms the current message instance into a SOAP Fault message. If the
+ * original message was SOAP 1.1 the fault will also be SOAP 1.1 else, SOAP 1.2
+ *
+ * TODO this class needs more attention! - revisit later
  */
 public class FaultMediator extends AbstractMediator {
 
-    private Log log = LogFactory.getLog(getClass());
-
     public static final int SOAP11 = 1;
     public static final int SOAP12 = 2;
 
     private int soapVersion;
-
     private QName code;
     private String reason;
+
     //TODO support SOAP 1.2 fault stuff..
     //Node, Role, detail etc
 

Modified: incubator/synapse/trunk/scratch/synapse2/modules/core/src/org/apache/synapse/mediators/transform/HeaderMediator.java
URL: http://svn.apache.org/viewcvs/incubator/synapse/trunk/scratch/synapse2/modules/core/src/org/apache/synapse/mediators/transform/HeaderMediator.java?rev=399670&r1=399669&r2=399670&view=diff
==============================================================================
--- incubator/synapse/trunk/scratch/synapse2/modules/core/src/org/apache/synapse/mediators/transform/HeaderMediator.java (original)
+++ incubator/synapse/trunk/scratch/synapse2/modules/core/src/org/apache/synapse/mediators/transform/HeaderMediator.java Thu May  4 04:32:21 2006
@@ -18,7 +18,18 @@
 import org.apache.synapse.mediators.AbstractMediator;
 import org.apache.synapse.SynapseMessage;
 import org.apache.synapse.HeaderType;
+import org.apache.synapse.Util;
+import org.apache.axiom.om.xpath.AXIOMXPath;
 
+/**
+ * The header mediator is able to set a given value as a SOAP header, or remove a given
+ * header from the current message instance. This supports the headers currently
+ * supported by the HeaderType class. If an expression is supplied, its runtime value
+ * is evaluated using the current message. Unless the action is set to remove, the
+ * default behaviour of this mediator is to set a header value.
+ *
+ * @see HeaderType
+ */
 public class HeaderMediator extends AbstractMediator {
 
     public static final int ACTION_SET = 0;
@@ -28,16 +39,24 @@
     private String value = null;
     private int action = ACTION_SET;
 
-    private String expression = null; //TODO handle this case later
+    private AXIOMXPath expression = null;
     private HeaderType headerType = new HeaderType();
 
+    /**
+     * Sets/Removes a SOAP header on the current message
+     *
+     * @param synMsg the current message which is altered as necessary
+     * @return true always
+     */
     public boolean mediate(SynapseMessage synMsg) {
         log.debug(getType() + " mediate()");
+
         if (action == ACTION_SET) {
-            headerType.setHeader(synMsg, getValue());
-            //TODO support exprns later
+            headerType.setHeader(synMsg,
+                (getValue() != null ? getValue() : Util.getStringValue(getExpression(), synMsg)));
+
         } else {
-            //TODO remove header later
+            headerType.removeHeader(synMsg);
         }
         return true;
     }
@@ -67,11 +86,11 @@
         this.value = value;
     }
 
-    public String getExpression() {
+    public AXIOMXPath getExpression() {
         return expression;
     }
 
-    public void setExpression(String expression) {
+    public void setExpression(AXIOMXPath expression) {
         this.expression = expression;
     }
 }

Copied: incubator/synapse/trunk/scratch/synapse2/modules/core/src/org/apache/synapse/mediators/transform/TransformMediator.java (from r399252, incubator/synapse/trunk/scratch/synapse2/modules/core/src/org/apache/synapse/mediators/transform/XSLTMediator.java)
URL: http://svn.apache.org/viewcvs/incubator/synapse/trunk/scratch/synapse2/modules/core/src/org/apache/synapse/mediators/transform/TransformMediator.java?p2=incubator/synapse/trunk/scratch/synapse2/modules/core/src/org/apache/synapse/mediators/transform/TransformMediator.java&p1=incubator/synapse/trunk/scratch/synapse2/modules/core/src/org/apache/synapse/mediators/transform/XSLTMediator.java&r1=399252&r2=399670&rev=399670&view=diff
==============================================================================
--- incubator/synapse/trunk/scratch/synapse2/modules/core/src/org/apache/synapse/mediators/transform/XSLTMediator.java (original)
+++ incubator/synapse/trunk/scratch/synapse2/modules/core/src/org/apache/synapse/mediators/transform/TransformMediator.java Thu May  4 04:32:21 2006
@@ -22,23 +22,35 @@
 import java.net.URL;
 
 /**
- * @see org.apache.synapse.mediators.base.builtin.xslt.XSLTProcessorConfigurator
- *      <p> This class is the class that transforms messages using XSLT.
+ * The transform mediator performs an XSLT or XQuery transformation requested, using
+ * the current message. The source attribute (if available) spcifies the source element
+ * on which the transformation would be applied. Additional properties passed into this
+ * mediator would become parameters (for XSLT) or variables (XQuery).
  */
-public class XSLTMediator extends AbstractMediator {
+public class TransformMediator extends AbstractMediator {
 
     private URL xsltUrl = null;
     private URL xqUrl = null;
     private String source = null;
 
+    /**
+     * Transforms this message (or its element specified as the source) using the
+     * given XSLT or XQuery transformation
+     * @param synMsg the current message where the transformation will apply
+     * @return true always
+     */
     public boolean mediate(SynapseMessage synMsg) {
         log.debug(getType() + " mediate()");
+
         if (xsltUrl != null) {
             performXLST(synMsg);
             return true;
+
         } else if (xqUrl != null) {
-            //TODO later
+            //TODO later revisit later
+            System.err.println("Unimplemented functionality..");
             return true;
+
         } else {
             log.error("Invalid configuration - xslt/xq not specified");
             return false;
@@ -47,39 +59,57 @@
 
     private void performXLST(SynapseMessage synMsg) {
         try {
+            // create a transformer
             Transformer transformer = TransformerFactory.newInstance().newTransformer(
                 new StreamSource(xsltUrl.openStream()));
 
-            ByteArrayOutputStream baos = new ByteArrayOutputStream();
-            XMLStreamWriter xsWriter = XMLOutputFactory.newInstance().createXMLStreamWriter(baos);
+            // create a byte array output stream and serialize the source node into it
+            ByteArrayOutputStream baosForSource = new ByteArrayOutputStream();
+            XMLStreamWriter xsWriterForSource = XMLOutputFactory.newInstance().createXMLStreamWriter(baosForSource);
 
             AXIOMXPath xp = new AXIOMXPath(source);
-            OMNode sourceNode = (OMNode) xp.evaluate(synMsg.getEnvelope());
-            sourceNode.serialize(xsWriter);
+            Object result = xp.evaluate(synMsg.getEnvelope());
+            OMNode sourceNode = null;
 
-            synMsg.getEnvelope().getBody().serialize(xsWriter);
+            if (result instanceof OMNode) {
+                sourceNode = (OMNode) result;
+            } else {
+                String msg = "XPath evaluation of the source element did not return an OMNode";
+                log.error(msg);
+                throw new SynapseException(msg);
+            }
+            sourceNode.serialize(xsWriterForSource);
+            Source transformSrc = new StreamSource(new ByteArrayInputStream(baosForSource.toByteArray()));
+
+            // create a new Stream result over a new BAOS..
+            ByteArrayOutputStream baosForTarget = new ByteArrayOutputStream();
+            StreamResult transformTgt = new StreamResult(baosForTarget);
 
-            Source transformSrc = new StreamSource(new ByteArrayInputStream(baos.toByteArray()));
-            ByteArrayOutputStream baos2 = new ByteArrayOutputStream();
-            StreamResult transformTgt = new StreamResult(baos2);
+            // perform transformation
             transformer.transform(transformSrc, transformTgt);
 
-            StAXOMBuilder builder = new StAXOMBuilder(new ByteArrayInputStream(baos2.toByteArray()));
+            StAXOMBuilder builder = new StAXOMBuilder(new ByteArrayInputStream(baosForTarget.toByteArray()));
             sourceNode.getParent().addChild(builder.getDocumentElement());
 
         } catch (MalformedURLException mue) {
-            throw new SynapseException(mue);
+            handleException(mue);
         } catch (TransformerConfigurationException tce) {
-            throw new SynapseException(tce);
+            handleException(tce);
         } catch (XMLStreamException xse) {
-            throw new SynapseException(xse);
+            handleException(xse);
         } catch (JaxenException je) {
-            throw new SynapseException(je);
+            handleException(je);
         } catch (TransformerException te) {
-            throw new SynapseException(te);
+            handleException(te);
         } catch (IOException ioe) {
-            throw new SynapseException(ioe);
+            handleException(ioe);
         }
+    }
+
+    private void handleException(Exception e) {
+        String msg = "Error performing XSLT/XQ transformation " + e.getMessage();
+        log.error(msg);
+        throw new SynapseException(msg, e);
     }
 
 }



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