Search in sources :

Example 6 with XMLStreamWriter

use of javax.xml.stream.XMLStreamWriter in project qi4j-sdk by Qi4j.

the class StaxValueSerializer method adaptOutput.

@Override
protected XMLStreamWriter adaptOutput(OutputStream output) throws Exception {
    XMLStreamWriter xmlStreamWriter = outputFactory.createXMLStreamWriter(output, "UTF-8");
    xmlStreamWriter.writeStartDocument("utf-8", "1.1");
    return xmlStreamWriter;
}
Also used : XMLStreamWriter(javax.xml.stream.XMLStreamWriter)

Example 7 with XMLStreamWriter

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

the class ReportsBO method getHostAttestationReport.

// BUG #497 XXX TODO needs rewrite to use HostAgentFactory and HostAgent interfaces
public String getHostAttestationReport(Hostname hostName) {
    XMLOutputFactory xof = XMLOutputFactory.newInstance();
    XMLStreamWriter xtw;
    StringWriter sw = new StringWriter();
    IManifestStrategy manifestStrategy;
    IManifestStrategyFactory strategyFactory;
    HashMap<String, ? extends IManifest> pcrManifestMap = null;
    TblHosts tblHosts = null;
    String attestationReport = "";
    try {
        tblHosts = getTblHostsJpaController().findByName(hostName.toString());
        if (tblHosts == null) {
            throw new ASException(ErrorCode.AS_HOST_NOT_FOUND, hostName.toString());
        }
        manifestStrategy = getManifestStrategy(tblHosts);
        // BUG #497  this is now obtained by IntelHostAgent using TAHelper's getQuoteInformationForHost which is what was called by TrustAgentManifestStrategy.getManifest()
        pcrManifestMap = manifestStrategy.getManifest(tblHosts);
    } catch (ASException aex) {
        throw aex;
    } catch (CryptographyException e) {
        throw new ASException(e, ErrorCode.AS_ENCRYPTION_ERROR, e.getCause() == null ? e.getMessage() : e.getCause().getMessage());
    } catch (Exception ex) {
        throw new ASException(ex);
    }
    try {
        // XXX BUG #497 this entire section in try{}catch{} has  moved to TAHelper and used by IntelHostAgent
        // 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 = tblHosts.getVmmMleId().getName();
        if (tblHosts.getAIKCertificate() == null || tblHosts.getAIKCertificate().isEmpty()) {
            tpmSupport = false;
        }
        // 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.toString());
        xtw.writeAttribute("Host_VMM", hostType);
        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();
        attestationReport = sw.toString();
    } catch (Exception ex) {
        throw new ASException(ex);
    }
    return attestationReport;
}
Also used : IManifestStrategy(com.intel.mountwilson.manifest.IManifestStrategy) XMLOutputFactory(javax.xml.stream.XMLOutputFactory) IManifestStrategyFactory(com.intel.mountwilson.manifest.IManifestStrategyFactory) ASException(com.intel.mountwilson.as.common.ASException) CryptographyException(com.intel.mtwilson.crypto.CryptographyException) IOException(java.io.IOException) StringWriter(java.io.StringWriter) CryptographyException(com.intel.mtwilson.crypto.CryptographyException) PcrManifest(com.intel.mountwilson.manifest.data.PcrManifest) TblPcrManifest(com.intel.mtwilson.as.data.TblPcrManifest) XMLStreamWriter(javax.xml.stream.XMLStreamWriter) TblHosts(com.intel.mtwilson.as.data.TblHosts) ASException(com.intel.mountwilson.as.common.ASException) IManifest(com.intel.mountwilson.manifest.data.IManifest)

Example 8 with XMLStreamWriter

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

the class CitrixHostAgent method getHostAttestationReport.

public String getHostAttestationReport(String pcrList) throws IOException {
    String attestationReport = "";
    XMLOutputFactory xof = XMLOutputFactory.newInstance();
    XMLStreamWriter xtw;
    StringWriter sw = new StringWriter();
    try {
        xtw = xof.createXMLStreamWriter(sw);
        xtw.writeStartDocument();
        xtw.writeStartElement("Host_Attestation_Report");
        xtw.writeAttribute("Host_Name", this.client.hostIpAddress);
        xtw.writeAttribute("vCenterVersion", "5.0");
        xtw.writeAttribute("HostVersion", "5.0");
        //xtw.writeAttribute("TXT_Support", tpmSupport.toString());
        HashMap<String, PcrManifest> pcrMap = client.getQuoteInformationForHost(pcrList);
        Iterator it = pcrMap.entrySet().iterator();
        while (it.hasNext()) {
            Map.Entry pairs = (Map.Entry) it.next();
            xtw.writeStartElement("PCRInfo");
            PcrManifest pcr = (PcrManifest) pairs.getValue();
            xtw.writeAttribute("ComponentName", Integer.toString(pcr.getPcrNumber()));
            xtw.writeAttribute("DigestValue", pcr.getPcrValue());
            xtw.writeEndElement();
            // avoids a ConcurrentModificationException
            it.remove();
        }
        xtw.writeEndElement();
        xtw.writeEndDocument();
        xtw.flush();
        xtw.close();
        attestationReport = sw.toString();
    } catch (XMLStreamException ex) {
        //            Logger.getLogger(CitrixHostAgent.class.getName()).log(Level.SEVERE, null, ex);
        log.error("Cannot get host attestation report", ex);
    }
    log.debug("getHostAttestationReport report:" + attestationReport);
    return attestationReport;
}
Also used : XMLOutputFactory(javax.xml.stream.XMLOutputFactory) StringWriter(java.io.StringWriter) XMLStreamException(javax.xml.stream.XMLStreamException) PcrManifest(com.intel.mountwilson.manifest.data.PcrManifest) XMLStreamWriter(javax.xml.stream.XMLStreamWriter) Iterator(java.util.Iterator) HashMap(java.util.HashMap) Map(java.util.Map)

