use of javax.xml.stream.XMLOutputFactory in project webservices-axiom by apache.
the class StAXUtils method getXMLOutputFactory.
/**
* Get a cached {@link XMLOutputFactory} instance using the specified configuration.
*
* @param configuration
* the configuration applied to the requested factory
* @return an {@link XMLOutputFactory} instance.
* @deprecated
*/
public static XMLOutputFactory getXMLOutputFactory(StAXWriterConfiguration configuration) {
if (configuration == null) {
configuration = StAXWriterConfiguration.DEFAULT;
}
XMLOutputFactory f = outputFactoryMap.get(configuration);
if (f == null) {
f = newXMLOutputFactory(StAXUtils.class.getClassLoader(), configuration);
outputFactoryMap.put(configuration, f);
if (log.isDebugEnabled()) {
if (f != null) {
log.debug("Created singleton XMLOutputFactory " + f.getClass() + " with configuration " + configuration);
}
}
}
return f;
}
use of javax.xml.stream.XMLOutputFactory in project simba-os by cegeka.
the class SAMLServiceImpl method createLogoutRequest.
@Override
public String createLogoutRequest(String logoutRequestId, Date issueInstant, String nameId, String sessionIndex) throws XMLStreamException, IOException {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
XMLOutputFactory factory = XMLOutputFactory.newInstance();
XMLStreamWriter writer = factory.createXMLStreamWriter(baos);
writer.writeStartElement("samlp", "LogoutRequest", NS_SAMLP);
writer.writeNamespace("samlp", NS_SAMLP);
writer.writeAttribute("ID", "_" + logoutRequestId);
writer.writeAttribute("Version", "2.0");
writer.writeAttribute("IssueInstant", SAML_DATE_FORMAT.format(issueInstant));
writer.writeStartElement("saml", "Issuer", NS_SAML);
writer.writeNamespace("saml", NS_SAML);
writer.writeCharacters("https://iamapps.belgium.be/");
writer.writeEndElement();
writer.writeStartElement("saml", "NameID", NS_SAML);
writer.writeNamespace("saml", NS_SAML);
writer.writeAttribute("NameQualifier", configurationService.getValue(SimbaConfigurationParameter.SAML_IDP_SLO_TARGET_URL));
writer.writeAttribute("SPNameQualifier", "https://iamapps.belgium.be/");
writer.writeAttribute("Format", NAMEID_TRANSIENT);
writer.writeCharacters(nameId);
writer.writeEndElement();
writer.writeStartElement("samlp", "SessionIndex", NS_SAMLP);
writer.writeNamespace("saml", NS_SAMLP);
writer.writeCharacters(sessionIndex);
writer.writeEndElement();
writer.writeEndElement();
writer.flush();
return encodeSAMLRequest(baos.toByteArray());
}
use of javax.xml.stream.XMLOutputFactory in project simba-os by cegeka.
the class SAMLServiceImpl method createAuthRequest.
@Override
public String createAuthRequest(String authRequestId, Date issueInstant) throws XMLStreamException, IOException {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
XMLOutputFactory factory = XMLOutputFactory.newInstance();
XMLStreamWriter writer = factory.createXMLStreamWriter(baos);
writer.writeStartElement("samlp", "AuthnRequest", NS_SAMLP);
writer.writeNamespace("samlp", NS_SAMLP);
writer.writeAttribute("ID", "_" + authRequestId);
writer.writeAttribute("Version", "2.0");
writer.writeAttribute("IssueInstant", SAML_DATE_FORMAT.format(issueInstant));
writer.writeAttribute("ForceAuthn", "false");
writer.writeAttribute("IsPassive", "false");
writer.writeAttribute("ProtocolBinding", BINDING_HTTP_POST);
writer.writeAttribute("AssertionConsumerServiceURL", configurationService.getValue(SimbaConfigurationParameter.SAML_ASSERTION_CONSUMER_SERVICE_URL));
writer.writeStartElement("saml", "Issuer", NS_SAML);
writer.writeNamespace("saml", NS_SAML);
writer.writeCharacters(configurationService.getValue(SimbaConfigurationParameter.SAML_ISSUER));
writer.writeEndElement();
writer.writeStartElement("samlp", "NameIDPolicy", NS_SAMLP);
writer.writeAttribute("Format", NAMEID_TRANSIENT);
writer.writeAttribute("SPNameQualifier", configurationService.getValue(SimbaConfigurationParameter.SAML_ISSUER));
writer.writeAttribute("AllowCreate", "true");
writer.writeEndElement();
writer.writeStartElement("samlp", "RequestedAuthnContext", NS_SAMLP);
writer.writeNamespace("samlp", NS_SAMLP);
writer.writeAttribute("Comparison", "exact");
writer.writeStartElement("saml", "AuthnContextClassRef", NS_SAML);
writer.writeNamespace("saml", NS_SAML);
writer.writeCharacters(AC_FAS_EID);
writer.writeEndElement();
writer.writeEndElement();
writer.writeEndElement();
writer.flush();
return encodeSAMLRequest(baos.toByteArray());
}
use of javax.xml.stream.XMLOutputFactory in project dhis2-core by dhis2.
the class DefaultAdxDataService method saveDataValueSetInternal.
private ImportSummary saveDataValueSetInternal(InputStream in, ImportOptions importOptions, TaskId id) {
notifier.clear(id).notify(id, "ADX parsing process started");
ImportOptions adxImportOptions = ObjectUtils.firstNonNull(importOptions, ImportOptions.getDefaultImportOptions()).instance().setNotificationLevel(NotificationLevel.OFF);
// Get import options
IdScheme dataSetIdScheme = importOptions.getIdSchemes().getDataSetIdScheme();
IdScheme dataElementIdScheme = importOptions.getIdSchemes().getDataElementIdScheme();
// Create meta-data maps
CachingMap<String, DataSet> dataSetMap = new CachingMap<>();
CachingMap<String, DataElement> dataElementMap = new CachingMap<>();
// Get meta-data maps
IdentifiableObjectCallable<DataSet> dataSetCallable = new IdentifiableObjectCallable<>(identifiableObjectManager, DataSet.class, dataSetIdScheme, null);
IdentifiableObjectCallable<DataElement> dataElementCallable = new IdentifiableObjectCallable<>(identifiableObjectManager, DataElement.class, dataElementIdScheme, null);
// Heat cache
if (importOptions.isPreheatCacheDefaultFalse()) {
dataSetMap.load(identifiableObjectManager.getAll(DataSet.class), o -> o.getPropertyValue(dataSetIdScheme));
dataElementMap.load(identifiableObjectManager.getAll(DataElement.class), o -> o.getPropertyValue(dataElementIdScheme));
}
XMLReader adxReader = XMLFactory.getXMLReader(in);
ImportSummary importSummary;
adxReader.moveToStartElement(AdxDataService.ROOT, AdxDataService.NAMESPACE);
ExecutorService executor = Executors.newSingleThreadExecutor();
// Give the DXF import a different notification task ID so it doesn't conflict with notifications from this level.
TaskId dxfTaskId = new TaskId(TaskCategory.DATAVALUE_IMPORT_INTERNAL, id.getUser());
int groupCount = 0;
try (PipedOutputStream pipeOut = new PipedOutputStream()) {
Future<ImportSummary> futureImportSummary = executor.submit(new AdxPipedImporter(dataValueSetService, adxImportOptions, dxfTaskId, pipeOut, sessionFactory));
XMLOutputFactory factory = XMLOutputFactory.newInstance();
XMLStreamWriter dxfWriter = factory.createXMLStreamWriter(pipeOut);
List<ImportConflict> adxConflicts = new LinkedList<>();
dxfWriter.writeStartDocument("1.0");
dxfWriter.writeStartElement("dataValueSet");
dxfWriter.writeDefaultNamespace("http://dhis2.org/schema/dxf/2.0");
notifier.notify(id, "Starting to import ADX data groups.");
while (adxReader.moveToStartElement(AdxDataService.GROUP, AdxDataService.NAMESPACE)) {
notifier.update(id, "Importing ADX data group: " + groupCount);
// note this returns conflicts which are detected at ADX level
adxConflicts.addAll(parseAdxGroupToDxf(adxReader, dxfWriter, adxImportOptions, dataSetMap, dataSetCallable, dataElementMap, dataElementCallable));
groupCount++;
}
// end dataValueSet
dxfWriter.writeEndElement();
dxfWriter.writeEndDocument();
pipeOut.flush();
importSummary = futureImportSummary.get(TOTAL_MINUTES_TO_WAIT, TimeUnit.MINUTES);
importSummary.getConflicts().addAll(adxConflicts);
importSummary.getImportCount().incrementIgnored(adxConflicts.size());
} catch (AdxException ex) {
importSummary = new ImportSummary();
importSummary.setStatus(ImportStatus.ERROR);
importSummary.setDescription("Data set import failed within group number: " + groupCount);
importSummary.getConflicts().add(ex.getImportConflict());
notifier.update(id, NotificationLevel.ERROR, "ADX data import done", true);
log.warn("Import failed: " + DebugUtils.getStackTrace(ex));
} catch (IOException | XMLStreamException | InterruptedException | ExecutionException | TimeoutException ex) {
importSummary = new ImportSummary();
importSummary.setStatus(ImportStatus.ERROR);
importSummary.setDescription("Data set import failed within group number: " + groupCount);
notifier.update(id, NotificationLevel.ERROR, "ADX data import done", true);
log.warn("Import failed: " + DebugUtils.getStackTrace(ex));
}
executor.shutdown();
notifier.update(id, INFO, "ADX data import done", true).addTaskSummary(id, importSummary);
ImportCount c = importSummary.getImportCount();
log.info("ADX data import done, imported: " + c.getImported() + ", updated: " + c.getUpdated() + ", deleted: " + c.getDeleted() + ", ignored: " + c.getIgnored());
return importSummary;
}
use of javax.xml.stream.XMLOutputFactory in project elasticsearch by elastic.
the class AzureDiscoveryClusterFormationTests method startHttpd.
/**
* Creates mock EC2 endpoint providing the list of started nodes to the DescribeInstances API call
*/
@BeforeClass
public static void startHttpd() throws Exception {
logDir = createTempDir();
SSLContext sslContext = getSSLContext();
httpsServer = MockHttpServer.createHttps(new InetSocketAddress(InetAddress.getLoopbackAddress().getHostAddress(), 0), 0);
httpsServer.setHttpsConfigurator(new HttpsConfigurator(sslContext));
httpsServer.createContext("/subscription/services/hostedservices/myservice", (s) -> {
Headers headers = s.getResponseHeaders();
headers.add("Content-Type", "text/xml; charset=UTF-8");
XMLOutputFactory xmlOutputFactory = XMLOutputFactory.newFactory();
xmlOutputFactory.setProperty(XMLOutputFactory.IS_REPAIRING_NAMESPACES, true);
StringWriter out = new StringWriter();
XMLStreamWriter sw;
try {
sw = xmlOutputFactory.createXMLStreamWriter(out);
sw.writeStartDocument();
String namespace = "http://schemas.microsoft.com/windowsazure";
sw.setDefaultNamespace(namespace);
sw.writeStartElement(XMLConstants.DEFAULT_NS_PREFIX, "HostedService", namespace);
{
sw.writeStartElement("Deployments");
{
Path[] files = FileSystemUtils.files(logDir);
for (int i = 0; i < files.length; i++) {
Path resolve = files[i].resolve("transport.ports");
if (Files.exists(resolve)) {
List<String> addresses = Files.readAllLines(resolve);
Collections.shuffle(addresses, random());
String address = addresses.get(0);
int indexOfLastColon = address.lastIndexOf(':');
String host = address.substring(0, indexOfLastColon);
String port = address.substring(indexOfLastColon + 1);
sw.writeStartElement("Deployment");
{
sw.writeStartElement("Name");
sw.writeCharacters("mydeployment");
sw.writeEndElement();
sw.writeStartElement("DeploymentSlot");
sw.writeCharacters(DeploymentSlot.Production.name());
sw.writeEndElement();
sw.writeStartElement("Status");
sw.writeCharacters(DeploymentStatus.Running.name());
sw.writeEndElement();
sw.writeStartElement("RoleInstanceList");
{
sw.writeStartElement("RoleInstance");
{
sw.writeStartElement("RoleName");
sw.writeCharacters(UUID.randomUUID().toString());
sw.writeEndElement();
sw.writeStartElement("IpAddress");
sw.writeCharacters(host);
sw.writeEndElement();
sw.writeStartElement("InstanceEndpoints");
{
sw.writeStartElement("InstanceEndpoint");
{
sw.writeStartElement("Name");
sw.writeCharacters("myendpoint");
sw.writeEndElement();
sw.writeStartElement("Vip");
sw.writeCharacters(host);
sw.writeEndElement();
sw.writeStartElement("PublicPort");
sw.writeCharacters(port);
sw.writeEndElement();
}
sw.writeEndElement();
}
sw.writeEndElement();
}
sw.writeEndElement();
}
sw.writeEndElement();
}
sw.writeEndElement();
}
}
}
sw.writeEndElement();
}
sw.writeEndElement();
sw.writeEndDocument();
sw.flush();
final byte[] responseAsBytes = out.toString().getBytes(StandardCharsets.UTF_8);
s.sendResponseHeaders(200, responseAsBytes.length);
OutputStream responseBody = s.getResponseBody();
responseBody.write(responseAsBytes);
responseBody.close();
} catch (XMLStreamException e) {
Loggers.getLogger(AzureDiscoveryClusterFormationTests.class).error("Failed serializing XML", e);
throw new RuntimeException(e);
}
});
httpsServer.start();
}
Aggregations