Search in sources :

Example 1 with MarshallerException

use of org.onap.so.exceptions.MarshallerException in project so by onap.

the class XmlMarshaller method marshal.

public static String marshal(Object object) throws MarshallerException {
    StringWriter stringWriter = new StringWriter();
    try {
        JAXBContext jaxbContext = JAXBContext.newInstance(object.getClass());
        Marshaller jaxbMarshaller = jaxbContext.createMarshaller();
        jaxbMarshaller.marshal(object, stringWriter);
    } catch (JAXBException e) {
        logger.error(LoggingAnchor.THREE, MessageEnum.GENERAL_EXCEPTION.toString(), ErrorCode.SchemaError.getValue(), e.getMessage(), e);
        throw new MarshallerException(e.getMessage(), ErrorCode.SchemaError.getValue(), e);
    }
    return stringWriter.toString();
}
Also used : Marshaller(javax.xml.bind.Marshaller) MarshallerException(org.onap.so.exceptions.MarshallerException) StringWriter(java.io.StringWriter) JAXBException(javax.xml.bind.JAXBException) JAXBContext(javax.xml.bind.JAXBContext)

Example 2 with MarshallerException

use of org.onap.so.exceptions.MarshallerException in project so by onap.

the class XmlMarshaller method unMarshal.

public static Object unMarshal(String input, Object object) throws MarshallerException {
    try {
        SAXParserFactory spf = SAXParserFactory.newInstance();
        spf.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);
        spf.setFeature("http://xml.org/sax/features/external-general-entities", false);
        spf.setFeature("http://xml.org/sax/features/external-parameter-entities", false);
        spf.setNamespaceAware(true);
        XMLReader xmlReader = spf.newSAXParser().getXMLReader();
        JAXBContext jaxbContext = JAXBContext.newInstance(object.getClass());
        Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
        InputSource inputSource = new InputSource(new StringReader(input));
        SAXSource source = new SAXSource(xmlReader, inputSource);
        object = jaxbUnmarshaller.unmarshal(source, object.getClass()).getValue();
    } catch (Exception e) {
        logger.error(LoggingAnchor.THREE, MessageEnum.GENERAL_EXCEPTION.toString(), ErrorCode.SchemaError.getValue(), e.getMessage(), e);
        throw new MarshallerException(e.getMessage(), ErrorCode.SchemaError.getValue(), e);
    }
    return object;
}
Also used : InputSource(org.xml.sax.InputSource) SAXSource(javax.xml.transform.sax.SAXSource) MarshallerException(org.onap.so.exceptions.MarshallerException) StringReader(java.io.StringReader) JAXBContext(javax.xml.bind.JAXBContext) Unmarshaller(javax.xml.bind.Unmarshaller) XMLReader(org.xml.sax.XMLReader) MarshallerException(org.onap.so.exceptions.MarshallerException) JAXBException(javax.xml.bind.JAXBException) SAXParserFactory(javax.xml.parsers.SAXParserFactory)

Example 3 with MarshallerException

use of org.onap.so.exceptions.MarshallerException in project so by onap.

the class VnfAdapterImpl method unMarshal.

private Object unMarshal(String input) throws MarshallerException {
    try {
        SAXParserFactory spf = SAXParserFactory.newInstance();
        spf.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);
        spf.setFeature("http://xml.org/sax/features/external-general-entities", false);
        spf.setFeature("http://xml.org/sax/features/external-parameter-entities", false);
        spf.setNamespaceAware(true);
        XMLReader xmlReader = spf.newSAXParser().getXMLReader();
        JAXBContext jaxbContext = JAXBContext.newInstance(CreateVfModuleResponse.class, CreateVolumeGroupResponse.class, DeleteVfModuleResponse.class, DeleteVolumeGroupResponse.class);
        Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
        InputSource inputSource = new InputSource(new StringReader(input));
        SAXSource source = new SAXSource(xmlReader, inputSource);
        return jaxbUnmarshaller.unmarshal(source);
    } catch (Exception e) {
        logger.error(LoggingAnchor.THREE, MessageEnum.GENERAL_EXCEPTION.toString(), ErrorCode.SchemaError.getValue(), e.getMessage(), e);
        throw new MarshallerException("Error parsing VNF Adapter response. " + e.getMessage(), ErrorCode.SchemaError.getValue(), e);
    }
}
Also used : InputSource(org.xml.sax.InputSource) SAXSource(javax.xml.transform.sax.SAXSource) MarshallerException(org.onap.so.exceptions.MarshallerException) StringReader(java.io.StringReader) JAXBContext(javax.xml.bind.JAXBContext) Unmarshaller(javax.xml.bind.Unmarshaller) XMLReader(org.xml.sax.XMLReader) MarshallerException(org.onap.so.exceptions.MarshallerException) SAXParserFactory(javax.xml.parsers.SAXParserFactory)

Aggregations

JAXBContext (javax.xml.bind.JAXBContext)3 MarshallerException (org.onap.so.exceptions.MarshallerException)3 StringReader (java.io.StringReader)2 JAXBException (javax.xml.bind.JAXBException)2 Unmarshaller (javax.xml.bind.Unmarshaller)2 SAXParserFactory (javax.xml.parsers.SAXParserFactory)2 SAXSource (javax.xml.transform.sax.SAXSource)2 InputSource (org.xml.sax.InputSource)2 XMLReader (org.xml.sax.XMLReader)2 StringWriter (java.io.StringWriter)1 Marshaller (javax.xml.bind.Marshaller)1