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);
}
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);
}
}
Aggregations