synapse-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From asan...@apache.org
Subject svn commit: r609631 - /webservices/synapse/branches/1.1.1/modules/core/src/main/java/org/apache/synapse/mediators/transform/XSLTMediator.java
Date Mon, 07 Jan 2008 15:10:31 GMT
Author: asankha
Date: Mon Jan  7 07:10:24 2008
New Revision: 609631

URL: http://svn.apache.org/viewvc?rev=609631&view=rev
Log:
Fix SYNAPSE-187 and SYNAPSE-191

Modified:
    webservices/synapse/branches/1.1.1/modules/core/src/main/java/org/apache/synapse/mediators/transform/XSLTMediator.java

Modified: webservices/synapse/branches/1.1.1/modules/core/src/main/java/org/apache/synapse/mediators/transform/XSLTMediator.java
URL: http://svn.apache.org/viewvc/webservices/synapse/branches/1.1.1/modules/core/src/main/java/org/apache/synapse/mediators/transform/XSLTMediator.java?rev=609631&r1=609630&r2=609631&view=diff
==============================================================================
--- webservices/synapse/branches/1.1.1/modules/core/src/main/java/org/apache/synapse/mediators/transform/XSLTMediator.java
(original)
+++ webservices/synapse/branches/1.1.1/modules/core/src/main/java/org/apache/synapse/mediators/transform/XSLTMediator.java
Mon Jan  7 07:10:24 2008
@@ -29,9 +29,13 @@
 import org.apache.axiom.om.impl.llom.OMSourcedElementImpl;
 import org.apache.axiom.om.impl.llom.OMTextImpl;
 import org.apache.axiom.om.util.ElementHelper;
+import org.apache.axiom.om.util.StAXUtils;
 import org.apache.axiom.om.xpath.AXIOMXPath;
 import org.apache.axiom.soap.SOAP11Constants;
 import org.apache.axiom.soap.SOAP12Constants;
+import org.apache.axiom.soap.SOAPConstants;
+import org.apache.axiom.soap.SOAPEnvelope;
+import org.apache.axiom.soap.impl.builder.StAXSOAPModelBuilder;
 import org.apache.synapse.MessageContext;
 import org.apache.synapse.SynapseException;
 import org.apache.synapse.config.Entry;
@@ -42,6 +46,7 @@
 import org.apache.synapse.transport.base.BaseConstants;
 import org.apache.synapse.util.FixedByteArrayOutputStream;
 import org.apache.synapse.util.TextFileDataSource;
+import org.apache.axis2.AxisFault;
 import org.jaxen.JaxenException;
 import org.w3c.dom.Element;
 import org.w3c.dom.Node;
@@ -51,6 +56,7 @@
 import javax.xml.stream.XMLOutputFactory;
 import javax.xml.stream.XMLStreamException;
 import javax.xml.stream.XMLStreamWriter;
+import javax.xml.stream.XMLStreamReader;
 import javax.xml.transform.*;
 import javax.xml.transform.dom.DOMResult;
 import javax.xml.transform.dom.DOMSource;
@@ -59,6 +65,7 @@
 import java.io.*;
 import java.util.ArrayList;
 import java.util.List;
+import java.util.Iterator;
 
 /**
  * The XSLT mediator performs an XSLT transformation requested, using
@@ -209,6 +216,8 @@
         ByteArrayOutputStream baosForTarget = new FixedByteArrayOutputStream(BYTE_ARRAY_SIZE);
         File tempTargetFile = null;
         File tempSourceFile = null;
+        boolean isSoapEnvelope = (sourceNode == synCtx.getEnvelope());
+        boolean isSoapBody = (sourceNode == synCtx.getEnvelope().getBody());
 
         if (traceOrDebugOn) {
             trace.trace("Transformation source : " + sourceNode.toString());
@@ -396,8 +405,13 @@
                 // if we used a temporary file for the output of the transformation, read
from it
                 if (tempTargetFile != null) {
                     try {
-                        StAXOMBuilder builder = new StAXOMBuilder(new FileInputStream(tempTargetFile));
-                        result = builder.getDocumentElement();
+                        XMLStreamReader reader = StAXUtils.createXMLStreamReader(
+                            new FileInputStream(tempTargetFile));
+                        if (isSoapEnvelope) {
+                            result = new StAXSOAPModelBuilder(reader).getSOAPEnvelope();
+                        } else {
+                            result = new StAXOMBuilder(reader).getDocumentElement();
+                        }                        
 
                     } catch (XMLStreamException e) {
                         handleException(
@@ -416,9 +430,13 @@
                 } else {
                     // read the Fixed byte array stream
                     try {
-                        StAXOMBuilder builder = new StAXOMBuilder(
+                        XMLStreamReader reader = StAXUtils.createXMLStreamReader(
                             new ByteArrayInputStream(baosForTarget.toByteArray()));
-                        result = builder.getDocumentElement();
+                        if (isSoapEnvelope) {
+                            result = new StAXSOAPModelBuilder(reader).getSOAPEnvelope();
+                        } else {
+                            result = new StAXOMBuilder(reader).getDocumentElement();
+                        }
 
                     } catch (XMLStreamException e) {
                         handleException(
@@ -450,11 +468,34 @@
                 synCtx.setProperty(targetPropertyName, result);
             } else {
                 if (traceOrDebugOn) {
-                    traceOrDebug(traceOn, "Replace source node with result");
+                    traceOrDebug(traceOn, "Replace " +
+                        (isSoapEnvelope ? "SOAP envelope" : isSoapBody ? "SOAP body" : "node")
+                        + " with result");
+                }
+
+                if (isSoapEnvelope) {
+                    try {
+                        synCtx.setEnvelope((SOAPEnvelope) result);
+                    } catch (AxisFault ex) {
+                        handleException("Unable to replace SOAP envelope with result", ex,
synCtx);
+                    }
+
+                } else if (isSoapBody) {
+                    for (Iterator iter = synCtx.getEnvelope().getBody().getChildElements();
+                        iter.hasNext(); ) {
+                        OMElement child = (OMElement) iter.next();
+                        child.detach();
+                    }
+
+                    for (Iterator iter = result.getChildElements(); iter.hasNext(); ) {
+                        OMElement child = (OMElement) iter.next();
+                        synCtx.getEnvelope().getBody().addChild(child);
+                    }
+
+                } else {
+                    sourceNode.insertSiblingAfter(result);
+                    sourceNode.detach();
                 }
-                // replace the sourceNode with the result.
-                sourceNode.insertSiblingAfter(result);
-                sourceNode.detach();
             }
 
         } catch (TransformerException 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