Example 9 with XMLStreamWriter

use of javax.xml.stream.XMLStreamWriter in project jersey by jersey.

the class JettisonListElementProvider method writeCollection.

@Override
public final void writeCollection(Class<?> elementType, Collection<?> t, MediaType mediaType, Charset c, Marshaller m, OutputStream entityStream) throws JAXBException, IOException {
    final OutputStreamWriter osw = new OutputStreamWriter(entityStream, c);
    JettisonConfig origJsonConfig = JettisonConfig.DEFAULT;
    if (m instanceof JettisonConfigured) {
        origJsonConfig = ((JettisonConfigured) m).getJSONConfiguration();
    }
    final JettisonConfig unwrappingJsonConfig = JettisonConfig.createJSONConfiguration(origJsonConfig);
    final XMLStreamWriter jxsw = Stax2JettisonFactory.createWriter(osw, unwrappingJsonConfig);
    final String invisibleRootName = getRootElementName(elementType);
    try {
        jxsw.writeStartDocument();
        jxsw.writeStartElement(invisibleRootName);
        for (Object o : t) {
            m.marshal(o, jxsw);
        }
        jxsw.writeEndElement();
        jxsw.writeEndDocument();
        jxsw.flush();
    } catch (XMLStreamException ex) {
        Logger.getLogger(JettisonListElementProvider.class.getName()).log(Level.SEVERE, null, ex);
        throw new JAXBException(ex.getMessage(), ex);
    }
}
Also used : XMLStreamException(javax.xml.stream.XMLStreamException) JettisonConfigured(org.glassfish.jersey.jettison.JettisonConfigured) XMLStreamWriter(javax.xml.stream.XMLStreamWriter) JAXBException(javax.xml.bind.JAXBException) JettisonConfig(org.glassfish.jersey.jettison.JettisonConfig) OutputStreamWriter(java.io.OutputStreamWriter)

Example 10 with XMLStreamWriter

use of javax.xml.stream.XMLStreamWriter in project spring-framework by spring-projects.

the class StaxStreamHandlerTests method createStaxHandler.

@Override
protected AbstractStaxHandler createStaxHandler(Result result) throws XMLStreamException {
    XMLOutputFactory outputFactory = XMLOutputFactory.newFactory();
    XMLStreamWriter streamWriter = outputFactory.createXMLStreamWriter(result);
    return new StaxStreamHandler(streamWriter);
}
Also used : XMLOutputFactory(javax.xml.stream.XMLOutputFactory) XMLStreamWriter(javax.xml.stream.XMLStreamWriter)

Aggregations

XMLStreamWriter (javax.xml.stream.XMLStreamWriter)82 XMLStreamException (javax.xml.stream.XMLStreamException)36 XMLOutputFactory (javax.xml.stream.XMLOutputFactory)28 StringWriter (java.io.StringWriter)15 ByteArrayOutputStream (java.io.ByteArrayOutputStream)14 IOException (java.io.IOException)12 XmlWriter (org.apache.aries.blueprint.plugin.spi.XmlWriter)7 OutputStream (java.io.OutputStream)6 StAXResult (javax.xml.transform.stax.StAXResult)6 Test (org.junit.Test)6 OutputStreamWriter (java.io.OutputStreamWriter)5 JAXBException (javax.xml.bind.JAXBException)5 StreamResult (javax.xml.transform.stream.StreamResult)5 ZipEntry (java.util.zip.ZipEntry)4 XMLStreamReader (javax.xml.stream.XMLStreamReader)4 PcrManifest (com.intel.mountwilson.manifest.data.PcrManifest)3 StringReader (java.io.StringReader)3 ToXmlGenerator (com.fasterxml.jackson.dataformat.xml.ser.ToXmlGenerator)2 IManifest (com.intel.mountwilson.manifest.data.IManifest)2 Headers (com.sun.net.httpserver.Headers)2