Search in sources :

Example 16 with XMLOutputFactory

use of javax.xml.stream.XMLOutputFactory in project OpenAttestation by OpenAttestation.

the class TAHelper method getHostAttestationReport.

// hostName == internetAddress.toString() or Hostname.toString() or IPAddress.toString()
// vmmName == tblHosts.getVmmMleId().getName()
public String getHostAttestationReport(String hostName, HashMap<String, PcrManifest> pcrManifestMap, String vmmName) throws Exception {
    XMLOutputFactory xof = XMLOutputFactory.newInstance();
    XMLStreamWriter xtw;
    StringWriter sw = new StringWriter();
    /*
            // We need to check if the host supports TPM or not. Only way we can do it
            // using the host table contents is by looking at the AIK Certificate. Based
            // on this flag we generate the attestation report.
            boolean tpmSupport = true;
            String hostType = "";

            if (tblHosts.getAIKCertificate() == null || tblHosts.getAIKCertificate().isEmpty()) {
                tpmSupport = false;
            }
            * */
    // XXX   assuming it supports TPM since it's trust agent and we got a pcr manifest (which we only get from getQuoteInformationFromHost if the tpm quote was verified, which means we saved the AIK certificate when we did that)
    boolean tpmSupport = true;
    // xtw = xof.createXMLStreamWriter(new FileWriter("c:\\temp\\nb_xml.xml"));
    xtw = xof.createXMLStreamWriter(sw);
    xtw.writeStartDocument();
    xtw.writeStartElement("Host_Attestation_Report");
    xtw.writeAttribute("Host_Name", hostName);
    xtw.writeAttribute("Host_VMM", vmmName);
    xtw.writeAttribute("TXT_Support", String.valueOf(tpmSupport));
    if (tpmSupport == true) {
        ArrayList<IManifest> pcrMFList = new ArrayList<IManifest>();
        pcrMFList.addAll(pcrManifestMap.values());
        for (IManifest pcrInfo : pcrMFList) {
            PcrManifest pInfo = (PcrManifest) pcrInfo;
            xtw.writeStartElement("PCRInfo");
            xtw.writeAttribute("ComponentName", String.valueOf(pInfo.getPcrNumber()));
            xtw.writeAttribute("DigestValue", pInfo.getPcrValue().toUpperCase());
            xtw.writeEndElement();
        }
    } else {
        xtw.writeStartElement("PCRInfo");
        xtw.writeAttribute("Error", "Host does not support TPM.");
        xtw.writeEndElement();
    }
    xtw.writeEndElement();
    xtw.writeEndDocument();
    xtw.flush();
    xtw.close();
    String attestationReport = sw.toString();
    return attestationReport;
}
Also used : XMLOutputFactory(javax.xml.stream.XMLOutputFactory) PcrManifest(com.intel.mountwilson.manifest.data.PcrManifest) XMLStreamWriter(javax.xml.stream.XMLStreamWriter) ArrayList(java.util.ArrayList) IManifest(com.intel.mountwilson.manifest.data.IManifest)

Example 17 with XMLOutputFactory

use of javax.xml.stream.XMLOutputFactory in project uPortal by Jasig.

the class XmlUtilitiesImpl method serializeXMLEvents.

@Override
public String serializeXMLEvents(List<XMLEvent> xmlEvents, boolean isHtml) {
    final XMLOutputFactory outputFactory;
    if (isHtml) {
        outputFactory = this.getHtmlOutputFactory();
    } else {
        outputFactory = this.getXmlOutputFactory();
    }
    final StringWriter writer = new StringWriter();
    final XMLEventWriter xmlEventWriter;
    try {
        xmlEventWriter = new IndentingXMLEventWriter(outputFactory.createXMLEventWriter(writer));
    } catch (XMLStreamException e) {
        throw new RuntimeException("Failed to create XMLEventWriter", e);
    }
    try {
        for (final XMLEvent bufferedEvent : xmlEvents) {
            xmlEventWriter.add(bufferedEvent);
        }
        xmlEventWriter.flush();
        xmlEventWriter.close();
    } catch (XMLStreamException e) {
        throw new RuntimeException("Failed to write XMLEvents to XMLEventWriter", e);
    }
    return writer.toString();
}
Also used : XMLOutputFactory(javax.xml.stream.XMLOutputFactory) StringWriter(java.io.StringWriter) XMLStreamException(javax.xml.stream.XMLStreamException) XMLEventWriter(javax.xml.stream.XMLEventWriter) IndentingXMLEventWriter(org.apereo.portal.xml.stream.IndentingXMLEventWriter) IndentingXMLEventWriter(org.apereo.portal.xml.stream.IndentingXMLEventWriter) XMLEvent(javax.xml.stream.events.XMLEvent)

