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;
}
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;
}
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;
}
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);
}
}
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);
}
Aggregations