FasterXML / woodstox

The gold standard Stax XML API implementation. Now at Github.
Apache License 2.0
220 stars 81 forks source link

Not able to write xml to azure blob storage #178

Closed pavansinguluri closed 11 months ago

pavansinguluri commented 11 months ago

woodstox-core:6.5.0 I am writing to a xml file in azure blob storage using the below code

` @Service @Slf4j public class Test { private final ResourceLoader resourceLoader; private final String containerName; private static final String BLOB_RESOURCE_PATTERN = "azure-blob://%s/%s";

public Test(ResourceLoader resourceLoader,
            @Value("${spring.cloud.azure.storage.blob.container-name}") String containerName) {
    this.resourceLoader = resourceLoader;
    this.containerName = containerName;
}

public void launchXmlStreamWriter() {
    AtomicInteger counter = new AtomicInteger(0);
    Resource writeResource = resourceLoader.getResource(String.format(BLOB_RESOURCE_PATTERN, containerName, "9898-tet-out.xml"));

    try {
        OutputStream outputStream = ((WritableResource) writeResource).getOutputStream();
        // OutputStream outputStream = new FileSystemResource("out.xml").getOutputStream();

        XMLStreamWriter xmlOut = XMLOutputFactory.newFactory().createXMLStreamWriter(outputStream);
        xmlOut.writeStartDocument();
        xmlOut.writeStartElement("rootElement");

        JAXBContext context = JAXBContext.newInstance(Verification.class);
        Marshaller marshaller = context.createMarshaller();
        marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
        marshaller.setProperty(Marshaller.JAXB_FRAGMENT, Boolean.TRUE);

        Verification verification = prepareVerification();
        marshaller.marshal(verification, xmlOut);

        xmlOut.flush();
        xmlOut.close();
    } catch (Throwable e) {
        throw new RuntimeException(e);
    }
}

private Verification prepareVerification() {
    Verification verification = new Verification();
    return verification;
}

} `

Program exits without error but no file is created on blob storage. If i use FileSystemResource then it creates a file on my local system.Is it something i am doing wrong or its an issue with version

cowtowncoder commented 11 months ago

Something may be wrong but info you include is not enough to have any idea what might be happening, where.

I cannot really help without some more information: stack trace or such. It is not really clear problem has anything to do with Woodstox for example.

Closing; may be reopened with actual info on how to reproduce the problem.