Example usage for org.springframework.http.converter HttpMessageConversionException HttpMessageConversionException

List of usage examples for org.springframework.http.converter HttpMessageConversionException HttpMessageConversionException

Introduction

In this page you can find the example usage for org.springframework.http.converter HttpMessageConversionException HttpMessageConversionException.

Prototype

public HttpMessageConversionException(String msg, @Nullable Throwable cause) 

Source Link

Document

Create a new HttpMessageConversionException.

Usage

From source file:org.alfresco.repo.publishing.JaxbHttpMessageConverter.java

/**
 * Creates a new {@link Marshaller} for the given class.
 * //from   w w w . ja  va  2  s  .  c om
 * @param clazz
 *            the class to create the marshaller for
 * @return the {@code Marshaller}
 * @throws HttpMessageConversionException
 *             in case of JAXB errors
 */
protected final Marshaller createMarshaller(Class<?> clazz) {
    try {
        JAXBContext jaxbContext = getJaxbContext(clazz);
        return jaxbContext.createMarshaller();
    } catch (JAXBException ex) {
        throw new HttpMessageConversionException(
                "Could not create Marshaller for class [" + clazz + "]: " + ex.getMessage(), ex);
    }
}

From source file:org.alfresco.repo.publishing.JaxbHttpMessageConverter.java

/**
 * Creates a new {@link Unmarshaller} for the given class.
 * //from w  ww . j  av  a  2s .c  o  m
 * @param clazz
 *            the class to create the unmarshaller for
 * @return the {@code Unmarshaller}
 * @throws HttpMessageConversionException
 *             in case of JAXB errors
 */
protected final Unmarshaller createUnmarshaller(Class<?> clazz) throws JAXBException {
    try {
        JAXBContext jaxbContext = getJaxbContext(clazz);
        return jaxbContext.createUnmarshaller();
    } catch (JAXBException ex) {
        throw new HttpMessageConversionException(
                "Could not create Unmarshaller for class [" + clazz + "]: " + ex.getMessage(), ex);
    }
}

From source file:org.alfresco.repo.publishing.JaxbHttpMessageConverter.java

/**
 * Returns a {@link JAXBContext} for the given class.
 * //from w  ww . j  av a 2s  .  c  o  m
 * @param clazz
 *            the class to return the context for
 * @return the {@code JAXBContext}
 * @throws HttpMessageConversionException
 *             in case of JAXB errors
 */
protected final JAXBContext getJaxbContext(Class<?> clazz) {
    Assert.notNull(clazz, "'clazz' must not be null");
    JAXBContext result = null;
    if (defaultJaxbContext != null) {
        result = defaultJaxbContext;
    } else {
        result = jaxbContexts.get(clazz);
        if (result == null) {
            try {
                result = JAXBContext.newInstance(clazz);
                jaxbContexts.putIfAbsent(clazz, result);
            } catch (JAXBException ex) {
                throw new HttpMessageConversionException(
                        "Could not instantiate JAXBContext for class [" + clazz + "]: " + ex.getMessage(), ex);
            }
        }
    }
    return result;
}