use of javax.xml.stream.XMLOutputFactory in project webservices-axiom by apache.
the class StreamingOMSerializerTest method runTest.
@Override
protected void runTest() throws Throwable {
XMLInputFactory inputFactory = XMLInputFactory.newInstance();
StAXDialect dialect = StAXDialectDetector.getDialect(inputFactory.getClass());
inputFactory = dialect.normalize(inputFactory);
// Allow CDATA events
inputFactory = dialect.enableCDataReporting(inputFactory);
inputFactory.setProperty(XMLInputFactory.IS_REPLACING_ENTITY_REFERENCES, Boolean.FALSE);
XMLOutputFactory outputFactory = dialect.normalize(XMLOutputFactory.newInstance());
StreamingOMSerializer serializer = new StreamingOMSerializer();
ByteArrayOutputStream out = new ByteArrayOutputStream();
XMLStreamReader reader = inputFactory.createXMLStreamReader(new StreamSource(file.getUrl().toString()));
String encoding = reader.getEncoding();
XMLStreamWriter writer = outputFactory.createXMLStreamWriter(out, encoding);
writer.writeStartDocument(encoding, reader.getVersion());
serializer.serialize(reader, writer, false);
writer.writeEndDocument();
writer.flush();
InputSource actual = new InputSource();
actual.setByteStream(new ByteArrayInputStream(out.toByteArray()));
actual.setSystemId(file.getUrl().toString());
assertAbout(xml()).that(actual).hasSameContentAs(file.getUrl());
}
use of javax.xml.stream.XMLOutputFactory in project uPortal by Jasig.
the class StAXSerializingComponent method getEventReader.
@Override
public PipelineEventReader<CharacterEventReader, CharacterEvent> getEventReader(HttpServletRequest request, HttpServletResponse response) {
final PipelineEventReader<XMLEventReader, XMLEvent> eventReader = this.wrappedComponent.getEventReader(request, response);
// Writer shared by the ChunkingEventReader and the StAX Serializer
final StringWriter writer = new StringWriter();
final XMLOutputFactory outputFactory = this.xmlUtilities.getHtmlOutputFactory();
final XMLEventWriter xmlEventWriter;
try {
xmlEventWriter = outputFactory.createXMLEventWriter(writer);
} catch (XMLStreamException e) {
throw new RuntimeException("Failed to create XMLEventWriter", e);
}
// Add the chunking wrapper to the XMLEventReader
final XMLEventReader xmlEventReader = eventReader.getEventReader();
final ChunkingEventReader chunkingEventReader = new ChunkingEventReader(request, this.chunkingElements, this.chunkingPatternEventSources, this.chunkingPatterns, xmlEventReader, xmlEventWriter, writer);
try {
xmlEventWriter.add(chunkingEventReader);
xmlEventWriter.flush();
xmlEventWriter.close();
chunkingEventReader.close();
} catch (XMLStreamException e) {
throw new RuntimeException("Failed to write events to Writer", e);
}
// Return the chunked data
final List<CharacterEvent> characterEvents = chunkingEventReader.getCharacterEvents();
final CharacterEventBufferReader characterEventReader = new CharacterEventBufferReader(characterEvents.listIterator());
final Map<String, String> outputProperties = eventReader.getOutputProperties();
return new PipelineEventReaderImpl<CharacterEventReader, CharacterEvent>(characterEventReader, outputProperties);
}
use of javax.xml.stream.XMLOutputFactory in project uPortal by Jasig.
the class XmlUtilitiesImpl method convertToDom.
@Override
public Node convertToDom(XMLEventReader xmlEventReader) throws XMLStreamException {
// Convert the XmlEventReader into a DOM
final XMLOutputFactory xmlOutputFactory = this.getXmlOutputFactory();
final DOMResult sourceDom = new DOMResult(DocumentFactory.getThreadDocument());
final XMLEventWriter sourceWriter = xmlOutputFactory.createXMLEventWriter(sourceDom);
sourceWriter.add(xmlEventReader);
sourceWriter.flush();
sourceWriter.close();
return sourceDom.getNode();
}
use of javax.xml.stream.XMLOutputFactory in project CFLint by cflint.
the class DefaultCFlintResultMarshaller method output.
@Override
public void output(final BugList bugList, final Writer writer, final CFLintStats stats) throws MarshallerException {
try {
final XMLOutputFactory xmlOutputFactory = XMLOutputFactory.newInstance();
XMLStreamWriter xtw = new IndentingXMLStreamWriter(xmlOutputFactory.createXMLStreamWriter(writer));
writeIssues(bugList, xtw, stats);
xtw.flush();
} catch (XMLStreamException e) {
throw new MarshallerException(e);
}
}
use of javax.xml.stream.XMLOutputFactory in project oxCore by GluuFederation.
the class AuthRequest method getStreamedRequest.
public String getStreamedRequest(boolean useBase64) throws XMLStreamException, IOException {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
XMLOutputFactory factory = XMLOutputFactory.newInstance();
XMLStreamWriter writer = factory.createXMLStreamWriter(baos);
writer.writeStartElement("samlp", "AuthnRequest", "urn:oasis:names:tc:SAML:2.0:protocol");
writer.writeNamespace("samlp", "urn:oasis:names:tc:SAML:2.0:protocol");
writer.writeAttribute("ID", id);
writer.writeAttribute("Version", "2.0");
writer.writeAttribute("IssueInstant", this.issueInstant);
writer.writeAttribute("ProtocolBinding", "urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST");
writer.writeAttribute("AssertionConsumerServiceURL", this.samlSettings.getAssertionConsumerServiceUrl());
writer.writeStartElement("saml", "Issuer", "urn:oasis:names:tc:SAML:2.0:assertion");
writer.writeNamespace("saml", "urn:oasis:names:tc:SAML:2.0:assertion");
writer.writeCharacters(this.samlSettings.getIssuer());
writer.writeEndElement();
writer.writeStartElement("samlp", "NameIDPolicy", "urn:oasis:names:tc:SAML:2.0:protocol");
writer.writeNamespace("samlp", "urn:oasis:names:tc:SAML:2.0:protocol");
writer.writeAttribute("Format", this.samlSettings.getNameIdentifierFormat());
writer.writeAttribute("AllowCreate", "true");
writer.writeEndElement();
writer.writeStartElement("samlp", "RequestedAuthnContext", "urn:oasis:names:tc:SAML:2.0:protocol");
writer.writeNamespace("samlp", "urn:oasis:names:tc:SAML:2.0:protocol");
writer.writeAttribute("Comparison", "exact");
writer.writeStartElement("saml", "AuthnContextClassRef", "urn:oasis:names:tc:SAML:2.0:assertion");
writer.writeNamespace("saml", "urn:oasis:names:tc:SAML:2.0:assertion");
writer.writeCharacters("urn:oasis:names:tc:SAML:2.0:ac:classes:PasswordProtectedTransport");
writer.writeEndElement();
writer.writeEndElement();
writer.writeEndElement();
writer.flush();
if (LOG.isDebugEnabled()) {
LOG.debug("Genereated Saml Request " + new String(baos.toByteArray(), "UTF-8"));
}
if (useBase64) {
byte[] deflated = CompressionHelper.deflate(baos.toByteArray(), true);
String base64 = Base64.encodeBase64String(deflated);
String encoded = URLEncoder.encode(base64, "UTF-8");
return encoded;
}
return new String(baos.toByteArray(), "UTF-8");
}
Aggregations