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