Example usage for org.springframework.oxm.jaxb Jaxb2Marshaller unmarshal

List of usage examples for org.springframework.oxm.jaxb Jaxb2Marshaller unmarshal

Introduction

In this page you can find the example usage for org.springframework.oxm.jaxb Jaxb2Marshaller unmarshal.

Prototype

@Override
    public Object unmarshal(Source source) throws XmlMappingException 

Source Link

Usage

From source file:org.cleverbus.common.Tools.java

/**
 * Unmarshals XML into object graph.//from  w  ww  .  ja va  2 s.c  om
 *
 * @param xml the input string
 * @param targetClass the target class
 * @return object graph
 * @see XmlConverter
 */
@SuppressWarnings("unchecked")
public static <T> T unmarshalFromXml(String xml, Class<T> targetClass) {
    Jaxb2Marshaller jaxb2 = new Jaxb2Marshaller();
    jaxb2.setContextPath(targetClass.getPackage().getName());

    return (T) jaxb2.unmarshal(new StreamSource(new StringReader(xml)));
}

From source file:no.digipost.api.xml.MessagingMarshalling.java

/**
 * Enten returnerer denne et Messaging objekt, eller s kaster den en RuntimeException
 *//*w  ww  .  j  a va2s.c o m*/
public static Messaging getMessaging(final Jaxb2Marshaller jaxb2Marshaller, final WebServiceMessage message) {

    SoapHeader soapHeader = ((SoapMessage) message).getSoapHeader();
    if (soapHeader == null) {
        throw new RuntimeException("The ebMS header is missing (no SOAP header found in SOAP request)");
    }

    Iterator<SoapHeaderElement> soapHeaderElementIterator = soapHeader.examineHeaderElements(MESSAGING_QNAME);
    if (!soapHeaderElementIterator.hasNext()) {
        throw new RuntimeException("The ebMS header is missing in SOAP header");
    }

    SoapHeaderElement incomingSoapHeaderElement = soapHeaderElementIterator.next();
    try {
        return (Messaging) jaxb2Marshaller.unmarshal(incomingSoapHeaderElement.getSource());
    } catch (Exception e) {
        throw new RuntimeException("The ebMs header failed to unmarshall");
    }

}