Search in sources :

Example 6 with Canonicalizer20010315_OmitCommentsTransformer

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

the class TransformCanonicalizerTest method testInputStreamToInputStreamAPI.

@Test
public void testInputStreamToInputStreamAPI() throws Exception {
    Canonicalizer20010315_OmitCommentsTransformer canonicalizerTransformer = new Canonicalizer20010315_OmitCommentsTransformer();
    final ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
    Transformer transformer = new Transformer() {

        @Override
        public void setOutputStream(OutputStream outputStream) throws XMLSecurityException {
        }

        @Override
        public void setTransformer(Transformer transformer) throws XMLSecurityException {
        }

        @Override
        public void setProperties(Map<String, Object> properties) throws XMLSecurityException {
        }

        @Override
        public XMLSecurityConstants.TransformMethod getPreferredTransformMethod(XMLSecurityConstants.TransformMethod forInput) {
            return XMLSecurityConstants.TransformMethod.InputStream;
        }

        @Override
        public void transform(XMLSecEvent xmlSecEvent) throws XMLStreamException {
            Assert.fail("unexpected call to transform(XMLSecEvent");
        }

        @Override
        public void transform(InputStream inputStream) throws XMLStreamException {
            try {
                XMLSecurityUtils.copy(inputStream, byteArrayOutputStream);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }

        @Override
        public void doFinal() throws XMLStreamException {
        }
    };
    canonicalizerTransformer.setTransformer(transformer);
    canonicalizerTransformer.transform(this.getClass().getClassLoader().getResourceAsStream("ie/baltimore/merlin-examples/merlin-xmlenc-five/plaintext-base64.xml"));
    canonicalizerTransformer.doFinal();
    Assert.assertEquals(554, byteArrayOutputStream.size());
}
Also used : XMLSecurityConstants(org.apache.xml.security.stax.ext.XMLSecurityConstants) Transformer(org.apache.xml.security.stax.ext.Transformer) Canonicalizer20010315_OmitCommentsTransformer(org.apache.xml.security.stax.impl.transformer.canonicalizer.Canonicalizer20010315_OmitCommentsTransformer) InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Canonicalizer20010315_OmitCommentsTransformer(org.apache.xml.security.stax.impl.transformer.canonicalizer.Canonicalizer20010315_OmitCommentsTransformer) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) Map(java.util.Map) XMLSecEvent(org.apache.xml.security.stax.ext.stax.XMLSecEvent) Test(org.junit.Test)

Example 7 with Canonicalizer20010315_OmitCommentsTransformer

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

the class TransformCanonicalizerTest method testXMLSecEventToInputStreamAPI.

@Test
public void testXMLSecEventToInputStreamAPI() throws Exception {
    Canonicalizer20010315_OmitCommentsTransformer canonicalizerTransformer = new Canonicalizer20010315_OmitCommentsTransformer();
    final ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
    Transformer transformer = new Transformer() {

        @Override
        public void setOutputStream(OutputStream outputStream) throws XMLSecurityException {
        }

        @Override
        public void setTransformer(Transformer transformer) throws XMLSecurityException {
        }

        @Override
        public void setProperties(Map<String, Object> properties) throws XMLSecurityException {
        }

        @Override
        public XMLSecurityConstants.TransformMethod getPreferredTransformMethod(XMLSecurityConstants.TransformMethod forInput) {
            return XMLSecurityConstants.TransformMethod.InputStream;
        }

        @Override
        public void transform(XMLSecEvent xmlSecEvent) throws XMLStreamException {
            Assert.fail("unexpected call to transform(XMLSecEvent");
        }

        @Override
        public void transform(InputStream inputStream) throws XMLStreamException {
            try {
                XMLSecurityUtils.copy(inputStream, byteArrayOutputStream);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }

        @Override
        public void doFinal() throws XMLStreamException {
        }
    };
    canonicalizerTransformer.setTransformer(transformer);
    XMLEventReader xmlSecEventReader = xmlInputFactory.createXMLEventReader(this.getClass().getClassLoader().getResourceAsStream("ie/baltimore/merlin-examples/merlin-xmlenc-five/plaintext-base64.xml"));
    while (xmlSecEventReader.hasNext()) {
        XMLSecEvent xmlSecEvent = (XMLSecEvent) xmlSecEventReader.nextEvent();
        canonicalizerTransformer.transform(xmlSecEvent);
    }
    canonicalizerTransformer.doFinal();
    Assert.assertEquals(554, byteArrayOutputStream.size());
}
Also used : XMLSecurityConstants(org.apache.xml.security.stax.ext.XMLSecurityConstants) Transformer(org.apache.xml.security.stax.ext.Transformer) Canonicalizer20010315_OmitCommentsTransformer(org.apache.xml.security.stax.impl.transformer.canonicalizer.Canonicalizer20010315_OmitCommentsTransformer) InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Canonicalizer20010315_OmitCommentsTransformer(org.apache.xml.security.stax.impl.transformer.canonicalizer.Canonicalizer20010315_OmitCommentsTransformer) XMLEventReader(javax.xml.stream.XMLEventReader) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) Map(java.util.Map) XMLSecEvent(org.apache.xml.security.stax.ext.stax.XMLSecEvent) Test(org.junit.Test)

