org.springframework.oxm.UnmarshallingFailureException Java Examples

The following examples show how to use org.springframework.oxm.UnmarshallingFailureException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Jaxb2Marshaller.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
/**
 * Convert the given {@code JAXBException} to an appropriate exception from the
 * {@code org.springframework.oxm} hierarchy.
 * @param ex {@code JAXBException} that occured
 * @return the corresponding {@code XmlMappingException}
 */
protected XmlMappingException convertJaxbException(JAXBException ex) {
	if (ex instanceof ValidationException) {
		return new ValidationFailureException("JAXB validation exception", ex);
	}
	else if (ex instanceof MarshalException) {
		return new MarshallingFailureException("JAXB marshalling exception", ex);
	}
	else if (ex instanceof UnmarshalException) {
		return new UnmarshallingFailureException("JAXB unmarshalling exception", ex);
	}
	else {
		// fallback
		return new UncategorizedMappingException("Unknown JAXB exception", ex);
	}
}
 
Example #2
Source File: MarshallingHttpMessageConverterTests.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@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);

	try {
		converter.read(Object.class, inputMessage);
		fail("HttpMessageNotReadableException should be thrown");
	}
	catch (HttpMessageNotReadableException e) {
		assertTrue("Invalid exception hierarchy", e.getCause() == ex);
	}
}
 
Example #3
Source File: XStreamMarshaller.java    From java-technology-stack with MIT License 6 votes vote down vote up
/**
 * Convert the given XStream exception to an appropriate exception from the
 * {@code org.springframework.oxm} hierarchy.
 * <p>A boolean flag is used to indicate whether this exception occurs during marshalling or
 * unmarshalling, since XStream itself does not make this distinction in its exception hierarchy.
 * @param ex the XStream exception that occurred
 * @param marshalling indicates whether the exception occurs during marshalling ({@code true}),
 * or unmarshalling ({@code false})
 * @return the corresponding {@code XmlMappingException}
 */
protected XmlMappingException convertXStreamException(Exception ex, boolean marshalling) {
	if (ex instanceof StreamException || ex instanceof CannotResolveClassException ||
			ex instanceof ConversionException) {
		if (marshalling) {
			return new MarshallingFailureException("XStream marshalling exception",  ex);
		}
		else {
			return new UnmarshallingFailureException("XStream unmarshalling exception", ex);
		}
	}
	else {
		// fallback
		return new UncategorizedMappingException("Unknown XStream exception", ex);
	}
}
 
Example #4
Source File: CastorMarshaller.java    From java-technology-stack with MIT License 6 votes vote down vote up
/**
 * Convert the given {@code XMLException} to an appropriate exception from the
 * {@code org.springframework.oxm} hierarchy.
 * <p>A boolean flag is used to indicate whether this exception occurs during marshalling or
 * unmarshalling, since Castor itself does not make this distinction in its exception hierarchy.
 * @param ex the Castor {@code XMLException} that occurred
 * @param marshalling indicates whether the exception occurs during marshalling ({@code true}),
 * or unmarshalling ({@code false})
 * @return the corresponding {@code XmlMappingException}
 */
protected XmlMappingException convertCastorException(XMLException ex, boolean marshalling) {
	if (ex instanceof ValidationException) {
		return new ValidationFailureException("Castor validation exception", ex);
	}
	else if (ex instanceof MarshalException) {
		if (marshalling) {
			return new MarshallingFailureException("Castor marshalling exception", ex);
		}
		else {
			return new UnmarshallingFailureException("Castor unmarshalling exception", ex);
		}
	}
	else {
		// fallback
		return new UncategorizedMappingException("Unknown Castor exception", ex);
	}
}
 
Example #5
Source File: MarshallingHttpMessageConverterTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@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);

	try {
		converter.read(Object.class, inputMessage);
		fail("HttpMessageNotReadableException should be thrown");
	}
	catch (HttpMessageNotReadableException e) {
		assertTrue("Invalid exception hierarchy", e.getCause() == ex);
	}
}
 
Example #6
Source File: Jaxb2Marshaller.java    From java-technology-stack with MIT License 6 votes vote down vote up
/**
 * Convert the given {@code JAXBException} to an appropriate exception from the
 * {@code org.springframework.oxm} hierarchy.
 * @param ex {@code JAXBException} that occurred
 * @return the corresponding {@code XmlMappingException}
 */