Example 18 with XMLOutputFactory

use of javax.xml.stream.XMLOutputFactory in project uPortal by Jasig.

the class XSLTComponentTest method serializeXMLEventReader.

protected String serializeXMLEventReader(XMLEventReader reader) {
    final StringWriter writer = new StringWriter();
    final XMLOutputFactory outputFactory = XMLOutputFactory.newInstance();
    outputFactory.setProperty("javax.xml.stream.isRepairingNamespaces", true);
    final XMLEventWriter xmlEventWriter;
    try {
        xmlEventWriter = outputFactory.createXMLEventWriter(writer);
    } catch (XMLStreamException e) {
        throw new RuntimeException("Failed to create XMLEventWriter", e);
    }
    try {
        xmlEventWriter.setDefaultNamespace("http://www.w3.org/1999/xhtml");
        xmlEventWriter.add(reader);
        xmlEventWriter.flush();
        xmlEventWriter.close();
    } catch (XMLStreamException e) {
        throw new RuntimeException("Failed to write events to Writer", e);
    }
    return writer.toString();
}
Also used : XMLOutputFactory(javax.xml.stream.XMLOutputFactory) StringWriter(java.io.StringWriter) XMLStreamException(javax.xml.stream.XMLStreamException) XMLEventWriter(javax.xml.stream.XMLEventWriter)

Example 19 with XMLOutputFactory

use of javax.xml.stream.XMLOutputFactory in project webservices-axiom by apache.

the class TestSetPrefixScope method runTest.

protected void runTest() throws Throwable {
    XMLOutputFactory factory = staxImpl.newNormalizedXMLOutputFactory();
    XMLStreamWriter writer = factory.createXMLStreamWriter(new ByteArrayOutputStream());
    writer.writeStartDocument();
    writer.writeStartElement("root");
    writer.setPrefix("p", "urn:ns");
    writer.writeStartElement("child");
    assertEquals("p", writer.getPrefix("urn:ns"));
    writer.writeEndElement();
    assertEquals("p", writer.getPrefix("urn:ns"));
    writer.writeEndElement();
    writer.writeEndDocument();
    writer.close();
}
Also used : XMLOutputFactory(javax.xml.stream.XMLOutputFactory) XMLStreamWriter(javax.xml.stream.XMLStreamWriter) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 20 with XMLOutputFactory

use of javax.xml.stream.XMLOutputFactory in project webservices-axiom by apache.

the class TestCreateXMLEventWriterWithNullEncoding method runTest.

protected void runTest() throws Throwable {
    XMLOutputFactory factory = staxImpl.newNormalizedXMLOutputFactory();
    // This should cause an exception
    try {
        factory.createXMLEventWriter(System.out, null);
    } catch (Throwable ex) {
        // Expected
        return;
    }
    // Attention here: since the fail method works by throwing an exception and we
    // catch Throwable, it must be invoked outside of the catch block!
    fail("Expected createXMLEventWriter to throw an exception");
}
Also used : XMLOutputFactory(javax.xml.stream.XMLOutputFactory)

Aggregations

XMLOutputFactory (javax.xml.stream.XMLOutputFactory)42 XMLStreamWriter (javax.xml.stream.XMLStreamWriter)28 StringWriter (java.io.StringWriter)18 XMLStreamException (javax.xml.stream.XMLStreamException)15 XMLEventWriter (javax.xml.stream.XMLEventWriter)9 ByteArrayOutputStream (java.io.ByteArrayOutputStream)8 Test (org.junit.Test)8 StAXResult (javax.xml.transform.stax.StAXResult)7 IOException (java.io.IOException)6 DOMResult (javax.xml.transform.dom.DOMResult)6 StreamResult (javax.xml.transform.stream.StreamResult)6 Result (javax.xml.transform.Result)5 PcrManifest (com.intel.mountwilson.manifest.data.PcrManifest)3 OutputStream (java.io.OutputStream)3 SAXResult (javax.xml.transform.sax.SAXResult)3 IManifest (com.intel.mountwilson.manifest.data.IManifest)2 Headers (com.sun.net.httpserver.Headers)2 OutputStreamWriter (java.io.OutputStreamWriter)2 InetSocketAddress (java.net.InetSocketAddress)2 Path (java.nio.file.Path)2