Example 8 with Canonicalizer20010315_OmitCommentsTransformer

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

the class TransformCanonicalizerTest method testXMLSecEventToOutputStreamStreamAPI.

@Test
public void testXMLSecEventToOutputStreamStreamAPI() throws Exception {
    Canonicalizer20010315_OmitCommentsTransformer canonicalizerTransformer = new Canonicalizer20010315_OmitCommentsTransformer();
    final ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
    canonicalizerTransformer.setOutputStream(byteArrayOutputStream);
    XMLEventReader xmlSecEventReader = xmlInputFactory.createXMLEventReader(this.getClass().getClassLoader().getResourceAsStream("ie/baltimore/merlin-examples/merlin-xmlenc-five/plaintext-base64.xml"));
    while (xmlSecEventReader.hasNext()) {
        XMLSecEvent xmlSecEvent = (XMLSecEvent) xmlSecEventReader.nextEvent();
        canonicalizerTransformer.transform(xmlSecEvent);
    }
    canonicalizerTransformer.doFinal();
    Assert.assertEquals(554, byteArrayOutputStream.size());
}
Also used : Canonicalizer20010315_OmitCommentsTransformer(org.apache.xml.security.stax.impl.transformer.canonicalizer.Canonicalizer20010315_OmitCommentsTransformer) XMLEventReader(javax.xml.stream.XMLEventReader) ByteArrayOutputStream(java.io.ByteArrayOutputStream) XMLSecEvent(org.apache.xml.security.stax.ext.stax.XMLSecEvent) Test(org.junit.Test)

Aggregations

Canonicalizer20010315_OmitCommentsTransformer (org.apache.xml.security.stax.impl.transformer.canonicalizer.Canonicalizer20010315_OmitCommentsTransformer)8 ByteArrayOutputStream (java.io.ByteArrayOutputStream)7 XMLSecEvent (org.apache.xml.security.stax.ext.stax.XMLSecEvent)6 Test (org.junit.Test)6 IOException (java.io.IOException)4 InputStream (java.io.InputStream)4 OutputStream (java.io.OutputStream)4 Map (java.util.Map)4 XMLEventReader (javax.xml.stream.XMLEventReader)4 Transformer (org.apache.xml.security.stax.ext.Transformer)4 XMLSecurityConstants (org.apache.xml.security.stax.ext.XMLSecurityConstants)4 InclusiveNamespaces (org.apache.xml.security.binding.excc14n.InclusiveNamespaces)1 TransformType (org.apache.xml.security.binding.xmldsig.TransformType)1 XMLSecurityException (org.apache.xml.security.exceptions.XMLSecurityException)1 Canonicalizer20010315_WithCommentsTransformer (org.apache.xml.security.stax.impl.transformer.canonicalizer.Canonicalizer20010315_WithCommentsTransformer)1 CanonicalizerBase (org.apache.xml.security.stax.impl.transformer.canonicalizer.CanonicalizerBase)1 AlgorithmSuiteSecurityEvent (org.apache.xml.security.stax.securityEvent.AlgorithmSuiteSecurityEvent)1