use of org.apache.xml.security.stax.ext.Transformer 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.ext.Transformer in project santuario-java by apache.
the class TransformEnvelopedSignatureTest method testXMLSecEventToXMLSecEventAPI.
@Test
public void testXMLSecEventToXMLSecEventAPI() throws Exception {
TransformEnvelopedSignature transformEnvelopedSignature = new TransformEnvelopedSignature();
final List<XMLSecEvent> xmlSecEvents = new ArrayList<>();
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.XMLSecEvent;
}
@Override
public void transform(XMLSecEvent xmlSecEvent) throws XMLStreamException {
xmlSecEvents.add(xmlSecEvent);
}
@Override
public void transform(InputStream inputStream) throws XMLStreamException {
Assert.fail("unexpected call to transform(InputStream");
}
@Override
public void doFinal() throws XMLStreamException {
}
};
transformEnvelopedSignature.setTransformer(transformer);
XMLEventReader xmlSecEventReader = xmlInputFactory.createXMLEventReader(this.getClass().getClassLoader().getResourceAsStream("com/phaos/phaos-xmldsig-three/signature-rsa-enveloped.xml"));
while (xmlSecEventReader.hasNext()) {
XMLSecEvent xmlSecEvent = (XMLSecEvent) xmlSecEventReader.nextEvent();
transformEnvelopedSignature.transform(xmlSecEvent);
}
transformEnvelopedSignature.doFinal();
Assert.assertEquals(19, xmlSecEvents.size());
}
use of org.apache.xml.security.stax.ext.Transformer in project santuario-java by apache.
the class TransformIdentityTest method testInputStreamToXMLSecEventAPI.
@Test
public void testInputStreamToXMLSecEventAPI() throws Exception {
TransformIdentity transformIdentity = new TransformIdentity();
final List<XMLSecEvent> xmlSecEvents = new ArrayList<>();
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.XMLSecEvent;
}
@Override
public void transform(XMLSecEvent xmlSecEvent) throws XMLStreamException {
xmlSecEvents.add(xmlSecEvent);
}
@Override
public void transform(InputStream inputStream) throws XMLStreamException {
Assert.fail("unexpected call to transform(InputStream");
}
@Override
public void doFinal() throws XMLStreamException {
}
};
transformIdentity.setTransformer(transformer);
transformIdentity.transform(new UnixInputStream(this.getClass().getClassLoader().getResourceAsStream("ie/baltimore/merlin-examples/merlin-xmlenc-five/plaintext-base64.xml")));
transformIdentity.doFinal();
Assert.assertEquals(25, xmlSecEvents.size());
}
use of org.apache.xml.security.stax.ext.Transformer in project santuario-java by apache.
the class TransformIdentityTest method testInputStreamToInputStreamAPI.
@Test
public void testInputStreamToInputStreamAPI() throws Exception {
TransformIdentity transformIdentity = new TransformIdentity();
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 {
}
};
transformIdentity.setTransformer(transformer);
transformIdentity.transform(this.getClass().getClassLoader().getResourceAsStream("ie/baltimore/merlin-examples/merlin-xmlenc-five/base64.xml"));
transformIdentity.doFinal();
Assert.assertEquals(831, byteArrayOutputStream.size());
}
Aggregations