protected XmlMappingException convertJaxbException(JAXBException ex) {
	if (ex instanceof ValidationException) {
		return new ValidationFailureException("JAXB validation exception", ex);
	}
	else if (ex instanceof MarshalException) {
		return new MarshallingFailureException("JAXB marshalling exception", ex);
	}
	else if (ex instanceof UnmarshalException) {
		return new UnmarshallingFailureException("JAXB unmarshalling exception", ex);
	}
	else {
		// fallback
		return new UncategorizedMappingException("Unknown JAXB exception", ex);
	}
}
 
Example #7
Source File: AbstractMarshaller.java    From java-technology-stack with MIT License 6 votes vote down vote up
/**
 * Template method for handling {@code DOMSource}s.
 * <p>This implementation delegates to {@code unmarshalDomNode}.
 * If the given source is empty, an empty source {@code Document}
 * will be created as a placeholder.
 * @param domSource the {@code DOMSource}
 * @return the object graph
 * @throws XmlMappingException if the given source cannot be mapped to an object
 * @throws IllegalArgumentException if the {@code domSource} is empty
 * @see #unmarshalDomNode(org.w3c.dom.Node)
 */
protected Object unmarshalDomSource(DOMSource domSource) throws XmlMappingException {
	if (domSource.getNode() == null) {
		domSource.setNode(buildDocument());
	}
	try {
		return unmarshalDomNode(domSource.getNode());
	}
	catch (NullPointerException ex) {
		if (!isSupportDtd()) {
			throw new UnmarshallingFailureException("NPE while unmarshalling. " +
					"This can happen on JDK 1.6 due to the presence of DTD " +
					"declarations, which are disabled.", ex);
		}
		throw ex;
	}
}
 
Example #8
Source File: AbstractMarshaller.java    From java-technology-stack with MIT License 6 votes vote down vote up
/**
 * Build a new {@link Document} from this marshaller's {@link DocumentBuilderFactory},
 * as a placeholder for a DOM node.
 * @see #createDocumentBuilderFactory()
 * @see #createDocumentBuilder(DocumentBuilderFactory)
 */
protected Document buildDocument() {
	try {
		DocumentBuilder documentBuilder;
		synchronized (this.documentBuilderFactoryMonitor) {
			if (this.documentBuilderFactory == null) {
				this.documentBuilderFactory = createDocumentBuilderFactory();
			}
			documentBuilder = createDocumentBuilder(this.documentBuilderFactory);
		}
		return documentBuilder.newDocument();
	}
	catch (ParserConfigurationException ex) {
		throw new UnmarshallingFailureException("Could not create document placeholder: " + ex.getMessage(), ex);
	}
}
 
Example #9
Source File: AbstractMarshaller.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
/**
 * Template method for handling {@code DOMSource}s.
 * <p>This implementation delegates to {@code unmarshalDomNode}.
 * If the given source is empty, an empty source {@code Document}
 * will be created as a placeholder.
 * @param domSource the {@code DOMSource}
 * @return the object graph
 * @throws XmlMappingException if the given source cannot be mapped to an object
 * @throws IllegalArgumentException if the {@code domSource} is empty
 * @see #unmarshalDomNode(org.w3c.dom.Node)
 */
protected Object unmarshalDomSource(DOMSource domSource) throws XmlMappingException {
	if (domSource.getNode() == null) {
		domSource.setNode(buildDocument());
	}
	try {
		return unmarshalDomNode(domSource.getNode());
	}
	catch (NullPointerException ex) {
		if (!isSupportDtd()) {
			throw new UnmarshallingFailureException("NPE while unmarshalling. " +
					"This can happen on JDK 1.6 due to the presence of DTD " +
					"declarations, which are disabled.", ex);
		}
		throw ex;
	}
}
 
Example #10
Source File: MarshallingHttpMessageConverterTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@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);

	try {
		converter.read(Object.class, inputMessage);
		fail("HttpMessageNotReadableException should be thrown");
	}
	catch (HttpMessageNotReadableException e) {
		assertTrue("Invalid exception hierarchy", e.getCause() == ex);
	}
}
 
Example #11
Source File: XStreamMarshaller.java    From spring-analysis-note with MIT License 6 votes vote down vote up
/**
 * Convert the given XStream exception to an appropriate exception from the
 * {@code org.springframework.oxm} hierarchy.
 * <p>A boolean flag is used to indicate whether this exception occurs during marshalling or
 * unmarshalling, since XStream itself does not make this distinction in its exception hierarchy.
 * @param ex the XStream exception that occurred
 * @param marshalling indicates whether the exception occurs during marshalling ({@code true}),
 * or unmarshalling ({@code false})
 * @return the corresponding {@code XmlMappingException}
 */
