use of org.apache.xml.security.stax.ext.stax.XMLSecEvent in project santuario-java by apache.
the class XMLSecurityEventReaderTest method testIndex.
@Test
public void testIndex() throws Exception {
XMLInputFactory xmlInputFactory = XMLInputFactory.newInstance();
XMLStreamReader xmlStreamReader = xmlInputFactory.createXMLStreamReader(this.getClass().getClassLoader().getResourceAsStream("org/apache/xml/security/c14n/inExcl/plain-soap-1.1.xml"));
Deque<XMLSecEvent> xmlSecEventDeque = new ArrayDeque<XMLSecEvent>();
do {
xmlSecEventDeque.push(XMLSecEventFactory.allocate(xmlStreamReader, null));
xmlStreamReader.next();
} while (xmlStreamReader.hasNext());
// EndDocumentEvent
xmlSecEventDeque.push(XMLSecEventFactory.allocate(xmlStreamReader, null));
int skip = 100;
XMLSecurityEventReader xmlSecurityEventReader = new XMLSecurityEventReader(xmlSecEventDeque, skip);
XMLEventReader xmlEventReader = xmlInputFactory.createXMLEventReader(this.getClass().getClassLoader().getResourceAsStream("org/apache/xml/security/c14n/inExcl/plain-soap-1.1.xml"));
int currentIndex = 0;
while (xmlEventReader.hasNext()) {
XMLEvent stdXmlEvent = xmlEventReader.nextEvent();
if (currentIndex++ < skip) {
continue;
}
XMLEvent secXmlEvent = xmlSecurityEventReader.nextEvent();
Assert.assertEquals(stdXmlEvent.getEventType(), secXmlEvent.getEventType());
XMLEvent stdPeekedXMLEvent = xmlEventReader.peek();
XMLEvent secPeekedXMLEvent = xmlSecurityEventReader.peek();
if (stdPeekedXMLEvent == null) {
Assert.assertNull(secPeekedXMLEvent);
} else {
Assert.assertEquals(stdPeekedXMLEvent.getEventType(), secPeekedXMLEvent.getEventType());
}
}
Assert.assertFalse(xmlEventReader.hasNext());
Assert.assertFalse(xmlSecurityEventReader.hasNext());
}
use of org.apache.xml.security.stax.ext.stax.XMLSecEvent in project santuario-java by apache.
the class TransformBase64DecodeTest method testXMLSecEventToInputStreamAPI.
@Test
public void testXMLSecEventToInputStreamAPI() throws Exception {
TransformBase64Decode transformBase64Decode = new TransformBase64Decode();
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 {
}
};
transformBase64Decode.setTransformer(transformer);
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());
}
use of org.apache.xml.security.stax.ext.stax.XMLSecEvent in project santuario-java by apache.
the class TransformBase64DecodeTest method testInputStreamToInputStreamAPI.
@Test
public void testInputStreamToInputStreamAPI() throws Exception {
TransformBase64Decode transformBase64Decode = new TransformBase64Decode();
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 {
}
};
transformBase64Decode.setTransformer(transformer);
transformBase64Decode.transform(this.getClass().getClassLoader().getResourceAsStream("ie/baltimore/merlin-examples/merlin-xmlenc-five/base64.xml"));
transformBase64Decode.doFinal();
Assert.assertEquals(615, byteArrayOutputStream.size());
}
use of org.apache.xml.security.stax.ext.stax.XMLSecEvent 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());
}
use of org.apache.xml.security.stax.ext.stax.XMLSecEvent 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());
}
Aggregations