Search in sources :

Example 1 with UnmarshallingFailureException

use of org.springframework.oxm.UnmarshallingFailureException in project spring-framework by spring-projects.

the class MarshallingHttpMessageConverterTests method readWithMarshallingFailureException.

@Test
public void readWithMarshallingFailureException() throws Exception {
    MockHttpInputMessage inputMessage = new MockHttpInputMessage(new byte[0]);
    UnmarshallingFailureException ex = new UnmarshallingFailureException("forced");
    Unmarshaller unmarshaller = mock(Unmarshaller.class);
    given(unmarshaller.unmarshal(isA(StreamSource.class))).willThrow(ex);
    MarshallingHttpMessageConverter converter = new MarshallingHttpMessageConverter();
    converter.setUnmarshaller(unmarshaller);
    assertThatExceptionOfType(HttpMessageNotReadableException.class).isThrownBy(() -> converter.read(Object.class, inputMessage)).withCause(ex);
}
Also used : MockHttpInputMessage(org.springframework.http.MockHttpInputMessage) StreamSource(javax.xml.transform.stream.StreamSource) UnmarshallingFailureException(org.springframework.oxm.UnmarshallingFailureException) Unmarshaller(org.springframework.oxm.Unmarshaller) Test(org.junit.jupiter.api.Test)

Example 2 with UnmarshallingFailureException

use of org.springframework.oxm.UnmarshallingFailureException in project spring-framework by spring-projects.

the class CastorMarshaller method unmarshalSaxReader.

@Override
protected Object unmarshalSaxReader(XMLReader xmlReader, InputSource inputSource) throws XmlMappingException, IOException {
    UnmarshalHandler unmarshalHandler = createUnmarshaller().createHandler();
    try {
        ContentHandler contentHandler = Unmarshaller.getContentHandler(unmarshalHandler);
        xmlReader.setContentHandler(contentHandler);
        xmlReader.parse(inputSource);
        return unmarshalHandler.getObject();
    } catch (SAXException ex) {
        throw new UnmarshallingFailureException("SAX reader exception", ex);
    }
}
Also used : UnmarshallingFailureException(org.springframework.oxm.UnmarshallingFailureException) UnmarshalHandler(org.exolab.castor.xml.UnmarshalHandler) ContentHandler(org.xml.sax.ContentHandler) SAXException(org.xml.sax.SAXException)

Aggregations

UnmarshallingFailureException (org.springframework.oxm.UnmarshallingFailureException)2 StreamSource (javax.xml.transform.stream.StreamSource)1 UnmarshalHandler (org.exolab.castor.xml.UnmarshalHandler)1 Test (org.junit.jupiter.api.Test)1 MockHttpInputMessage (org.springframework.http.MockHttpInputMessage)1 Unmarshaller (org.springframework.oxm.Unmarshaller)1 ContentHandler (org.xml.sax.ContentHandler)1 SAXException (org.xml.sax.SAXException)1