protected XmlMappingException convertXStreamException(Exception ex, boolean marshalling) {
	if (ex instanceof StreamException || ex instanceof CannotResolveClassException ||
			ex instanceof ConversionException) {
		if (marshalling) {
			return new MarshallingFailureException("XStream marshalling exception",  ex);
		}
		else {
			return new UnmarshallingFailureException("XStream unmarshalling exception", ex);
		}
	}
	else {
		// fallback
		return new UncategorizedMappingException("Unknown XStream exception", ex);
	}
}
 
Example #12
Source File: Jaxb2Marshaller.java    From spring-analysis-note with MIT License 6 votes vote down vote up
/**
 * Convert the given {@code JAXBException} to an appropriate exception
 * from the {@code org.springframework.oxm} hierarchy.
 * @param ex {@code JAXBException} that occurred
 * @return the corresponding {@code XmlMappingException}
 */
protected XmlMappingException convertJaxbException(JAXBException ex) {
	if (ex instanceof ValidationException) {
		return new ValidationFailureException("JAXB validation exception", ex);
	}
	else if (ex instanceof MarshalException) {
		return new MarshallingFailureException("JAXB marshalling exception", ex);
	}
	else if (ex instanceof UnmarshalException) {
		return new UnmarshallingFailureException("JAXB unmarshalling exception", ex);
	}
	else {
		// fallback
		return new UncategorizedMappingException("Unknown JAXB exception", ex);
	}
}
 
Example #13
Source File: AbstractMarshaller.java    From spring-analysis-note with MIT License 6 votes vote down vote up
/**
 * Template method for handling {@code DOMSource}s.
 * <p>This implementation delegates to {@code unmarshalDomNode}.
 * If the given source is empty, an empty source {@code Document}
 * will be created as a placeholder.
 * @param domSource the {@code DOMSource}
 * @return the object graph
 * @throws XmlMappingException if the given source cannot be mapped to an object
 * @throws IllegalArgumentException if the {@code domSource} is empty
 * @see #unmarshalDomNode(org.w3c.dom.Node)
 */
protected Object unmarshalDomSource(DOMSource domSource) throws XmlMappingException {
	if (domSource.getNode() == null) {
		domSource.setNode(buildDocument());
	}
	try {
		return unmarshalDomNode(domSource.getNode());
	}
	catch (NullPointerException ex) {
		if (!isSupportDtd()) {
			throw new UnmarshallingFailureException("NPE while unmarshalling. " +
					"This can happen on JDK 1.6 due to the presence of DTD " +
					"declarations, which are disabled.", ex);
		}
		throw ex;
	}
}
 
Example #14
Source File: AbstractMarshaller.java    From spring-analysis-note with MIT License 6 votes vote down vote up
/**
 * Build a new {@link Document} from this marshaller's {@link DocumentBuilderFactory},
 * as a placeholder for a DOM node.
 * @see #createDocumentBuilderFactory()
 * @see #createDocumentBuilder(DocumentBuilderFactory)
 */
protected Document buildDocument() {
	try {
		DocumentBuilder documentBuilder;
		synchronized (this.documentBuilderFactoryMonitor) {
			if (this.documentBuilderFactory == null) {
				this.documentBuilderFactory = createDocumentBuilderFactory();
			}
			documentBuilder = createDocumentBuilder(this.documentBuilderFactory);
		}
		return documentBuilder.newDocument();
	}
	catch (ParserConfigurationException ex) {
		throw new UnmarshallingFailureException("Could not create document placeholder: " + ex.getMessage(), ex);
	}
}
 
Example #15
Source File: CastorMarshaller.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
/**
 * Convert the given {@code XMLException} to an appropriate exception from the
 * {@code org.springframework.oxm} hierarchy.
 * <p>A boolean flag is used to indicate whether this exception occurs during marshalling or
 * unmarshalling, since Castor itself does not make this distinction in its exception hierarchy.
 * @param ex Castor {@code XMLException} that occurred
 * @param marshalling indicates whether the exception occurs during marshalling ({@code true}),
 * or unmarshalling ({@code false})
 * @return the corresponding {@code XmlMappingException}
 */
protected XmlMappingException convertCastorException(XMLException ex, boolean marshalling) {
	if (ex instanceof ValidationException) {
		return new ValidationFailureException("Castor validation exception", ex);
	}
	else if (ex instanceof MarshalException) {
		if (marshalling) {
			return new MarshallingFailureException("Castor marshalling exception", ex);
		}
		else {
			return new UnmarshallingFailureException("Castor unmarshalling exception", ex);
		}
	}
	else {
		// fallback
		return new UncategorizedMappingException("Unknown Castor exception", ex);
	}
}
 
