You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@santuario.apache.org by gi...@apache.org on 2012/09/24 18:46:12 UTC
svn commit: r1389478 - in /santuario/xml-security-java/trunk: ./ src/etc/
src/main/java/org/apache/xml/security/stax/ext/
src/main/java/org/apache/xml/security/stax/impl/
src/main/java/org/apache/xml/security/stax/impl/processor/output/
src/main/java/o...
Author: giger
Date: Mon Sep 24 16:46:11 2012
New Revision: 1389478
URL: http://svn.apache.org/viewvc?rev=1389478&view=rev
Log:
SANTUARIO-346 - Create Memory + Performance tests for the stax code
+ some minor improvements
Added:
santuario/xml-security-java/trunk/src/etc/
santuario/xml-security-java/trunk/src/etc/plot.sh
- copied, changed from r1388136, webservices/wss4j/trunk/ws-security-stax/etc/plot.sh
santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/stax/performance/
santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/stax/performance/AbstractPerformanceTest.java (with props)
santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/stax/performance/PerformanceMemoryTest.java (with props)
santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/stax/performance/PerformanceTimingTest.java (with props)
Modified:
santuario/xml-security-java/trunk/pom.xml
santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/ext/AbstractBufferingOutputProcessor.java
santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/ext/XMLSecurityConstants.java
santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/InputProcessorChainImpl.java
santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/OutputProcessorChainImpl.java
santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/processor/output/AbstractEncryptOutputProcessor.java
santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/processor/output/FinalOutputProcessor.java
santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/processor/output/XMLSignatureEndingOutputProcessor.java
santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/stax/XMLSecEventBaseImpl.java
Modified: santuario/xml-security-java/trunk/pom.xml
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/pom.xml?rev=1389478&r1=1389477&r2=1389478&view=diff
==============================================================================
--- santuario/xml-security-java/trunk/pom.xml (original)
+++ santuario/xml-security-java/trunk/pom.xml Mon Sep 24 16:46:11 2012
@@ -300,6 +300,10 @@
<includes>
<include>**/*Test.java</include>
</includes>
+ <excludes>
+ <exclude>**/PerformanceMemoryTest.java</exclude>
+ <exclude>**/PerformanceTimingTest.java</exclude>
+ </excludes>
<systemPropertyVariables>
<product.version>${project.version}</product.version>
<log4j.configuration>log4j-xmlsec.xml</log4j.configuration>
@@ -379,7 +383,7 @@
<xmlunit.version>1.3</xmlunit.version>
<commons.codec.version>1.6</commons.codec.version>
<commons.compress.version>1.4.1</commons.compress.version>
- <woodstox.core.asl.version>4.1.3</woodstox.core.asl.version>
+ <woodstox.core.asl.version>4.1.4</woodstox.core.asl.version>
<jetty.version>8.1.4.v20120524</jetty.version>
</properties>
Copied: santuario/xml-security-java/trunk/src/etc/plot.sh (from r1388136, webservices/wss4j/trunk/ws-security-stax/etc/plot.sh)
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/src/etc/plot.sh?p2=santuario/xml-security-java/trunk/src/etc/plot.sh&p1=webservices/wss4j/trunk/ws-security-stax/etc/plot.sh&r1=1388136&r2=1389478&rev=1389478&view=diff
==============================================================================
--- webservices/wss4j/trunk/ws-security-stax/etc/plot.sh (original)
+++ santuario/xml-security-java/trunk/src/etc/plot.sh Mon Sep 24 16:46:11 2012
@@ -1,42 +1,7 @@
#!/bin/bash
SCRIPTDIR=$(dirname ${0})
-TARGETDIR="${SCRIPTDIR}/../target"
-
-awk '
-{
- for (i=1; i<=NF; i++) {
- a[NR,i] = $i
- }
-}
-NF>p { p = NF }
-END {
- for(j=1; j<=p; j++) {
- str=a[1,j]
- for(i=2; i<=NR; i++){
- str=str" "a[i,j];
- }
- print str
- }
-}' ${TARGETDIR}/memory-in-samples.txt > ${TARGETDIR}/memory-in-samples-transposed.txt
-
-awk '
-{
- for (i=1; i<=NF; i++) {
- a[NR,i] = $i
- }
-}
-NF>p { p = NF }
-END {
- for(j=1; j<=p; j++) {
- str=a[1,j]
- for(i=2; i<=NR; i++){
- str=str" "a[i,j];
- }
- print str
- }
-}' ${TARGETDIR}/memory-out-samples.txt > ${TARGETDIR}/memory-out-samples-transposed.txt
-
+TARGETDIR="${SCRIPTDIR}/../../target"
export GDFONTPATH=/usr/share/fonts/corefonts
@@ -45,38 +10,50 @@ gnuplot << EOF
set term png size 800,400
set key left top
set xlabel "Number of XML start elements"
-#echo 'set xdata time';
set ylabel "Time [s]"
-#echo 'set ytics (0,1)';
-#echo 'set xrange ["01.12.2009":]';
-#echo 'set timefmt "%s"';
-#echo 'set format x "%d.%m.%Y"';
set style data linespoints
-#echo 'set yrange [-0.25:1.25]';
-set output "${TARGETDIR}/timing-inbound.png"
-set title "Timing inbound (Timestamp Signature Encrypt)"
-plot "${TARGETDIR}/timing-in-samples.txt" using 1:3 title 'swssf', \
- "${TARGETDIR}/timing-in-samples.txt" using 1:4 title 'swssf-compressed', \
- "${TARGETDIR}/timing-in-samples.txt" using 1:2 title 'WSS4J'
-
-set output "${TARGETDIR}/timing-outbound.png"
-set title "Timing outbound (Timestamp Signature Encrypt)"
-plot "${TARGETDIR}/timing-out-samples.txt" using 1:3 title 'swssf', \
- "${TARGETDIR}/timing-out-samples.txt" using 1:4 title 'swssf-compressed', \
- "${TARGETDIR}/timing-out-samples.txt" using 1:2 title 'WSS4J'
+set output "${TARGETDIR}/signature-times-inbound.png"
+set title "Time needed for signature verification"
+plot "${TARGETDIR}/signatureInTimeSamples.txt" using 1:2 title 'StAX', \
+ "${TARGETDIR}/signatureInTimeSamples.txt" using 1:3 title 'DOM'
+
+set output "${TARGETDIR}/signature-times-outbound.png"
+set title "Time needed for signature creation"
+plot "${TARGETDIR}/signatureOutTimeSamples.txt" using 1:2 title 'StAX', \
+ "${TARGETDIR}/signatureOutTimeSamples.txt" using 1:3 title 'DOM'
+
+set output "${TARGETDIR}/encryption-times-inbound.png"
+set title "Time needed for decryption"
+plot "${TARGETDIR}/encryptionInTimeSamples.txt" using 1:2 title 'StAX', \
+ "${TARGETDIR}/encryptionInTimeSamples.txt" using 1:3 title 'DOM'
+
+set output "${TARGETDIR}/encryption-times-outbound.png"
+set title "Time needed for encryption"
+plot "${TARGETDIR}/encryptionOutTimeSamples.txt" using 1:2 title 'StAX', \
+ "${TARGETDIR}/encryptionOutTimeSamples.txt" using 1:3 title 'DOM'
+
set ylabel "Memory [MB]"
-set output "${TARGETDIR}/memory-inbound.png"
-set title "HEAP memory consumption inbound (Timestamp Signature Encrypt)"
-plot "${TARGETDIR}/memory-in-samples-transposed.txt" using 1:4 title 'swssf', \
- "${TARGETDIR}/memory-in-samples-transposed.txt" using 1:3 title 'swssf-compressed', \
- "${TARGETDIR}/memory-in-samples-transposed.txt" using 1:2 title 'WSS4J'
-
-set output "${TARGETDIR}/memory-outbound.png"
-set title "HEAP memory consumption outbound (Timestamp Signature Encrypt)"
-plot "${TARGETDIR}/memory-out-samples-transposed.txt" using 1:4 title 'swssf', \
- "${TARGETDIR}/memory-out-samples-transposed.txt" using 1:3 title 'swssf-compressed', \
- "${TARGETDIR}/memory-out-samples-transposed.txt" using 1:2 title 'WSS4J'
+set output "${TARGETDIR}/signature-memory-inbound.png"
+set title "HEAP memory consumption during signature verification"
+plot "${TARGETDIR}/signatureInMemorySamples.txt" using 1:2 title 'StAX', \
+ "${TARGETDIR}/signatureInMemorySamples.txt" using 1:3 title 'DOM'
+
+set output "${TARGETDIR}/signature-memory-outbound.png"
+set title "HEAP memory consumption during signature creation"
+plot "${TARGETDIR}/signatureOutMemorySamples.txt" using 1:2 title 'StAX', \
+ "${TARGETDIR}/signatureOutMemorySamples.txt" using 1:3 title 'DOM'
+
+set output "${TARGETDIR}/encryption-memory-inbound.png"
+set title "HEAP memory consumption during decryption"
+plot "${TARGETDIR}/encryptionInMemorySamples.txt" using 1:2 title 'StAX', \
+ "${TARGETDIR}/encryptionInMemorySamples.txt" using 1:3 title 'DOM'
+
+set output "${TARGETDIR}/encryption-memory-outbound.png"
+set title "HEAP memory consumption during encryption"
+plot "${TARGETDIR}/encryptionOutMemorySamples.txt" using 1:2 title 'StAX', \
+ "${TARGETDIR}/encryptionOutMemorySamples.txt" using 1:3 title 'DOM'
+
EOF
Modified: santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/ext/AbstractBufferingOutputProcessor.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/ext/AbstractBufferingOutputProcessor.java?rev=1389478&r1=1389477&r2=1389478&view=diff
==============================================================================
--- santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/ext/AbstractBufferingOutputProcessor.java (original)
+++ santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/ext/AbstractBufferingOutputProcessor.java Mon Sep 24 16:46:11 2012
@@ -69,14 +69,13 @@ public abstract class AbstractBufferingO
@Override
public void processEvent(XMLSecEvent xmlSecEvent, OutputProcessorChain outputProcessorChain)
throws XMLStreamException, XMLSecurityException {
- xmlSecEventBuffer.push(xmlSecEvent);
+ xmlSecEventBuffer.offer(xmlSecEvent);
}
@Override
public void doFinal(OutputProcessorChain outputProcessorChain) throws XMLStreamException, XMLSecurityException {
OutputProcessorChain subOutputProcessorChain = outputProcessorChain.createSubChain(this);
- final Iterator<XMLSecEvent> xmlSecEventIterator = getXmlSecEventBuffer().descendingIterator();
- flushBufferAndCallbackAfterTokenID(subOutputProcessorChain, xmlSecEventIterator);
+ flushBufferAndCallbackAfterTokenID(subOutputProcessorChain, getXmlSecEventBuffer());
//call final on the rest of the chain
subOutputProcessorChain.doFinal();
//this processor is now finished and we can remove it now
@@ -87,7 +86,7 @@ public abstract class AbstractBufferingO
throws XMLStreamException, XMLSecurityException;
protected void flushBufferAndCallbackAfterTokenID(OutputProcessorChain outputProcessorChain,
- Iterator<XMLSecEvent> xmlSecEventIterator)
+ Deque<XMLSecEvent> xmlSecEventDeque)
throws XMLStreamException, XMLSecurityException {
String appendAfterThisTokenId = getAppendAfterThisTokenId();
@@ -100,8 +99,8 @@ public abstract class AbstractBufferingO
QName matchingElementName = null;
loop:
- while (xmlSecEventIterator.hasNext()) {
- XMLSecEvent xmlSecEvent = xmlSecEventIterator.next();
+ while (!xmlSecEventDeque.isEmpty()) {
+ XMLSecEvent xmlSecEvent = xmlSecEventDeque.pop();
outputProcessorChain.reset();
outputProcessorChain.processEvent(xmlSecEvent);
@@ -127,8 +126,8 @@ public abstract class AbstractBufferingO
//we found the token and...
int level = 0;
loop:
- while (xmlSecEventIterator.hasNext()) {
- XMLSecEvent xmlSecEvent = xmlSecEventIterator.next();
+ while (!xmlSecEventDeque.isEmpty()) {
+ XMLSecEvent xmlSecEvent = xmlSecEventDeque.pop();
outputProcessorChain.reset();
outputProcessorChain.processEvent(xmlSecEvent);
@@ -151,8 +150,8 @@ public abstract class AbstractBufferingO
}
//loop through the rest of the document
- while (xmlSecEventIterator.hasNext()) {
- XMLSecEvent xmlSecEvent = xmlSecEventIterator.next();
+ while (!xmlSecEventDeque.isEmpty()) {
+ XMLSecEvent xmlSecEvent = xmlSecEventDeque.pop();
outputProcessorChain.reset();
outputProcessorChain.processEvent(xmlSecEvent);
}
Modified: santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/ext/XMLSecurityConstants.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/ext/XMLSecurityConstants.java?rev=1389478&r1=1389477&r2=1389478&view=diff
==============================================================================
--- santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/ext/XMLSecurityConstants.java (original)
+++ santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/ext/XMLSecurityConstants.java Mon Sep 24 16:46:11 2012
@@ -30,6 +30,7 @@ import javax.xml.bind.Unmarshaller;
import javax.xml.datatype.DatatypeConfigurationException;
import javax.xml.datatype.DatatypeFactory;
import javax.xml.namespace.QName;
+import javax.xml.stream.XMLOutputFactory;
import javax.xml.transform.Source;
import javax.xml.transform.stream.StreamSource;
import javax.xml.validation.Schema;
@@ -50,6 +51,7 @@ public class XMLSecurityConstants {
private static Schema schema;
public static final DatatypeFactory datatypeFactory;
+ public static final XMLOutputFactory xmlOutputFactory;
static {
try {
@@ -64,6 +66,9 @@ public class XMLSecurityConstants {
throw new RuntimeException(e);
}
+ xmlOutputFactory = XMLOutputFactory.newInstance();
+ xmlOutputFactory.setProperty(XMLOutputFactory.IS_REPAIRING_NAMESPACES, false);
+
try {
setJaxbContext(
JAXBContext.newInstance(
Modified: santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/InputProcessorChainImpl.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/InputProcessorChainImpl.java?rev=1389478&r1=1389477&r2=1389478&view=diff
==============================================================================
--- santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/InputProcessorChainImpl.java (original)
+++ santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/InputProcessorChainImpl.java Mon Sep 24 16:46:11 2012
@@ -39,7 +39,7 @@ public class InputProcessorChainImpl imp
protected static final transient Log log = LogFactory.getLog(InputProcessorChainImpl.class);
protected static final transient boolean isDebugEnabled = log.isDebugEnabled();
- private List<InputProcessor> inputProcessors = Collections.synchronizedList(new ArrayList<InputProcessor>(20));//the default of ten entries is not enough
+ private List<InputProcessor> inputProcessors;
private int startPos = 0;
private int curPos = 0;
@@ -51,17 +51,19 @@ public class InputProcessorChainImpl imp
}
public InputProcessorChainImpl(SecurityContext securityContext, int startPos) {
- this(securityContext, new DocumentContextImpl(), startPos);
+ this(securityContext, new DocumentContextImpl(), startPos, new ArrayList<InputProcessor>(20));
}
public InputProcessorChainImpl(SecurityContext securityContext, DocumentContextImpl documentContext) {
- this(securityContext, documentContext, 0);
+ this(securityContext, documentContext, 0, new ArrayList<InputProcessor>(20));
}
- protected InputProcessorChainImpl(SecurityContext securityContext, DocumentContextImpl documentContextImpl, int startPos) {
+ protected InputProcessorChainImpl(SecurityContext securityContext, DocumentContextImpl documentContextImpl,
+ int startPos, List<InputProcessor> inputProcessors) {
this.securityContext = securityContext;
this.curPos = this.startPos = startPos;
- documentContext = documentContextImpl;
+ this.documentContext = documentContextImpl;
+ this.inputProcessors = Collections.synchronizedList(inputProcessors);
}
public void reset() {
@@ -76,10 +78,6 @@ public class InputProcessorChainImpl imp
return this.documentContext;
}
- private void setInputProcessors(List<InputProcessor> inputProcessors) {
- this.inputProcessors = inputProcessors;
- }
-
public void addProcessor(InputProcessor newInputProcessor) {
int startPhaseIdx = 0;
int endPhaseIdx = inputProcessors.size();
@@ -195,11 +193,10 @@ public class InputProcessorChainImpl imp
InputProcessorChainImpl inputProcessorChain;
try {
inputProcessorChain = new InputProcessorChainImpl(securityContext, documentContext.clone(),
- inputProcessors.indexOf(inputProcessor) + 1);
+ inputProcessors.indexOf(inputProcessor) + 1, new ArrayList<InputProcessor>(this.inputProcessors));
} catch (CloneNotSupportedException e) {
throw new XMLSecurityException(XMLSecurityException.ErrorCode.FAILURE, e);
}
- inputProcessorChain.setInputProcessors(new ArrayList<InputProcessor>(this.inputProcessors));
return inputProcessorChain;
}
}
Modified: santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/OutputProcessorChainImpl.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/OutputProcessorChainImpl.java?rev=1389478&r1=1389477&r2=1389478&view=diff
==============================================================================
--- santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/OutputProcessorChainImpl.java (original)
+++ santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/OutputProcessorChainImpl.java Mon Sep 24 16:46:11 2012
@@ -40,7 +40,7 @@ public class OutputProcessorChainImpl im
protected static final transient Log log = LogFactory.getLog(OutputProcessorChainImpl.class);
protected static final transient boolean isDebugEnabled = log.isDebugEnabled();
- private List<OutputProcessor> outputProcessors = new ArrayList<OutputProcessor>(20); //the default of ten entries is not enough
+ private List<OutputProcessor> outputProcessors;
private int startPos = 0;
private int curPos = 0;
private XMLSecStartElement parentXmlSecStartElement;
@@ -53,17 +53,19 @@ public class OutputProcessorChainImpl im
}
public OutputProcessorChainImpl(SecurityContext securityContext, int startPos) {
- this(securityContext, new DocumentContextImpl(), startPos);
+ this(securityContext, new DocumentContextImpl(), startPos, new ArrayList<OutputProcessor>(20));
}
public OutputProcessorChainImpl(SecurityContext securityContext, DocumentContextImpl documentContext) {
- this(securityContext, documentContext, 0);
+ this(securityContext, documentContext, 0, new ArrayList<OutputProcessor>(20));
}
- protected OutputProcessorChainImpl(SecurityContext securityContext, DocumentContextImpl documentContextImpl, int startPos) {
+ protected OutputProcessorChainImpl(SecurityContext securityContext, DocumentContextImpl documentContextImpl,
+ int startPos, List<OutputProcessor> outputProcessors) {
this.securityContext = securityContext;
this.curPos = this.startPos = startPos;
documentContext = documentContextImpl;
+ this.outputProcessors = outputProcessors;
}
public void reset() {
@@ -78,10 +80,6 @@ public class OutputProcessorChainImpl im
return this.documentContext;
}
- private void setOutputProcessors(List<OutputProcessor> outputProcessors) {
- this.outputProcessors = outputProcessors;
- }
-
public void addProcessor(OutputProcessor newOutputProcessor) {
int startPhaseIdx = 0;
int endPhaseIdx = outputProcessors.size();
@@ -227,11 +225,10 @@ public class OutputProcessorChainImpl im
OutputProcessorChainImpl outputProcessorChain;
try {
outputProcessorChain = new OutputProcessorChainImpl(securityContext, documentContext.clone(),
- outputProcessors.indexOf(outputProcessor) + 1);
+ outputProcessors.indexOf(outputProcessor) + 1, this.outputProcessors);
} catch (CloneNotSupportedException e) {
throw new XMLSecurityException(XMLSecurityException.ErrorCode.FAILURE, e);
}
- outputProcessorChain.setOutputProcessors(this.outputProcessors);
if (parentXMLSecStartElement != null) {
outputProcessorChain.setParentXmlSecStartElement(parentXMLSecStartElement);
} else {
Modified: santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/processor/output/AbstractEncryptOutputProcessor.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/processor/output/AbstractEncryptOutputProcessor.java?rev=1389478&r1=1389477&r2=1389478&view=diff
==============================================================================
--- santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/processor/output/AbstractEncryptOutputProcessor.java (original)
+++ santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/processor/output/AbstractEncryptOutputProcessor.java Mon Sep 24 16:46:11 2012
@@ -35,7 +35,6 @@ import javax.crypto.NoSuchPaddingExcepti
import javax.crypto.spec.IvParameterSpec;
import javax.xml.namespace.QName;
import javax.xml.stream.XMLEventWriter;
-import javax.xml.stream.XMLOutputFactory;
import javax.xml.stream.XMLStreamConstants;
import javax.xml.stream.XMLStreamException;
import java.io.BufferedOutputStream;
@@ -58,13 +57,10 @@ import java.util.List;
*/
public abstract class AbstractEncryptOutputProcessor extends AbstractOutputProcessor {
- private static final XMLOutputFactory xmlOutputFactory;
private static final XMLSecStartElement wrapperStartElement;
private static final XMLSecEndElement wrapperEndElement;
static {
- xmlOutputFactory = XMLOutputFactory.newInstance();
- xmlOutputFactory.setProperty(XMLOutputFactory.IS_REPAIRING_NAMESPACES, false);
wrapperStartElement = XMLSecEventFactory.createXmlSecStartElement(new QName("a"), null, null);
wrapperEndElement = XMLSecEventFactory.createXmlSecEndElement(new QName("a"));
}
@@ -155,7 +151,7 @@ public abstract class AbstractEncryptOut
//we create a new StAX writer for optimized namespace writing.
//spec says (4.2): "The cleartext octet sequence obtained in step 3 is interpreted as UTF-8 encoded character data."
- xmlEventWriter = xmlOutputFactory.createXMLEventWriter(new BufferedOutputStream(cipherOutputStream, 8192 * 5), "UTF-8");
+ xmlEventWriter = XMLSecurityConstants.xmlOutputFactory.createXMLEventWriter(new BufferedOutputStream(cipherOutputStream, 8192 * 5), "UTF-8");
//we have to output a fake element to workaround text-only encryption:
xmlEventWriter.add(wrapperStartElement);
} catch (NoSuchPaddingException e) {
Modified: santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/processor/output/FinalOutputProcessor.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/processor/output/FinalOutputProcessor.java?rev=1389478&r1=1389477&r2=1389478&view=diff
==============================================================================
--- santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/processor/output/FinalOutputProcessor.java (original)
+++ santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/processor/output/FinalOutputProcessor.java Mon Sep 24 16:46:11 2012
@@ -26,7 +26,6 @@ import org.apache.xml.security.stax.ext.
import org.apache.xml.security.stax.impl.XMLSecurityEventWriter;
import javax.xml.stream.XMLEventWriter;
-import javax.xml.stream.XMLOutputFactory;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamWriter;
import java.io.OutputStream;
@@ -41,17 +40,12 @@ import java.io.OutputStream;
public class FinalOutputProcessor extends AbstractOutputProcessor {
private XMLEventWriter xmlEventWriter;
- private static final XMLOutputFactory xmlOutputFactory = XMLOutputFactory.newInstance();
-
- static {
- xmlOutputFactory.setProperty(XMLOutputFactory.IS_REPAIRING_NAMESPACES, false);
- }
public FinalOutputProcessor(OutputStream outputStream, String encoding) throws XMLSecurityException {
super();
setPhase(XMLSecurityConstants.Phase.POSTPROCESSING);
try {
- xmlEventWriter = xmlOutputFactory.createXMLEventWriter(outputStream, encoding);
+ xmlEventWriter = XMLSecurityConstants.xmlOutputFactory.createXMLEventWriter(outputStream, encoding);
} catch (XMLStreamException e) {
throw new XMLSecurityException(XMLSecurityException.ErrorCode.FAILURE, e);
}
Modified: santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/processor/output/XMLSignatureEndingOutputProcessor.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/processor/output/XMLSignatureEndingOutputProcessor.java?rev=1389478&r1=1389477&r2=1389478&view=diff
==============================================================================
--- santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/processor/output/XMLSignatureEndingOutputProcessor.java (original)
+++ santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/processor/output/XMLSignatureEndingOutputProcessor.java Mon Sep 24 16:46:11 2012
@@ -20,7 +20,7 @@ package org.apache.xml.security.stax.imp
import java.security.cert.X509Certificate;
import java.util.ArrayList;
-import java.util.Iterator;
+import java.util.Deque;
import java.util.List;
import javax.xml.stream.XMLStreamException;
@@ -72,15 +72,15 @@ public class XMLSignatureEndingOutputPro
@Override
protected void flushBufferAndCallbackAfterTokenID(
- OutputProcessorChain outputProcessorChain, Iterator<XMLSecEvent> xmlSecEventIterator)
+ OutputProcessorChain outputProcessorChain, Deque<XMLSecEvent> xmlSecEventDeque)
throws XMLStreamException, XMLSecurityException {
//@see SANTUARIO-324
//output root element...
outputProcessorChain.reset();
- outputProcessorChain.processEvent(xmlSecEventIterator.next());
+ outputProcessorChain.processEvent(xmlSecEventDeque.pop());
//...then call super to append the signature and flush the rest
- super.flushBufferAndCallbackAfterTokenID(outputProcessorChain, xmlSecEventIterator);
+ super.flushBufferAndCallbackAfterTokenID(outputProcessorChain, xmlSecEventDeque);
}
@Override
Modified: santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/stax/XMLSecEventBaseImpl.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/stax/XMLSecEventBaseImpl.java?rev=1389478&r1=1389477&r2=1389478&view=diff
==============================================================================
--- santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/stax/XMLSecEventBaseImpl.java (original)
+++ santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/stax/XMLSecEventBaseImpl.java Mon Sep 24 16:46:11 2012
@@ -36,7 +36,6 @@ import java.util.List;
*/
public abstract class XMLSecEventBaseImpl implements XMLSecEvent {
- protected static final Location location = new LocationImpl();
protected XMLSecStartElement parentXMLSecStartELement;
@Override
@@ -81,7 +80,7 @@ public abstract class XMLSecEventBaseImp
@Override
public Location getLocation() {
- return location;
+ return new LocationImpl();
}
@Override
Added: santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/stax/performance/AbstractPerformanceTest.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/stax/performance/AbstractPerformanceTest.java?rev=1389478&view=auto
==============================================================================
--- santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/stax/performance/AbstractPerformanceTest.java (added)
+++ santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/stax/performance/AbstractPerformanceTest.java Mon Sep 24 16:46:11 2012
@@ -0,0 +1,309 @@
+/**
+ * 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.xml.security.test.stax.performance;
+
+import org.apache.xml.security.encryption.XMLCipher;
+import org.apache.xml.security.signature.XMLSignature;
+import org.apache.xml.security.stax.ext.*;
+import org.apache.xml.security.test.stax.utils.XmlReaderToWriter;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+
+import javax.crypto.KeyGenerator;
+import javax.xml.namespace.QName;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLStreamConstants;
+import javax.xml.stream.XMLStreamReader;
+import javax.xml.stream.XMLStreamWriter;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.dom.DOMSource;
+import javax.xml.transform.stream.StreamResult;
+import java.io.*;
+import java.security.Key;
+import java.security.KeyStore;
+import java.security.cert.X509Certificate;
+
+/**
+ * @author $Author: $
+ * @version $Revision: $ $Date: $
+ */
+public abstract class AbstractPerformanceTest {
+
+ private static Key encryptionSymKey;
+ protected XMLInputFactory xmlInputFactory;
+ protected DocumentBuilderFactory documentBuilderFactory;
+ protected TransformerFactory transformerFactory;
+ protected Key key;
+ protected X509Certificate cert;
+ private OutboundXMLSec outboundSignatureXMLSec;
+ private InboundXMLSec inboundSignatureXMLSec;
+ private OutboundXMLSec outboundEncryptionXMLSec;
+ private InboundXMLSec inboundDecryptionXMLSec;
+
+ @BeforeClass
+ public static void genKey() throws Exception {
+ KeyGenerator keygen = KeyGenerator.getInstance("AES");
+ keygen.init(256);
+ encryptionSymKey = keygen.generateKey();
+ }
+
+ @Before
+ public void setUp() throws Exception {
+ xmlInputFactory = XMLInputFactory.newInstance();
+ xmlInputFactory.setProperty(XMLInputFactory.IS_COALESCING, false);
+ xmlInputFactory.setProperty(XMLInputFactory.SUPPORT_DTD, false);
+
+ documentBuilderFactory = DocumentBuilderFactory.newInstance();
+ documentBuilderFactory.setNamespaceAware(true);
+
+ transformerFactory = TransformerFactory.newInstance();
+
+ org.apache.xml.security.Init.init();
+
+ KeyStore keyStore = KeyStore.getInstance("jks");
+ keyStore.load(
+ this.getClass().getClassLoader().getResource("transmitter.jks").openStream(),
+ "default".toCharArray()
+ );
+ key = keyStore.getKey("transmitter", "default".toCharArray());
+ cert = (X509Certificate) keyStore.getCertificate("transmitter");
+
+ setUpOutboundSignatureXMLSec();
+ setUpInboundSignatureXMLSec();
+
+ setUpOutboundEncryptionXMLSec();
+ setUpInboundEncryptionXMLSec();
+ }
+
+ protected File generateLargeXMLFile(int factor) throws Exception {
+ File path = getTmpFilePath();
+ path.mkdirs();
+ File target = new File(path, "tmp.xml");
+ FileWriter fileWriter = new FileWriter(target, false);
+ fileWriter.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
+ "<test xmlns=\"http://www.example.com\">");
+ fileWriter.close();
+ FileOutputStream fileOutputStream = new FileOutputStream(target, true);
+ for (int i = 0; i < factor; i++) {
+ int read = 0;
+ byte[] buffer = new byte[4096];
+ InputStream inputStream = this.getClass().getClassLoader().getResourceAsStream(
+ "org/w3c/www/interop/xmlenc-core-11/plaintext.xml");
+ while ((read = inputStream.read(buffer)) != -1) {
+ fileOutputStream.write(buffer, 0, read);
+ }
+ inputStream.close();
+ }
+ fileWriter = new FileWriter(target, true);
+ fileWriter.write("</test>");
+ fileWriter.close();
+
+ return target;
+ }
+
+ protected int countXMLStartTags(File file) throws Exception {
+ int i = 0;
+ FileInputStream fileInputStream = new FileInputStream(file);
+ XMLStreamReader xmlStreamReader = xmlInputFactory.createXMLStreamReader(fileInputStream);
+ while (xmlStreamReader.hasNext()) {
+ xmlStreamReader.next();
+ switch (xmlStreamReader.getEventType()) {
+ case XMLStreamConstants.START_ELEMENT:
+ i++;
+ break;
+ }
+ }
+ xmlStreamReader.close();
+ fileInputStream.close();
+ return i;
+ }
+
+ protected abstract File getTmpFilePath();
+
+ protected void setUpOutboundSignatureXMLSec() throws XMLSecurityException {
+ XMLSecurityProperties xmlSecurityProperties = new XMLSecurityProperties();
+ XMLSecurityConstants.Action[] actions = new XMLSecurityConstants.Action[]{
+ XMLSecurityConstants.SIGNATURE
+ };
+ xmlSecurityProperties.setOutAction(actions);
+ xmlSecurityProperties.setSignatureKeyIdentifierType(XMLSecurityConstants.XMLKeyIdentifierType.X509_CERTIFICATE);
+
+ xmlSecurityProperties.setSignatureKey(key);
+ xmlSecurityProperties.setSignatureCerts(new X509Certificate[]{cert});
+
+ SecurePart securePart = new SecurePart(
+ new QName("http://www.example.com", "test"),
+ SecurePart.Modifier.Element,
+ new String[]{
+ "http://www.w3.org/2000/09/xmldsig#enveloped-signature",
+ "http://www.w3.org/TR/2001/REC-xml-c14n-20010315"
+ },
+ "http://www.w3.org/2000/09/xmldsig#sha1"
+ );
+ xmlSecurityProperties.addSignaturePart(securePart);
+
+ outboundSignatureXMLSec = XMLSec.getOutboundXMLSec(xmlSecurityProperties);
+ }
+
+ protected void setUpInboundSignatureXMLSec() throws XMLSecurityException {
+ XMLSecurityProperties inboundProperties = new XMLSecurityProperties();
+ inboundProperties.setSignatureVerificationKey(cert.getPublicKey());
+ inboundSignatureXMLSec = XMLSec.getInboundWSSec(inboundProperties);
+ }
+
+ protected void setUpOutboundEncryptionXMLSec() throws XMLSecurityException {
+ XMLSecurityProperties xmlSecurityProperties = new XMLSecurityProperties();
+ XMLSecurityConstants.Action[] actions = new XMLSecurityConstants.Action[]{
+ XMLSecurityConstants.ENCRYPT
+ };
+ xmlSecurityProperties.setOutAction(actions);
+ xmlSecurityProperties.setEncryptionKey(encryptionSymKey);
+ xmlSecurityProperties.setEncryptionSymAlgorithm("http://www.w3.org/2001/04/xmlenc#aes256-cbc");
+
+ SecurePart securePart = new SecurePart(
+ new QName("http://www.example.com", "test"),
+ SecurePart.Modifier.Element
+ );
+ xmlSecurityProperties.addEncryptionPart(securePart);
+
+ outboundEncryptionXMLSec = XMLSec.getOutboundXMLSec(xmlSecurityProperties);
+ }
+
+ protected void setUpInboundEncryptionXMLSec() throws XMLSecurityException {
+ XMLSecurityProperties inboundProperties = new XMLSecurityProperties();
+ inboundProperties.setDecryptionKey(encryptionSymKey);
+ inboundDecryptionXMLSec = XMLSec.getInboundWSSec(inboundProperties);
+ }
+
+ protected File doStreamingSignatureOutbound(File file, int tagCount) throws Exception {
+
+ final File signedFile = new File(getTmpFilePath(), "signature-stax-" + tagCount + ".xml");
+ OutputStream outputStream = new BufferedOutputStream(new FileOutputStream(signedFile));
+ XMLStreamWriter xmlStreamWriter = outboundSignatureXMLSec.processOutMessage(outputStream, "UTF-8");
+
+ InputStream inputStream = new BufferedInputStream(new FileInputStream(file));
+ XMLStreamReader xmlStreamReader = xmlInputFactory.createXMLStreamReader(inputStream);
+
+ XmlReaderToWriter.writeAll(xmlStreamReader, xmlStreamWriter);
+ xmlStreamWriter.close();
+ outputStream.close();
+ xmlStreamReader.close();
+ inputStream.close();
+ return signedFile;
+ }
+
+ protected void doStreamingSignatureInbound(File file, int tagCount) throws Exception {
+
+ InputStream inputStream = new BufferedInputStream(new FileInputStream(file));
+ XMLStreamReader xmlStreamReader = xmlInputFactory.createXMLStreamReader(inputStream);
+ XMLStreamReader securityStreamReader = inboundSignatureXMLSec.processInMessage(xmlStreamReader);
+
+ while (securityStreamReader.hasNext()) {
+ securityStreamReader.next();
+ }
+ xmlStreamReader.close();
+ inputStream.close();
+ securityStreamReader.close();
+ }
+
+ protected void doDOMSignatureOutbound(File file, int tagCount) throws Exception {
+
+ DocumentBuilder builder = documentBuilderFactory.newDocumentBuilder();
+ Document document = builder.parse(file);
+
+ XMLSignature sig = new XMLSignature(document, "", "http://www.w3.org/2000/09/xmldsig#rsa-sha1");
+ Element root = document.getDocumentElement();
+ root.insertBefore(sig.getElement(), root.getFirstChild());
+
+ sig.sign(key);
+ sig.addKeyInfo(cert);
+
+ javax.xml.transform.Transformer transformer = transformerFactory.newTransformer();
+ transformer.transform(new DOMSource(document), new StreamResult(new File(getTmpFilePath(), "signature-dom-" + tagCount + ".xml")));
+ }
+
+ protected void doDOMSignatureInbound(File file, int tagCount) throws Exception {
+
+ DocumentBuilder builder = documentBuilderFactory.newDocumentBuilder();
+ Document document = builder.parse(file);
+
+ Element signatureElement = (Element) document.getElementsByTagNameNS("http://www.w3.org/2000/09/xmldsig#", "Signature").item(0);
+ ((Element) signatureElement.getParentNode()).setIdAttributeNS(null, "Id", true);
+ XMLSignature xmlSignature = new XMLSignature(signatureElement, "", true);
+ xmlSignature.checkSignatureValue(cert);
+ }
+
+ protected File doStreamingEncryptionOutbound(File file, int tagCount) throws Exception {
+
+ final File signedFile = new File(getTmpFilePath(), "encryption-stax-" + tagCount + ".xml");
+ OutputStream outputStream = new BufferedOutputStream(new FileOutputStream(signedFile));
+ XMLStreamWriter xmlStreamWriter = outboundEncryptionXMLSec.processOutMessage(outputStream, "UTF-8");
+
+ InputStream inputStream = new BufferedInputStream(new FileInputStream(file));
+ XMLStreamReader xmlStreamReader = xmlInputFactory.createXMLStreamReader(inputStream);
+
+ XmlReaderToWriter.writeAll(xmlStreamReader, xmlStreamWriter);
+ xmlStreamWriter.close();
+ outputStream.close();
+ xmlStreamReader.close();
+ inputStream.close();
+ return signedFile;
+ }
+
+ protected void doStreamingDecryptionInbound(File file, int tagCount) throws Exception {
+
+ InputStream inputStream = new BufferedInputStream(new FileInputStream(file));
+ XMLStreamReader xmlStreamReader = xmlInputFactory.createXMLStreamReader(inputStream);
+ XMLStreamReader securityStreamReader = inboundDecryptionXMLSec.processInMessage(xmlStreamReader);
+
+ while (securityStreamReader.hasNext()) {
+ securityStreamReader.next();
+ }
+ xmlStreamReader.close();
+ inputStream.close();
+ securityStreamReader.close();
+ }
+
+ protected void doDOMEncryptionOutbound(File file, int tagCount) throws Exception {
+
+ DocumentBuilder builder = documentBuilderFactory.newDocumentBuilder();
+ Document document = builder.parse(file);
+
+ XMLCipher cipher = XMLCipher.getInstance("http://www.w3.org/2001/04/xmlenc#aes256-cbc");
+ cipher.init(XMLCipher.ENCRYPT_MODE, encryptionSymKey);
+ document = cipher.doFinal(document, document.getDocumentElement());
+
+ javax.xml.transform.Transformer transformer = transformerFactory.newTransformer();
+ transformer.transform(new DOMSource(document), new StreamResult(new File(getTmpFilePath(), "encryption-dom-" + tagCount + ".xml")));
+ }
+
+ protected void doDOMDecryptionInbound(File file, int tagCount) throws Exception {
+
+ DocumentBuilder builder = documentBuilderFactory.newDocumentBuilder();
+ Document document = builder.parse(file);
+
+ XMLCipher cipher = XMLCipher.getInstance("http://www.w3.org/2001/04/xmlenc#aes256-cbc");
+ cipher.init(XMLCipher.DECRYPT_MODE, encryptionSymKey);
+ cipher.doFinal(document, document.getDocumentElement());
+ }
+}
Propchange: santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/stax/performance/AbstractPerformanceTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/stax/performance/PerformanceMemoryTest.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/stax/performance/PerformanceMemoryTest.java?rev=1389478&view=auto
==============================================================================
--- santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/stax/performance/PerformanceMemoryTest.java (added)
+++ santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/stax/performance/PerformanceMemoryTest.java Mon Sep 24 16:46:11 2012
@@ -0,0 +1,262 @@
+/**
+ * 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.xml.security.test.stax.performance;
+
+import org.junit.Test;
+
+import java.io.File;
+import java.io.FileWriter;
+import java.util.*;
+
+/**
+ * @author $Author: $
+ * @version $Revision: $ $Date: $
+ */
+public class PerformanceMemoryTest extends AbstractPerformanceTest {
+
+ private static final int runs = 40;
+ private static final int xmlResizeFactor = 1000;
+
+ //junit creates for every test method a new class instance so we need a static list
+ private static Map<Integer, File> signedFiles = new TreeMap<Integer, File>();
+ private static Map<Integer, File> encryptedFiles = new TreeMap<Integer, File>();
+
+
+ @Override
+ protected File getTmpFilePath() {
+ return new File("target/performanceMemoryTest");
+ }
+
+ @Test
+ public void testOutboundSignatureMemoryPerformance() throws Exception {
+ System.out.println("Testing Outbound Signature Memory Performance");
+ FileWriter outSignatureSamplesWriter = new FileWriter("target/signatureOutMemorySamples.txt", false);
+ for (int i = 1; i <= runs; i++) {
+ System.out.println("Run " + i);
+
+ File file = generateLargeXMLFile(i * xmlResizeFactor);
+
+ int startTagCount = countXMLStartTags(file);
+ outSignatureSamplesWriter.write("" + startTagCount);
+
+ long startMem = getUsedMemory();
+ MemorySamplerThread mst = new MemorySamplerThread(startMem);
+ Thread thread = new Thread(mst);
+ thread.setPriority(9);
+ thread.start();
+ File signedFile = doStreamingSignatureOutbound(file, startTagCount);
+ mst.setStop(true);
+ thread.join();
+ outSignatureSamplesWriter.write(" " + mst.getMaxUsedMemory());
+ signedFiles.put(startTagCount, signedFile);
+
+ startMem = getUsedMemory();
+ mst = new MemorySamplerThread(startMem);
+ thread = new Thread(mst);
+ thread.setPriority(9);
+ thread.start();
+ doDOMSignatureOutbound(file, startTagCount);
+ mst.setStop(true);
+ thread.join();
+ outSignatureSamplesWriter.write(" " + mst.getMaxUsedMemory());
+
+ outSignatureSamplesWriter.write("\n");
+ }
+ outSignatureSamplesWriter.close();
+ }
+
+ @Test
+ public void testInboundSignatureMemoryPerformance() throws Exception {
+ System.out.println("Testing Inbound Signature Memory Performance");
+ FileWriter inSignatureSamplesWriter = new FileWriter("target/signatureInMemorySamples.txt", false);
+
+ int run = 1;
+ Iterator<Map.Entry<Integer, File>> mapIterator = signedFiles.entrySet().iterator();
+ while (mapIterator.hasNext()) {
+ Map.Entry<Integer, File> entry = mapIterator.next();
+ System.out.println("Run " + (run++));
+
+ File file = entry.getValue();
+ Integer startTagCount = entry.getKey();
+ inSignatureSamplesWriter.write("" + startTagCount);
+
+ long startMem = getUsedMemory();
+ MemorySamplerThread mst = new MemorySamplerThread(startMem);
+ Thread thread = new Thread(mst);
+ thread.setPriority(9);
+ thread.start();
+ doStreamingSignatureInbound(file, startTagCount);
+ mst.setStop(true);
+ thread.join();
+ inSignatureSamplesWriter.write(" " + mst.getMaxUsedMemory());
+
+ startMem = getUsedMemory();
+ mst = new MemorySamplerThread(startMem);
+ thread = new Thread(mst);
+ thread.setPriority(9);
+ thread.start();
+ doDOMSignatureInbound(file, startTagCount);
+ mst.setStop(true);
+ thread.join();
+ inSignatureSamplesWriter.write(" " + mst.getMaxUsedMemory());
+
+ inSignatureSamplesWriter.write("\n");
+ }
+ inSignatureSamplesWriter.close();
+ }
+
+ @Test
+ public void testOutboundEncryptionMemoryPerformance() throws Exception {
+ System.out.println("Testing Outbound Encryption Memory Performance");
+ FileWriter outEncryptionSamplesWriter = new FileWriter("target/encryptionOutMemorySamples.txt", false);
+ for (int i = 1; i <= runs; i++) {
+ System.out.println("Run " + i);
+
+ File file = generateLargeXMLFile(i * xmlResizeFactor);
+
+ int startTagCount = countXMLStartTags(file);
+ outEncryptionSamplesWriter.write("" + startTagCount);
+
+ long startMem = getUsedMemory();
+ MemorySamplerThread mst = new MemorySamplerThread(startMem);
+ Thread thread = new Thread(mst);
+ thread.setPriority(9);
+ thread.start();
+ File encryptedFile = doStreamingEncryptionOutbound(file, startTagCount);
+ mst.setStop(true);
+ thread.join();
+ outEncryptionSamplesWriter.write(" " + mst.getMaxUsedMemory());
+ encryptedFiles.put(startTagCount, encryptedFile);
+
+ startMem = getUsedMemory();
+ mst = new MemorySamplerThread(startMem);
+ thread = new Thread(mst);
+ thread.setPriority(9);
+ thread.start();
+ doDOMEncryptionOutbound(file, startTagCount);
+ mst.setStop(true);
+ thread.join();
+ outEncryptionSamplesWriter.write(" " + mst.getMaxUsedMemory());
+
+ outEncryptionSamplesWriter.write("\n");
+ }
+ outEncryptionSamplesWriter.close();
+ }
+
+ @Test
+ public void testInboundDecryptionMemoryPerformance() throws Exception {
+ System.out.println("Testing Inbound Decryption Memory Performance");
+ FileWriter inEncryptionSamplesWriter = new FileWriter("target/encryptionInMemorySamples.txt", false);
+
+ int run = 1;
+ Iterator<Map.Entry<Integer, File>> mapIterator = encryptedFiles.entrySet().iterator();
+ while (mapIterator.hasNext()) {
+ Map.Entry<Integer, File> entry = mapIterator.next();
+ System.out.println("Run " + (run++));
+
+ File file = entry.getValue();
+ Integer startTagCount = entry.getKey();
+ inEncryptionSamplesWriter.write("" + startTagCount);
+
+ long startMem = getUsedMemory();
+ MemorySamplerThread mst = new MemorySamplerThread(startMem);
+ Thread thread = new Thread(mst);
+ thread.setPriority(9);
+ thread.start();
+ doStreamingDecryptionInbound(file, startTagCount);
+ mst.setStop(true);
+ thread.join();
+ inEncryptionSamplesWriter.write(" " + mst.getMaxUsedMemory());
+
+ startMem = getUsedMemory();
+ mst = new MemorySamplerThread(startMem);
+ thread = new Thread(mst);
+ thread.setPriority(9);
+ thread.start();
+ doDOMDecryptionInbound(file, startTagCount);
+ inEncryptionSamplesWriter.write(" " + mst.getMaxUsedMemory());
+ mst.setStop(true);
+ thread.join();
+
+ inEncryptionSamplesWriter.write("\n");
+ }
+ inEncryptionSamplesWriter.close();
+ }
+
+ private static void gc() {
+ System.gc();
+ System.runFinalization();
+ System.gc();
+ }
+
+ private static long getUsedMemory() {
+ gc();
+ gc();
+ long totalMemory = Runtime.getRuntime().totalMemory();
+ long freeMemory = Runtime.getRuntime().freeMemory();
+ return totalMemory - freeMemory;
+ }
+
+ class MemorySamplerThread implements Runnable {
+
+ private long memoryDiff = 0;
+ private volatile boolean stop = false;
+
+ private List<Integer> memory = new LinkedList<Integer>();
+
+ MemorySamplerThread(long memoryDiff) {
+ this.memoryDiff = memoryDiff;
+ System.out.println("memory diff " + memoryDiff / 1024 / 1024);
+ }
+
+ public boolean isStop() {
+ return stop;
+ }
+
+ public void setStop(boolean stop) {
+ this.stop = stop;
+ }
+
+ public void run() {
+ int sleepTime = 50;
+ while (!isStop()) {
+ try {
+ Thread.sleep(sleepTime);
+ if (isStop()) {
+ break;
+ }
+ } catch (InterruptedException e) {
+ throw new RuntimeException(e);
+ }
+ memory.add((int) (((getUsedMemory()) - memoryDiff) / 1024.0 / 1024.0));
+ }
+ }
+
+ public int getMaxUsedMemory() {
+ System.out.println("Collected " + memory.size() + " samples");
+ int maxMem = Integer.MIN_VALUE;
+ for (int i = 0; i < memory.size(); i++) {
+ int mem = memory.get(i);
+ maxMem = mem > maxMem ? mem : maxMem;
+ }
+ System.out.println("Max memory usage: " + maxMem + "MB");
+ return maxMem;
+ }
+ }
+}
Propchange: santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/stax/performance/PerformanceMemoryTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/stax/performance/PerformanceTimingTest.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/stax/performance/PerformanceTimingTest.java?rev=1389478&view=auto
==============================================================================
--- santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/stax/performance/PerformanceTimingTest.java (added)
+++ santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/stax/performance/PerformanceTimingTest.java Mon Sep 24 16:46:11 2012
@@ -0,0 +1,170 @@
+/**
+ * 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.xml.security.test.stax.performance;
+
+import org.junit.Test;
+
+import java.io.File;
+import java.io.FileWriter;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.TreeMap;
+
+/**
+ * @author $Author: $
+ * @version $Revision: $ $Date: $
+ */
+public class PerformanceTimingTest extends AbstractPerformanceTest {
+
+ private static final int runs = 40;
+ private static final int xmlResizeFactor = 1000;
+
+ private static Map<Integer, File> signedFiles = new TreeMap<Integer, File>();
+ private static Map<Integer, File> encryptedFiles = new TreeMap<Integer, File>();
+
+
+ @Override
+ protected File getTmpFilePath() {
+ return new File("target/performanceTimingTest");
+ }
+
+ @Test
+ public void testOutboundSignatureTimePerformance() throws Exception {
+ System.out.println("Testing Outbound Signature Time Performance");
+ FileWriter outSignatureSamplesWriter = new FileWriter("target/signatureOutTimeSamples.txt", false);
+ for (int i = 1; i <= runs; i++) {
+ System.out.println("Run " + i);
+
+ File file = generateLargeXMLFile(i * xmlResizeFactor);
+
+ int startTagCount = countXMLStartTags(file);
+ outSignatureSamplesWriter.write("" + startTagCount);
+
+ long start = System.currentTimeMillis();
+ File signedFile = doStreamingSignatureOutbound(file, startTagCount);
+ outSignatureSamplesWriter.write(" " + ((System.currentTimeMillis() - start) / 1000.0));
+ signedFiles.put(startTagCount, signedFile);
+ System.gc();
+ System.gc();
+
+ start = System.currentTimeMillis();
+ doDOMSignatureOutbound(file, startTagCount);
+ outSignatureSamplesWriter.write(" " + ((System.currentTimeMillis() - start) / 1000.0));
+ System.gc();
+ System.gc();
+
+ outSignatureSamplesWriter.write("\n");
+ }
+ outSignatureSamplesWriter.close();
+ }
+
+ @Test
+ public void testInboundSignatureTimePerformance() throws Exception {
+ System.out.println("Testing Inbound Signature Time Performance");
+ FileWriter inSignatureSamplesWriter = new FileWriter("target/signatureInTimeSamples.txt", false);
+
+ int run = 1;
+ Iterator<Map.Entry<Integer, File>> mapIterator = signedFiles.entrySet().iterator();
+ while (mapIterator.hasNext()) {
+ Map.Entry<Integer, File> entry = mapIterator.next();
+ System.out.println("Run " + (run++));
+
+ File file = entry.getValue();
+ Integer startTagCount = entry.getKey();
+ inSignatureSamplesWriter.write("" + startTagCount);
+
+ long start = System.currentTimeMillis();
+ doStreamingSignatureInbound(file, startTagCount);
+ inSignatureSamplesWriter.write(" " + ((System.currentTimeMillis() - start) / 1000.0));
+ System.gc();
+ System.gc();
+
+ start = System.currentTimeMillis();
+ doDOMSignatureInbound(file, startTagCount);
+ inSignatureSamplesWriter.write(" " + ((System.currentTimeMillis() - start) / 1000.0));
+ System.gc();
+ System.gc();
+
+ inSignatureSamplesWriter.write("\n");
+ }
+ inSignatureSamplesWriter.close();
+ }
+
+ @Test
+ public void testOutboundEncryptionTimePerformance() throws Exception {
+ System.out.println("Testing Outbound Encryption Time Performance");
+ FileWriter outEncryptionSamplesWriter = new FileWriter("target/encryptionOutTimeSamples.txt", false);
+ for (int i = 1; i <= runs; i++) {
+ System.out.println("Run " + i);
+
+ File file = generateLargeXMLFile(i * xmlResizeFactor);
+
+ int startTagCount = countXMLStartTags(file);
+ outEncryptionSamplesWriter.write("" + startTagCount);
+
+ long start = System.currentTimeMillis();
+ File encryptedFile = doStreamingEncryptionOutbound(file, startTagCount);
+ outEncryptionSamplesWriter.write(" " + ((System.currentTimeMillis() - start) / 1000.0));
+ encryptedFiles.put(startTagCount, encryptedFile);
+ System.gc();
+ System.gc();
+
+ start = System.currentTimeMillis();
+ doDOMEncryptionOutbound(file, startTagCount);
+ outEncryptionSamplesWriter.write(" " + ((System.currentTimeMillis() - start) / 1000.0));
+ System.gc();
+ System.gc();
+
+ outEncryptionSamplesWriter.write("\n");
+ }
+ outEncryptionSamplesWriter.close();
+ }
+
+ @Test
+ public void testInboundDecryptionTimePerformance() throws Exception {
+ System.out.println("Testing Inbound Decryption Time Performance");
+ FileWriter inEncryptionSamplesWriter = new FileWriter("target/encryptionInTimeSamples.txt", false);
+
+ int run = 1;
+ Iterator<Map.Entry<Integer, File>> mapIterator = encryptedFiles.entrySet().iterator();
+ while (mapIterator.hasNext()) {
+ Map.Entry<Integer, File> entry = mapIterator.next();
+ System.out.println("Run " + (run++));
+
+ File file = entry.getValue();
+ Integer startTagCount = entry.getKey();
+ inEncryptionSamplesWriter.write("" + startTagCount);
+
+ long start = System.currentTimeMillis();
+ doStreamingDecryptionInbound(file, startTagCount);
+ inEncryptionSamplesWriter.write(" " + ((System.currentTimeMillis() - start) / 1000.0));
+ System.gc();
+ System.gc();
+
+ start = System.currentTimeMillis();
+ doDOMDecryptionInbound(file, startTagCount);
+ inEncryptionSamplesWriter.write(" " + ((System.currentTimeMillis() - start) / 1000.0));
+ System.gc();
+ System.gc();
+
+ inEncryptionSamplesWriter.write("\n");
+ }
+ inEncryptionSamplesWriter.close();
+ }
+}
Propchange: santuario/xml-security-java/trunk/src/test/java/org/apache/xml/security/test/stax/performance/PerformanceTimingTest.java
------------------------------------------------------------------------------
svn:eol-style = native