Search in sources :

Example 1 with AccessorException

use of com.sun.xml.bind.api.AccessorException in project X-Road by nordic-institute.

the class SoapParserImpl method unmarshalHeader.

@SuppressWarnings("unchecked")
static <T> T unmarshalHeader(Class<?> clazz, SOAPHeader soapHeader, boolean checkRequiredFields) throws Exception {
    Unmarshaller unmarshaller = JaxbUtils.createUnmarshaller(clazz);
    if (checkRequiredFields) {
        unmarshaller.setListener(new RequiredHeaderFieldsChecker(clazz));
    }
    unmarshaller.setEventHandler(event -> {
        switch(event.getSeverity()) {
            case ValidationEvent.WARNING:
                return true;
            case ValidationEvent.ERROR:
                Throwable t = event.getLinkedException();
                return !(t instanceof AccessorException && t.getCause() instanceof CodedException);
            case ValidationEvent.FATAL_ERROR:
                return false;
            default:
                return true;
        }
    });
    JAXBElement<T> jaxbElement = (JAXBElement<T>) unmarshaller.unmarshal(soapHeader, clazz);
    return jaxbElement.getValue();
}
Also used : CodedException(ee.ria.xroad.common.CodedException) AccessorException(com.sun.xml.bind.api.AccessorException) JAXBElement(javax.xml.bind.JAXBElement) Unmarshaller(javax.xml.bind.Unmarshaller)

Aggregations

AccessorException (com.sun.xml.bind.api.AccessorException)1 CodedException (ee.ria.xroad.common.CodedException)1 JAXBElement (javax.xml.bind.JAXBElement)1 Unmarshaller (javax.xml.bind.Unmarshaller)1