Example #16
Source File: XStreamMarshaller.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
/**
    * Convert the given XStream exception to an appropriate exception from the
    * {@code org.springframework.oxm} hierarchy.
    * <p>A boolean flag is used to indicate whether this exception occurs during marshalling or
    * unmarshalling, since XStream itself does not make this distinction in its exception hierarchy.
    * @param ex XStream exception that occurred
    * @param marshalling indicates whether the exception occurs during marshalling ({@code true}),
    * or unmarshalling ({@code false})
    * @return the corresponding {@code XmlMappingException}
    */
protected XmlMappingException convertXStreamException(Exception ex, boolean marshalling) {
	if (ex instanceof StreamException || ex instanceof CannotResolveClassException ||
			ex instanceof ConversionException) {
		if (marshalling) {
			return new MarshallingFailureException("XStream marshalling exception",  ex);
		}
		else {
			return new UnmarshallingFailureException("XStream unmarshalling exception", ex);
		}
	}
	else {
		// fallback
		return new UncategorizedMappingException("Unknown XStream exception", ex);
	}
}
 
Example #17
Source File: XmlBeansMarshaller.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
/**
 * Convert the given XMLBeans exception to an appropriate exception from the
 * {@code org.springframework.oxm} hierarchy.
 * <p>A boolean flag is used to indicate whether this exception occurs during marshalling or
 * unmarshalling, since XMLBeans itself does not make this distinction in its exception hierarchy.
 * @param ex XMLBeans Exception that occured
 * @param marshalling indicates whether the exception occurs during marshalling ({@code true}),
 * or unmarshalling ({@code false})
 * @return the corresponding {@code XmlMappingException}
 */
protected XmlMappingException convertXmlBeansException(Exception ex, boolean marshalling) {
	if (ex instanceof XMLStreamValidationException) {
		return new ValidationFailureException("XMLBeans validation exception", ex);
	}
	else if (ex instanceof XmlException || ex instanceof SAXException) {
		if (marshalling) {
			return new MarshallingFailureException("XMLBeans marshalling exception",  ex);
		}
		else {
			return new UnmarshallingFailureException("XMLBeans unmarshalling exception", ex);
		}
	}
	else {
		// fallback
		return new UncategorizedMappingException("Unknown XMLBeans exception", ex);
	}
}
 
Example #18
Source File: Jaxb2Marshaller.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Override
public byte[] getAttachmentAsByteArray(String cid) {
	try {
		DataHandler dataHandler = getAttachmentAsDataHandler(cid);
		return FileCopyUtils.copyToByteArray(dataHandler.getInputStream());
	}
	catch (IOException ex) {
		throw new UnmarshallingFailureException("Couldn't read attachment", ex);
	}
}
 
Example #19
Source File: CastorMarshaller.java    From java-technology-stack with MIT License 5 votes vote down vote up
@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);
	}
}
 
Example #20
Source File: CastorMarshaller.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@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);
	}
}
 
Example #21
Source File: AbstractMarshaller.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
/**
 * Build a new {@link Document} from this marshaller's {@link DocumentBuilderFactory},
 * as a placeholder for a DOM node.
 * @see #createDocumentBuilderFactory()
 * @see #createDocumentBuilder(DocumentBuilderFactory)
 */
protected Document buildDocument() {
	try {
		synchronized (this.documentBuilderFactoryMonitor) {
			if (this.documentBuilderFactory == null) {
				this.documentBuilderFactory = createDocumentBuilderFactory();
			}
		}
		DocumentBuilder documentBuilder = createDocumentBuilder(this.documentBuilderFactory);
		return documentBuilder.newDocument();
	}
	catch (ParserConfigurationException ex) {
		throw new UnmarshallingFailureException("Could not create document placeholder: " + ex.getMessage(), ex);
	}
}
 
Example #22
Source File: JibxMarshaller.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
/**
 * Convert the given {@code JiBXException} to an appropriate exception from the
 * {@code org.springframework.oxm} hierarchy.
 * <p>A boolean flag is used to indicate whether this exception occurs during marshalling or
 * unmarshalling, since JiBX itself does not make this distinction in its exception hierarchy.
 * @param ex {@code JiBXException} that occured
 * @param marshalling indicates whether the exception occurs during marshalling ({@code true}),
 * or unmarshalling ({@code false})
 * @return the corresponding {@code XmlMappingException}
 */
