Example usage for org.springframework.oxm MarshallingFailureException getMostSpecificCause

List of usage examples for org.springframework.oxm MarshallingFailureException getMostSpecificCause

Introduction

In this page you can find the example usage for org.springframework.oxm MarshallingFailureException getMostSpecificCause.

Prototype

public Throwable getMostSpecificCause() 

Source Link

Document

Retrieve the most specific cause of this exception, that is, either the innermost cause (root cause) or this exception itself.

Usage

From source file:no.digipost.signature.client.asice.manifest.ManifestCreator.java

public Manifest createManifest(JOB job, Sender sender) {
    Object xmlManifest = buildXmlManifest(job, sender);

    try (ByteArrayOutputStream manifestStream = new ByteArrayOutputStream()) {
        marshal(xmlManifest, manifestStream);
        return new Manifest(manifestStream.toByteArray());
    } catch (MarshallingFailureException e) {
        if (e.getMostSpecificCause() instanceof SAXParseException) {
            throw new XmlValidationException("Unable to validate generated Manifest XML. "
                    + "This typically happens if one or more values are not in accordance with the XSD. "
                    + "You may inspect the cause (by calling getCause()) to see which constraint has been violated.",
                    (SAXParseException) e.getMostSpecificCause());
        }/*from  w w w  . ja  v a  2s . c  o m*/
        throw e;
    } catch (IOException e) {
        throw new RuntimeIOException(e);
    }
}

From source file:no.difi.sdp.client.asice.manifest.CreateManifest.java

public Manifest createManifest(Forsendelse forsendelse) {
    SDPManifest sdpManifest = sdpBuilder.createManifest(forsendelse);

    ByteArrayOutputStream manifestStream = new ByteArrayOutputStream();
    try {/*ww  w . ja v  a2 s  .com*/
        marshaller.marshal(sdpManifest, new StreamResult(manifestStream));
        return new Manifest(manifestStream.toByteArray());
    } catch (MarshallingFailureException e) {
        if (e.getMostSpecificCause() instanceof SAXParseException) {
            throw new XmlValideringException(
                    "Kunne ikke validere generert Manifest XML. Sjekk at alle pkrevde input er satt og ikke er null",
                    SendException.AntattSkyldig.KLIENT, (SAXParseException) e.getMostSpecificCause());
        }

        throw e;
    }

}