Author: asankha
Date: Wed Oct 31 02:26:38 2007
New Revision: 590603
URL: http://svn.apache.org/viewvc?rev=590603&view=rev
Log:
fix https://issues.apache.org/jira/browse/SYNAPSE-167 where XSLT mediator could
run out of memory when dealing with very large requests/responses
Added:
webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/util/FixedByteArrayOutputStream.java
webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/util/TextFileDataSource.java
webservices/synapse/trunk/java/repository/conf/sample/resources/transform/message.xml
(with props)
webservices/synapse/trunk/java/repository/conf/sample/resources/transform/small_message.xml
(with props)
webservices/synapse/trunk/java/repository/conf/sample/resources/transform/transform_load.xml
(with props)
webservices/synapse/trunk/java/repository/conf/sample/resources/transform/transform_load_2.xml
(with props)
webservices/synapse/trunk/java/repository/conf/sample/resources/transform/transform_load_3.xml
(with props)
Modified:
webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/transform/XSLTMediator.java
webservices/synapse/trunk/java/modules/core/src/test/java/org/apache/synapse/registry/url/SimpleURLRegistryTest.java
webservices/synapse/trunk/java/modules/extensions/src/test/java/org/apache/synapse/mediators/TestUtils.java
webservices/synapse/trunk/java/modules/extensions/src/test/java/org/apache/synapse/mediators/transform/XSLTMediatorTest.java
webservices/synapse/trunk/java/modules/transports/src/main/java/org/apache/synapse/transport/vfs/VFSTransportSender.java
webservices/synapse/trunk/java/pom.xml
Modified:
webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/transform/XSLTMediator.java
URL:
http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/transform/XSLTMediator.java?rev=590603&r1=590602&r2=590603&view=diff
==============================================================================
---
webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/transform/XSLTMediator.java
(original)
+++
webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/transform/XSLTMediator.java
Wed Oct 31 02:26:38 2007
@@ -27,12 +27,15 @@
import org.apache.axiom.om.impl.dom.DOOMAbstractFactory;
import org.apache.axiom.om.impl.dom.jaxp.DocumentBuilderFactoryImpl;
import org.apache.axiom.om.impl.llom.OMTextImpl;
+import org.apache.axiom.om.impl.llom.OMSourcedElementImpl;
import org.apache.axiom.om.util.ElementHelper;
import org.apache.axiom.om.xpath.AXIOMXPath;
import org.apache.axiom.soap.SOAP11Constants;
import org.apache.axiom.soap.SOAP12Constants;
import org.apache.synapse.MessageContext;
import org.apache.synapse.SynapseException;
+import org.apache.synapse.util.FixedByteArrayOutputStream;
+import org.apache.synapse.util.TextFileDataSource;
import org.apache.synapse.core.axis2.Axis2MessageContext;
import org.apache.synapse.config.Entry;
import org.apache.synapse.config.SynapseConfigUtils;
@@ -52,8 +55,10 @@
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
+import javax.xml.namespace.QName;
+import javax.activation.FileDataSource;
+import javax.activation.DataHandler;
+import java.io.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
@@ -69,9 +74,15 @@
* "http://ws.apache.org/ns/synapse/transform/feature/dom" for the Transformer
Factory, which
* is used to decide between using DOM and Streams during the transformation
process. By default
* this is turned on as an optimization, but should be set to false if issues
are detected
+ *
+ * Note: Set the TransformerFactory system property to generate and use
translets
+ *
-Djavax.xml.transform.TransformerFactory=org.apache.xalan.xsltc.trax.TransformerFactoryImpl
+ *
*/
public class XSLTMediator extends AbstractMediator {
+ /** Maximum size of a byte array stream attempted in-memory before file
serialization is used */
+ private static final int BYTE_ARRAY_SIZE = 8192;
/**
* The feature for which deciding swiching between DOM and Stream during
the
* transformation process
@@ -130,16 +141,6 @@
public static final String DEFAULT_XPATH =
"s11:Body/child::*[position()=1] | " +
"s12:Body/child::*[position()=1]";
- static {
- // Set the TransformerFactory system property to generate and use
translets.
- // Note: To make this sample more flexible, need to load properties
from a properties file.
- String key = "javax.xml.transform.TransformerFactory";
- String value = "org.apache.xalan.xsltc.trax.TransformerFactoryImpl";
- Properties props = System.getProperties();
- props.put(key, value);
- System.setProperties(props);
- }
-
public XSLTMediator() {
// create the default XPath
try {
@@ -175,7 +176,6 @@
try {
performXLST(synCtx, traceOrDebugOn, traceOn);
- return true;
} catch (Exception e) {
handleException("Unable to perform XSLT transformation using : " +
xsltKey +
@@ -189,7 +189,7 @@
traceOrDebug(traceOn, "End : XSLT mediator");
}
- return false;
+ return true;
}
/**
@@ -202,7 +202,11 @@
boolean reCreate = false;
OMNode sourceNode = getTransformSource(synCtx);
- ByteArrayOutputStream baosForTarget = null;
+ OutputStream osForTarget = null;
+ InputStream isForSource = null;
+ ByteArrayOutputStream baosForTarget = new
FixedByteArrayOutputStream(BYTE_ARRAY_SIZE);
+ File tempTargetFile = null;
+ File tempSourceFile = null;
if (traceOrDebugOn) {
trace.trace("Transformation source : " + sourceNode.toString());
@@ -236,22 +240,53 @@
traceOrDebug(traceOn, "Using byte array serialization for
transformation");
}
- baosForTarget = new ByteArrayOutputStream();
try {
// create a byte array output stream and serialize the source
node into it
- ByteArrayOutputStream baosForSource = new
ByteArrayOutputStream();
+ ByteArrayOutputStream baosForSource = new
FixedByteArrayOutputStream(BYTE_ARRAY_SIZE);
XMLStreamWriter xsWriterForSource =
XMLOutputFactory.newInstance().
createXMLStreamWriter(baosForSource);
sourceNode.serialize(xsWriterForSource);
- transformSrc = new StreamSource(
- new ByteArrayInputStream(baosForSource.toByteArray()));
-
- // create a new Stream result over a new BAOS..
+ isForSource = new
ByteArrayInputStream(baosForSource.toByteArray());
+ transformSrc = new StreamSource(isForSource);
transformTgt = new StreamResult(baosForTarget);
} catch (XMLStreamException e) {
handleException("Error creating a StreamResult for the
transformation", e, synCtx);
+
+ } catch (SynapseException x) {
+
+ if (traceOrDebugOn) {
+ traceOrDebug(traceOn, "Error creating a StreamResult using
a byte array" +
+ " - attempting using temporary files for
serialization");
+ }
+
+ OutputStream osForSource = null;
+
+ try {
+ // create a output stream and serialize the source node
into it
+ tempSourceFile = File.createTempFile("xs_", ".xml");
+ tempTargetFile = File.createTempFile("xt_", ".xml");
+
+ osForSource = new FileOutputStream(tempSourceFile);
+ osForTarget = new FileOutputStream(tempTargetFile);
+
+ XMLStreamWriter xsWriterForSource =
+
XMLOutputFactory.newInstance().createXMLStreamWriter(osForSource);
+
+ sourceNode.serialize(xsWriterForSource);
+ transformSrc = new StreamSource(tempSourceFile);
+ transformTgt = new StreamResult(osForTarget);
+
+ } catch (XMLStreamException e) {
+ handleException("Error creating a StreamResult for the
transformation", e, synCtx);
+ } catch (IOException e) {
+ handleException("Error using a temporary file/s for the
transformation", e, synCtx);
+ } finally {
+ try {
+ osForSource.close();
+ } catch (IOException ignore) {}
+ }
}
}
@@ -302,11 +337,37 @@
}
}
- transformer.transform(transformSrc, transformTgt);
+ try {
+ transformer.transform(transformSrc, transformTgt);
+
+ } catch (TransformerException x) {
+ // did we exceed the in-memory BYTE_ARRAY_SIZE? if so, use a
file for output
+ try {
+ tempTargetFile = File.createTempFile("xt_", ".xml");
+ osForTarget = new FileOutputStream(tempTargetFile);
+ transformTgt = new StreamResult(osForTarget);
+
+ // retry transformation again
+ isForSource.reset();
+ transformer.reset();
+ transformer.transform(transformSrc, transformTgt);
+
+ } catch (IOException e) {
+ handleException("Error using a temporary file/s for the
transformation", e, synCtx);
+ }
+ }
+
if (traceOrDebugOn) {
traceOrDebug(traceOn, "Transformation completed - processing
result");
}
+ if (tempSourceFile != null) {
+ boolean deleted = tempSourceFile.delete();
+ if (!deleted) {
+ tempSourceFile.deleteOnExit();
+ }
+ }
+
// get the result OMElement
OMElement result = null;
if (transformTgt instanceof DOMResult) {
@@ -330,17 +391,40 @@
} else {
- try {
- StAXOMBuilder builder = new StAXOMBuilder(
- new ByteArrayInputStream(baosForTarget.toByteArray()));
- result = builder.getDocumentElement();
+ // 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();
+
+ } catch (XMLStreamException e) {
+ handleException(
+ "Error building result element from XSLT
transformation", e, synCtx);
+
+ } catch (Exception e) {
+ result = handleNonXMLResult(tempTargetFile,
traceOrDebugOn, traceOn);
+
+ } finally {
+ boolean deleted = tempTargetFile.delete();
+ if (!deleted) {
+ tempTargetFile.deleteOnExit();
+ }
+ }
- } catch (XMLStreamException e) {
- handleException(
- "Error building result element from XSLT
transformation", e, synCtx);
+ } else {
+ // read the Fixed byte array stream
+ try {
+ StAXOMBuilder builder = new StAXOMBuilder(
+ new
ByteArrayInputStream(baosForTarget.toByteArray()));
+ result = builder.getDocumentElement();
+
+ } catch (XMLStreamException e) {
+ handleException(
+ "Error building result element from XSLT
transformation", e, synCtx);
- } catch (Exception e) {
- result = handleNonXMLResult(baosForTarget.toString(),
traceOrDebugOn, traceOn);
+ } catch (Exception e) {
+ result = handleNonXMLResult(baosForTarget.toString(),
traceOrDebugOn, traceOn);
+ }
}
}
@@ -439,6 +523,34 @@
log.error(msg, e);
throw new SynapseException(msg, e);
}
+ }
+
+ /**
+ * If the transformation results in a non-XML payload, use standard
wrapper elements
+ * to wrap the text payload so that other mediators could still process
the result
+ * @param file the text payload file
+ * @param traceOrDebugOn is tracing on debug logging on?
+ * @param traceOn is tracing on?
+ * @return an OMElement wrapping the text payload
+ */
+ private OMElement handleNonXMLResult(File file, boolean traceOrDebugOn,
boolean traceOn) {
+
+ OMFactory fac = OMAbstractFactory.getOMFactory();
+ OMElement wrapper = null;
+
+ if (traceOrDebugOn) {
+ traceOrDebug(traceOn, "Processing non SOAP/XML (text)
transformation result");
+ }
+ if (traceOn && trace.isTraceEnabled()) {
+ trace.trace("Wrapping text transformation result from : " + file);
+ }
+
+ if (file != null) {
+ TextFileDataSource txtFileDS = new TextFileDataSource(new
FileDataSource(file));
+ wrapper = new
OMSourcedElementImpl(BaseConstants.DEFAULT_TEXT_WRAPPER, fac, txtFileDS);
+ }
+
+ return wrapper;
}
/**
Added:
webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/util/FixedByteArrayOutputStream.java
URL:
http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/util/FixedByteArrayOutputStream.java?rev=590603&view=auto
==============================================================================
---
webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/util/FixedByteArrayOutputStream.java
(added)
+++
webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/util/FixedByteArrayOutputStream.java
Wed Oct 31 02:26:38 2007
@@ -0,0 +1,44 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.util;
+
+import org.apache.synapse.SynapseException;
+import java.io.ByteArrayOutputStream;
+
+public class FixedByteArrayOutputStream extends ByteArrayOutputStream {
+
+ public FixedByteArrayOutputStream(int size) {
+ super(size);
+ }
+
+ public synchronized void write(int b) {
+ if (count+1 > buf.length) {
+ throw new SynapseException("Fixed size of internal byte array
exceeded");
+ }
+ super.write(b);
+ }
+
+ public synchronized void write(byte b[], int off, int len) {
+ if (count+len > buf.length) {
+ throw new SynapseException("Fixed size of internal byte array
exceeded");
+ }
+ super.write(b, off, len);
+ }
+}
Added:
webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/util/TextFileDataSource.java
URL:
http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/util/TextFileDataSource.java?rev=590603&view=auto
==============================================================================
---
webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/util/TextFileDataSource.java
(added)
+++
webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/util/TextFileDataSource.java
Wed Oct 31 02:26:38 2007
@@ -0,0 +1,150 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.util;
+
+import org.apache.axiom.om.OMDataSource;
+import org.apache.axiom.om.OMOutputFormat;
+import org.apache.axiom.om.OMFactory;
+import org.apache.axiom.om.OMAbstractFactory;
+import org.apache.axiom.om.impl.llom.OMSourcedElementImpl;
+import org.apache.axiom.om.impl.serialize.StreamingOMSerializer;
+import org.apache.axiom.om.util.StAXUtils;
+import org.apache.synapse.SynapseException;
+import org.apache.synapse.transport.base.BaseConstants;
+
+import javax.activation.DataSource;
+import javax.activation.FileDataSource;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+import javax.xml.stream.XMLStreamWriter;
+import java.io.*;
+
+public class TextFileDataSource implements OMDataSource {
+
+ private static final byte[] prefix =
+ "<text xmlns=\"http://ws.apache.org/commons/ns/payload\">".getBytes();
+ private static final byte[] suffix = "</text>".getBytes();
+ private static final byte[] empty =
+ "<text xmlns=\"http://ws.apache.org/commons/ns/payload\"/>".getBytes();
+ private InputStream is = null;
+ private int i = 0, j = 0;
+
+ public TextFileDataSource(DataSource ds) {
+ try {
+ this.is = ds.getInputStream();
+ } catch (IOException e) {
+ throw new SynapseException(
+ "Unable to get an InputStream for DataSource : " +
ds.getName(), e);
+ }
+ }
+
+ public void serialize(OutputStream out, OMOutputFormat format) throws
XMLStreamException {
+ try {
+ //out.write(prefix);
+ // Transfer bytes from is to out
+ byte[] buf = new byte[4096];
+ int len;
+ while ((len = is.read(buf)) > 0) {
+ out.write(buf, 0, len);
+ }
+ //out.write(suffix);
+ } catch (IOException e) {
+ throw new SynapseException("Error serializing TextFileDataSource
to an OutputStream", e);
+ }
+ }
+
+ public void serialize(Writer writer, OMOutputFormat format) throws
XMLStreamException {
+ try {
+ writer.write(new String(empty));
+ } catch (IOException e) {
+ throw new XMLStreamException(e);
+ }
+ }
+
+ public void serialize(XMLStreamWriter xmlWriter) throws XMLStreamException
{
+ StreamingOMSerializer serializer = new StreamingOMSerializer();
+ serializer.serialize(getReader(), xmlWriter);
+ }
+
+ public XMLStreamReader getReader() throws XMLStreamException {
+ return StAXUtils.createXMLStreamReader(getInputStream());
+ }
+
+ private InputStream getInputStream() {
+
+ return new InputStream() {
+
+ public int read(byte b[]) throws IOException {
+ return read(b, 0, b.length);
+ }
+
+ public int read(byte b[], int off, int len) throws IOException {
+ int pos = off;
+ if (i < prefix.length) {
+ while (i < prefix.length && pos-off < len) {
+ b[pos++] = prefix[i++];
+ }
+ return pos - off;
+ }
+
+ int ret = is.read(b, pos, len-pos);
+
+ if (ret == -1 && j < suffix.length) {
+ while (j < suffix.length && pos-off < len) {
+ b[pos++] = suffix[j++];
+ }
+ return pos - off;
+ }
+
+ return ret;
+ }
+
+ public int read() throws IOException {
+ if (i < prefix.length) {
+ while (i < prefix.length) {
+ return prefix[i++];
+ }
+ }
+ int ret = is.read();
+
+ if (ret == -1 && j < suffix.length) {
+ while (j < suffix.length) {
+ return suffix[j++];
+ }
+ }
+ return ret;
+ }
+ };
+ }
+
+ public static void main(String[] args) throws Exception {
+ TextFileDataSource textFileDataSource = new TextFileDataSource(
+ // new File("/tmp/test.txt"));
+ new
FileDataSource("/home/asankha/code/synapse/repository/conf/sample/resources/transform/message.xml"));
+
+ OMFactory fac = OMAbstractFactory.getOMFactory();
+ OMSourcedElementImpl element =
+ new OMSourcedElementImpl(
+ BaseConstants.DEFAULT_TEXT_WRAPPER, fac, textFileDataSource);
+ element.serializeAndConsume(new FileOutputStream("/tmp/out.txt"));
+ element.serialize(System.out);
+ //element.serializeAndConsume(System.out);
+ }
+}
Modified:
webservices/synapse/trunk/java/modules/core/src/test/java/org/apache/synapse/registry/url/SimpleURLRegistryTest.java
URL:
http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/core/src/test/java/org/apache/synapse/registry/url/SimpleURLRegistryTest.java?rev=590603&r1=590602&r2=590603&view=diff
==============================================================================
---
webservices/synapse/trunk/java/modules/core/src/test/java/org/apache/synapse/registry/url/SimpleURLRegistryTest.java
(original)
+++
webservices/synapse/trunk/java/modules/core/src/test/java/org/apache/synapse/registry/url/SimpleURLRegistryTest.java
Wed Oct 31 02:26:38 2007
@@ -64,8 +64,8 @@
// still cached content should be available and valid
assertEquals(TEXT_1, reg.getResource(prop).toString());
- // now sleep 1 sec, still cache should be valid
- Thread.sleep(1000);
+ // now sleep ~1 sec, still cache should be valid
+ Thread.sleep(800);
assertEquals(TEXT_1, reg.getResource(prop).toString());
// sleep another 1 sec.. cache should expire and new content should be
loaded
Modified:
webservices/synapse/trunk/java/modules/extensions/src/test/java/org/apache/synapse/mediators/TestUtils.java
URL:
http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/extensions/src/test/java/org/apache/synapse/mediators/TestUtils.java?rev=590603&r1=590602&r2=590603&view=diff
==============================================================================
---
webservices/synapse/trunk/java/modules/extensions/src/test/java/org/apache/synapse/mediators/TestUtils.java
(original)
+++
webservices/synapse/trunk/java/modules/extensions/src/test/java/org/apache/synapse/mediators/TestUtils.java
Wed Oct 31 02:26:38 2007
@@ -142,6 +142,40 @@
return synCtx;
}
+ public static TestMessageContext
getTestContextForXSLTMediatorUsingFile(String path, Map props) throws Exception
{
+
+ // create a test synapse context
+ TestMessageContext synCtx = new TestMessageContext();
+ SynapseConfiguration testConfig = new SynapseConfiguration();
+ testConfig.setRegistry(new SimpleURLRegistry());
+
+ if (props != null) {
+ Iterator iter = props.keySet().iterator();
+ while (iter.hasNext()) {
+ String key = (String) iter.next();
+ testConfig.addEntry(key, (Entry) props.get(key));
+ }
+ }
+ synCtx.setConfiguration(testConfig);
+
+ SOAPEnvelope envelope =
OMAbstractFactory.getSOAP11Factory().getDefaultEnvelope();
+ OMDocument omDoc =
OMAbstractFactory.getSOAP11Factory().createOMDocument();
+ omDoc.addChild(envelope);
+
+ //XMLStreamReader parser = XMLInputFactory.newInstance().
+ // createXMLStreamReader(new FileReader(path));
+ StAXOMBuilder builder = new StAXOMBuilder(path);
+
+ // set a dummy static message
+ OMFactory fac = OMAbstractFactory.getOMFactory();
+ envelope.getBody().addChild(fac.createOMText("first text child "));
+ envelope.getBody().addChild(builder.getDocumentElement());
+ envelope.getBody().addChild(fac.createOMText("second text child "));
+
+ synCtx.setEnvelope(envelope);
+ return synCtx;
+ }
+
public static TestMessageContext getTestContext(String bodyText) throws
Exception {
return getTestContext(bodyText, null);
}
Modified:
webservices/synapse/trunk/java/modules/extensions/src/test/java/org/apache/synapse/mediators/transform/XSLTMediatorTest.java
URL:
http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/extensions/src/test/java/org/apache/synapse/mediators/transform/XSLTMediatorTest.java?rev=590603&r1=590602&r2=590603&view=diff
==============================================================================
---
webservices/synapse/trunk/java/modules/extensions/src/test/java/org/apache/synapse/mediators/transform/XSLTMediatorTest.java
(original)
+++
webservices/synapse/trunk/java/modules/extensions/src/test/java/org/apache/synapse/mediators/transform/XSLTMediatorTest.java
Wed Oct 31 02:26:38 2007
@@ -20,9 +20,10 @@
package org.apache.synapse.mediators.transform;
import junit.framework.TestCase;
-import org.apache.axiom.om.OMContainer;
-import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.*;
+import org.apache.axiom.om.impl.builder.StAXOMBuilder;
import org.apache.axiom.om.xpath.AXIOMXPath;
+import org.apache.axiom.soap.SOAPEnvelope;
import org.apache.synapse.mediators.TestUtils;
import org.apache.synapse.mediators.MediatorProperty;
import org.apache.synapse.mediators.transform.XSLTMediator;
@@ -34,6 +35,7 @@
import java.util.List;
import java.util.ArrayList;
import java.net.URL;
+import java.io.FileOutputStream;
public class XSLTMediatorTest extends TestCase {
@@ -134,6 +136,76 @@
assertTrue("String".equals(symbolElem.getText()));
} else {
fail("Unexpected element found in SOAP body");
+ }
+ }
+
+ public void testTransformXSLTLargeMessagesCSV() throws Exception {
+
+ // create a new switch mediator
+ transformMediator = new XSLTMediator();
+ // set XSLT transformation URL
+ transformMediator.setXsltKey("xslt-key");
+
+ for (int i=0; i<2; i++) {
+ Map props = new HashMap();
+ Entry prop = new Entry();
+ prop.setType(Entry.URL_SRC);
+ prop.setSrc(new
URL("file:./../../repository/conf/sample/resources/transform/transform_load.xml"));
+ props.put("xslt-key", prop);
+
+ // invoke transformation, with static enveope
+ MessageContext synCtx =
TestUtils.getTestContextForXSLTMediatorUsingFile("./../../repository/conf/sample/resources/transform/message.xml",
props);
+ //MessageContext synCtx =
TestUtils.getTestContextForXSLTMediator(SOURCE, props);
+ transformMediator.mediate(synCtx);
+// synCtx.getEnvelope().serializeAndConsume(new
FileOutputStream("/tmp/out.xml"));
+// System.gc();
+// System.out.println("done : " + i + " :: " +
Runtime.getRuntime().freeMemory());
+ }
+ }
+
+ public void testTransformXSLTLargeMessagesXML() throws Exception {
+
+ // create a new switch mediator
+ transformMediator = new XSLTMediator();
+ // set XSLT transformation URL
+ transformMediator.setXsltKey("xslt-key");
+
+ for (int i=0; i<2; i++) {
+ Map props = new HashMap();
+ Entry prop = new Entry();
+ prop.setType(Entry.URL_SRC);
+ prop.setSrc(new
URL("file:./../../repository/conf/sample/resources/transform/transform_load_3.xml"));
+ props.put("xslt-key", prop);
+
+ // invoke transformation, with static enveope
+ MessageContext synCtx =
TestUtils.getTestContextForXSLTMediatorUsingFile("./../../repository/conf/sample/resources/transform/message.xml",
props);
+ //MessageContext synCtx =
TestUtils.getTestContextForXSLTMediator(SOURCE, props);
+ transformMediator.mediate(synCtx);
+// System.gc();
+// System.out.println("done : " + i + " :: " +
Runtime.getRuntime().freeMemory());
+ }
+ }
+
+
+ public void testTransformXSLTSmallMessages() throws Exception {
+
+ // create a new switch mediator
+ transformMediator = new XSLTMediator();
+ // set XSLT transformation URL
+ transformMediator.setXsltKey("xslt-key");
+
+ for (int i=0; i<5; i++) {
+ Map props = new HashMap();
+ Entry prop = new Entry();
+ prop.setType(Entry.URL_SRC);
+ prop.setSrc(new
URL("file:./../../repository/conf/sample/resources/transform/transform_load_2.xml"));
+ props.put("xslt-key", prop);
+
+ // invoke transformation, with static enveope
+ MessageContext synCtx =
TestUtils.getTestContextForXSLTMediatorUsingFile("./../../repository/conf/sample/resources/transform/small_message.xml",
props);
+ //MessageContext synCtx =
TestUtils.getTestContextForXSLTMediator(SOURCE, props);
+ transformMediator.mediate(synCtx);
+ //System.out.println("done : " + i + " :: " +
Runtime.getRuntime().freeMemory());
}
}
Modified:
webservices/synapse/trunk/java/modules/transports/src/main/java/org/apache/synapse/transport/vfs/VFSTransportSender.java
URL:
http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/transports/src/main/java/org/apache/synapse/transport/vfs/VFSTransportSender.java?rev=590603&r1=590602&r2=590603&view=diff
==============================================================================
---
webservices/synapse/trunk/java/modules/transports/src/main/java/org/apache/synapse/transport/vfs/VFSTransportSender.java
(original)
+++
webservices/synapse/trunk/java/modules/transports/src/main/java/org/apache/synapse/transport/vfs/VFSTransportSender.java
Wed Oct 31 02:26:38 2007
@@ -36,8 +36,10 @@
import org.apache.axiom.om.OMElement;
import org.apache.axiom.om.OMNode;
import org.apache.axiom.om.OMText;
+import org.apache.axiom.om.impl.llom.OMSourcedElementImpl;
import javax.activation.DataHandler;
+import javax.xml.stream.XMLStreamException;
import java.io.OutputStream;
import java.io.IOException;
import java.io.ByteArrayOutputStream;
@@ -174,12 +176,19 @@
} else if
(BaseConstants.DEFAULT_TEXT_WRAPPER.equals(firstChild.getQName())) {
try {
OutputStream os =
responseFile.getContent().getOutputStream();
- os.write(firstChild.getText().getBytes());
+
+ if (firstChild instanceof OMSourcedElementImpl) {
+ firstChild.serializeAndConsume(os);
+ } else {
+ os.write(firstChild.getText().getBytes());
+ }
} catch (FileSystemException e) {
handleException("Error getting an output stream to file :
" +
responseFile.getName().getBaseName(), e);
} catch (IOException e) {
handleException("Error getting text content of message as
bytes", e);
+ } catch (XMLStreamException e) {
+ handleException("Error serializing OMSourcedElement
content", e);
}
} else {
populateSOAPFile(responseFile, msgContext);
Modified: webservices/synapse/trunk/java/pom.xml
URL:
http://svn.apache.org/viewvc/webservices/synapse/trunk/java/pom.xml?rev=590603&r1=590602&r2=590603&view=diff
==============================================================================
--- webservices/synapse/trunk/java/pom.xml (original)
+++ webservices/synapse/trunk/java/pom.xml Wed Oct 31 02:26:38 2007
@@ -171,6 +171,9 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.3</version>
+ <configuration>
+ <argLine>-Xms128m -Xmx128m</argLine>
+ </configuration>
</plugin>
<plugin>
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]