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());
}
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());
}
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());
}
Aggregations