public XmlMappingException convertJibxException(JiBXException ex, boolean marshalling) {
	if (ex instanceof ValidationException) {
		return new ValidationFailureException("JiBX validation exception", ex);
	}
	else {
		if (marshalling) {
			return new MarshallingFailureException("JiBX marshalling exception", ex);
		}
		else {
			return new UnmarshallingFailureException("JiBX unmarshalling exception", ex);
		}
	}
}
 
Example #23
Source File: JibxMarshaller.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Override
protected Object unmarshalDomNode(Node node) throws XmlMappingException {
	try {
		return transformAndUnmarshal(new DOMSource(node), null);
	}
	catch (IOException ex) {
		throw new UnmarshallingFailureException("JiBX unmarshalling exception", ex);
	}
}
 
Example #24
Source File: JibxMarshaller.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Override
protected Object unmarshalXmlEventReader(XMLEventReader eventReader) {
	try {
		XMLStreamReader streamReader = StaxUtils.createEventStreamReader(eventReader);
		return unmarshalXmlStreamReader(streamReader);
	}
	catch (XMLStreamException ex) {
		return new UnmarshallingFailureException("JiBX unmarshalling exception", ex);
	}
}
 
Example #25
Source File: MarshallingHttpMessageConverter.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Override
protected Object readFromSource(Class<?> clazz, HttpHeaders headers, Source source) throws IOException {
	Assert.notNull(this.unmarshaller, "Property 'unmarshaller' is required");
	try {
		Object result = this.unmarshaller.unmarshal(source);
		if (!clazz.isInstance(result)) {
			throw new TypeMismatchException(result, clazz);
		}
		return result;
	}
	catch (UnmarshallingFailureException ex) {
		throw new HttpMessageNotReadableException("Could not read [" + clazz + "]", ex);
	}
}
 
Example #26
Source File: MarshallingHttpMessageConverter.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
protected Object readFromSource(Class<?> clazz, HttpHeaders headers, Source source) throws IOException {
	Assert.notNull(this.unmarshaller, "Property 'unmarshaller' is required");
	try {
		Object result = this.unmarshaller.unmarshal(source);
		if (!clazz.isInstance(result)) {
			throw new TypeMismatchException(result, clazz);
		}
		return result;
	}
	catch (UnmarshallingFailureException ex) {
		throw new HttpMessageNotReadableException("Could not read [" + clazz + "]", ex);
	}
}
 
Example #27
Source File: Jaxb2Marshaller.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Override
public byte[] getAttachmentAsByteArray(String cid) {
	try {
		DataHandler dataHandler = getAttachmentAsDataHandler(cid);
		return FileCopyUtils.copyToByteArray(dataHandler.getInputStream());
	}
	catch (IOException ex) {
		throw new UnmarshallingFailureException("Couldn't read attachment", ex);
	}
}
 
Example #28
Source File: JibxMarshaller.java    From java-technology-stack with MIT License 5 votes vote down vote up
/**
 * Convert the given {@code JiBXException} to an appropriate exception from the
 * {@code org.springframework.oxm} hierarchy.
 * <p>A boolean flag is used to indicate whether this exception occurs during marshalling or
 * unmarshalling, since JiBX itself does not make this distinction in its exception hierarchy.
 * @param ex {@code JiBXException} that occurred
 * @param marshalling indicates whether the exception occurs during marshalling ({@code true}),
 * or unmarshalling ({@code false})
 * @return the corresponding {@code XmlMappingException}
 */
public XmlMappingException convertJibxException(JiBXException ex, boolean marshalling) {
	if (ex instanceof ValidationException) {
		return new ValidationFailureException("JiBX validation exception", ex);
	}
	else {
		if (marshalling) {
			return new MarshallingFailureException("JiBX marshalling exception", ex);
		}
		else {
			return new UnmarshallingFailureException("JiBX unmarshalling exception", ex);
		}
	}
}
 
Example #29
Source File: JibxMarshaller.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Override
protected Object unmarshalDomNode(Node node) throws XmlMappingException {
	try {
		return transformAndUnmarshal(new DOMSource(node), null);
	}
	catch (IOException ex) {
		throw new UnmarshallingFailureException("JiBX unmarshalling exception", ex);
	}
}
 
Example #30
Source File: JibxMarshaller.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Override
protected Object unmarshalXmlEventReader(XMLEventReader eventReader) {
	try {
		XMLStreamReader streamReader = StaxUtils.createEventStreamReader(eventReader);
		return unmarshalXmlStreamReader(streamReader);
	}
	catch (XMLStreamException ex) {
		return new UnmarshallingFailureException("JiBX unmarshalling exception", ex);
	}
}