Search in sources :

Example 6 with TransformBase64Decode

use of org.apache.xml.security.stax.impl.transformer.TransformBase64Decode in project santuario-java by apache.

the class TransformBase64DecodeTest method testXMLSecEventToOutputStreamStreamAPI.

@Test
public void testXMLSecEventToOutputStreamStreamAPI() throws Exception {
    TransformBase64Decode transformBase64Decode = new TransformBase64Decode();
    final ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
    transformBase64Decode.setOutputStream(byteArrayOutputStream);
    XMLEventReader xmlSecEventReader = xmlInputFactory.createXMLEventReader(this.getClass().getClassLoader().getResourceAsStream("ie/baltimore/merlin-examples/merlin-xmlenc-five/plaintext-base64.xml"));
    XMLSecEvent xmlSecEvent = null;
    while (xmlSecEventReader.hasNext()) {
        xmlSecEvent = (XMLSecEvent) xmlSecEventReader.nextEvent();
        if (xmlSecEvent.isStartElement() && xmlSecEvent.asStartElement().getName().equals(new QName("urn:example:po", "PaymentInfo"))) {
            break;
        }
    }
    while (xmlSecEventReader.hasNext()) {
        transformBase64Decode.transform(xmlSecEvent);
        if (xmlSecEvent.isEndElement() && xmlSecEvent.asEndElement().getName().equals(new QName("urn:example:po", "PaymentInfo"))) {
            break;
        }
        xmlSecEvent = (XMLSecEvent) xmlSecEventReader.nextEvent();
    }
    transformBase64Decode.doFinal();
    Assert.assertEquals(153, byteArrayOutputStream.size());
}
Also used : TransformBase64Decode(org.apache.xml.security.stax.impl.transformer.TransformBase64Decode) QName(javax.xml.namespace.QName) XMLEventReader(javax.xml.stream.XMLEventReader) ByteArrayOutputStream(java.io.ByteArrayOutputStream) XMLSecEvent(org.apache.xml.security.stax.ext.stax.XMLSecEvent) Test(org.junit.Test)

Aggregations

ByteArrayOutputStream (java.io.ByteArrayOutputStream)6 TransformBase64Decode (org.apache.xml.security.stax.impl.transformer.TransformBase64Decode)6 Test (org.junit.Test)6 XMLSecEvent (org.apache.xml.security.stax.ext.stax.XMLSecEvent)5 InputStream (java.io.InputStream)4 OutputStream (java.io.OutputStream)4 Map (java.util.Map)4 Transformer (org.apache.xml.security.stax.ext.Transformer)4 XMLSecurityConstants (org.apache.xml.security.stax.ext.XMLSecurityConstants)4 QName (javax.xml.namespace.QName)3 XMLEventReader (javax.xml.stream.XMLEventReader)3 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2