You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@synapse.apache.org by sa...@apache.org on 2006/05/03 12:58:26 UTC

svn commit: r399252 [2/2] - in /incubator/synapse/trunk/scratch/synapse2/modules/core/src/org/apache/synapse: ./ api/ axis2/ config/ mediators/ mediators/base/ mediators/builtin/ mediators/ext/ mediators/filters/ mediators/transform/

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=399252&r1=399251&r2=399252&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 Wed May  3 03:58:21 2006
@@ -28,13 +28,14 @@
  * 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.
  */
-public class FilterMediator extends AbstractListMediator {
+public class FilterMediator extends AbstractListMediator implements org.apache.synapse.api.FilterMediator {
 
-    private String source = null;
-    private String regex = null;
-    private String xpath = null;
+    private AXIOMXPath source = null;
+    private Pattern regex = null;
+    private AXIOMXPath xpath = null;
 
     public boolean mediate(SynapseMessage synMsg) {
+        log.debug(getType() + " mediate()");
         if (test(synMsg)) {
             return super.mediate(synMsg);
         } else {
@@ -45,14 +46,11 @@
     public boolean test(SynapseMessage synMsg) {
         try {
             if (xpath != null) {
-                AXIOMXPath xp = new AXIOMXPath(xpath);
-                return xp.booleanValueOf(synMsg.getEnvelope());
+                return xpath.booleanValueOf(synMsg.getEnvelope());
 
             } else if (source != null && regex != null) {
-                Pattern pattern = Pattern.compile(regex);
-                AXIOMXPath xp = new AXIOMXPath(source);
-                Object result = xp.evaluate(synMsg.getEnvelope());
-                return pattern.matcher(result.toString()).matches();
+                Object result = source.evaluate(synMsg.getEnvelope());
+                return regex.matcher(result.toString()).matches();
 
             } else {
                 log.error("Invalid configuration specified");
@@ -66,27 +64,27 @@
     }
 
 
-    public String getSource() {
+    public AXIOMXPath getSource() {
         return source;
     }
 
-    public void setSource(String source) {
+    public void setSource(AXIOMXPath source) {
         this.source = source;
     }
 
-    public String getRegex() {
+    public Pattern getRegex() {
         return regex;
     }
 
-    public void setRegex(String regex) {
+    public void setRegex(Pattern regex) {
         this.regex = regex;
     }
 
-    public String getXpath() {
+    public AXIOMXPath getXpath() {
         return xpath;
     }
 
-    public void setXpath(String xpath) {
+    public void setXpath(AXIOMXPath xpath) {
         this.xpath = xpath;
     }
 

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=399252&r1=399251&r2=399252&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 Wed May  3 03:58:21 2006
@@ -18,10 +18,9 @@
 
 import org.apache.axiom.om.OMAbstractFactory;
 import org.apache.axiom.om.OMDocument;
-import org.apache.axiom.soap.SOAP12Constants;
-import org.apache.axiom.soap.SOAPEnvelope;
-import org.apache.axiom.soap.SOAPFactory;
+import org.apache.axiom.soap.*;
 import org.apache.axis2.addressing.EndpointReference;
+import org.apache.axis2.AxisFault;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.synapse.SynapseException;
@@ -37,55 +36,80 @@
 
     private Log log = LogFactory.getLog(getClass());
 
-    private QName faultCode;
-    private String reason;
+    public static final int SOAP11 = 1;
+    public static final int SOAP12 = 2;
+
+    private int soapVersion;
 
-    public boolean mediate(SynapseMessage smc) {
-        log.debug("process");
+    private QName code;
+    private String reason;
+    //TODO support SOAP 1.2 fault stuff..
+    //Node, Role, detail etc
 
-        SOAPEnvelope envelop = smc.getEnvelope();
+    public boolean mediate(SynapseMessage synMsg) {
+        log.debug(getType() + " mediate()");
+        SOAPEnvelope envelop = synMsg.getEnvelope();
         SOAPFactory factory;
-        if (envelop != null) {
-            if (envelop.getNamespace().getName().equals(
-                SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI)) {
-                factory = OMAbstractFactory.getSOAP12Factory();
-            } else {
+
+        switch (soapVersion) {
+            case SOAP11:
                 factory = OMAbstractFactory.getSOAP11Factory();
+                break;
+            case SOAP12:
+                factory = OMAbstractFactory.getSOAP12Factory();
+                break;
+            default : {
+                if (envelop != null) {
+                    if (envelop.getNamespace().getName().equals(
+                        SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI)) {
+                        factory = OMAbstractFactory.getSOAP12Factory();
+                    } else {
+                        factory = OMAbstractFactory.getSOAP11Factory();
+                    }
+                } else {
+                    factory = OMAbstractFactory.getSOAP11Factory();
+                }
             }
+        }
 
+        // TODO : Figure out how to easily gen the correct fault
+        // Replace this
+        OMDocument soapFaultDocument = factory.createOMDocument();
+        SOAPEnvelope faultEnvelope   = factory.getDefaultFaultEnvelope();
+        //SOAPFault fault = factory.createSOAPFault();
+        //faultEnvelope.setFirstChild(fault);
+        soapFaultDocument.addChild(faultEnvelope);
+
+        // set the fault message to the "faultTo" of the original message if it exists
+        // else to the "replyTo"
+        EndpointReference toEPR = synMsg.getTo();
+        EndpointReference faultToEPR = synMsg.getFaultTo();
+        if (faultToEPR != null) {
+            synMsg.setTo(faultToEPR);
+            synMsg.setReplyTo(toEPR);
         } else {
-            factory = OMAbstractFactory.getSOAP11Factory();
+            EndpointReference replyToEPR = synMsg.getReplyTo();
+            synMsg.setTo(replyToEPR);
+            synMsg.setReplyTo(toEPR);
         }
-        try {
-            // TODO : Figure out how to easily gen the correct fault
+        synMsg.setResponse(true);
 
-            // Replace this
-            OMDocument soapFaultDocument = factory.createOMDocument();
-            SOAPEnvelope faultEnvelope = factory.getDefaultFaultEnvelope();
-            soapFaultDocument.addChild(faultEnvelope);
-
-            smc.setEnvelope(faultEnvelope);
-        } catch (Exception e) {
-            throw new SynapseException(e);
+        try {
+            synMsg.setEnvelope(faultEnvelope);
+        } catch (AxisFault af) {
+            String msg = "Error replacing SOAP envelope with a fault envelope " + af.getMessage();
+            log.error(msg);
+            throw new SynapseException(af);
         }
-        smc.setResponse(true);
-
-        // Flipping the headers
-        EndpointReference tempEPR = smc.getTo();
-        smc.setTo(smc.getReplyTo());
-        smc.setReplyTo(tempEPR);
-
-        smc.getSynapseEnvironment().injectMessage(smc);
-
-        return false;
+        return true;
     }
 
-    public QName getFaultCode() {
-        return faultCode;
+    public QName getCode() {
+        return code;
     }
 
-    public void setFaultCode(QName faultCode) {
-        this.faultCode = faultCode;
+    public void setCode(QName code) {
+        this.code = code;
     }
 
     public String getReason() {
@@ -95,4 +119,14 @@
     public void setReason(String reason) {
         this.reason = reason;
     }
+
+    public int getSoapVersion() {
+        return soapVersion;
+    }
+
+    public void setSoapVersion(int soapVersion) {
+        this.soapVersion = soapVersion;
+    }
+
+
 }

Modified: 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/XSLTMediator.java?rev=399252&r1=399251&r2=399252&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/XSLTMediator.java Wed May  3 03:58:21 2006
@@ -32,7 +32,7 @@
     private String source = null;
 
     public boolean mediate(SynapseMessage synMsg) {
-
+        log.debug(getType() + " mediate()");
         if (xsltUrl != null) {
             performXLST(synMsg);
             return true;



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