X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fconfig%2Fconfig-persister-file-xml-adapter%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fconfig%2Fpersist%2Fstorage%2Ffile%2Fxml%2Fmodel%2FConfig.java;h=6a6d360cfa794c2209ba7d5fe28a8dc1efeca3ab;hb=4b2e28032b61c23e2c488a3f33c76611fc80c9d7;hp=fb84651ca1446771af3a2cb397d535a3cbbf3ec5;hpb=576aa6018e48dfca8f223b7ac929139a32135201;p=controller.git diff --git a/opendaylight/config/config-persister-file-xml-adapter/src/main/java/org/opendaylight/controller/config/persist/storage/file/xml/model/Config.java b/opendaylight/config/config-persister-file-xml-adapter/src/main/java/org/opendaylight/controller/config/persist/storage/file/xml/model/Config.java index fb84651ca1..6a6d360cfa 100644 --- a/opendaylight/config/config-persister-file-xml-adapter/src/main/java/org/opendaylight/controller/config/persist/storage/file/xml/model/Config.java +++ b/opendaylight/config/config-persister-file-xml-adapter/src/main/java/org/opendaylight/controller/config/persist/storage/file/xml/model/Config.java @@ -12,8 +12,9 @@ import com.google.common.base.Optional; import com.google.common.collect.Iterables; import com.google.common.collect.Lists; import com.google.common.io.Files; -import org.apache.commons.lang3.StringUtils; - +import java.io.File; +import java.io.IOException; +import java.util.List; import javax.xml.bind.JAXBContext; import javax.xml.bind.JAXBException; import javax.xml.bind.Marshaller; @@ -21,9 +22,11 @@ import javax.xml.bind.Unmarshaller; import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlElementWrapper; import javax.xml.bind.annotation.XmlRootElement; -import java.io.File; -import java.io.IOException; -import java.util.List; +import javax.xml.stream.XMLInputFactory; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; +import javax.xml.transform.stream.StreamSource; +import org.apache.commons.lang3.StringUtils; @XmlRootElement(name = "persisted-snapshots") public final class Config { @@ -66,15 +69,19 @@ public final class Config { } public static Config fromXml(File from) { - if(isEmpty(from)) + if(isEmpty(from)) { return new Config(); + } try { JAXBContext jaxbContext = JAXBContext.newInstance(Config.class); Unmarshaller um = jaxbContext.createUnmarshaller(); - - return (Config) um.unmarshal(from); - } catch (JAXBException e) { + XMLInputFactory xif = XMLInputFactory.newFactory(); + xif.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, false); + xif.setProperty(XMLInputFactory.SUPPORT_DTD, false); + XMLStreamReader xsr = xif.createXMLStreamReader(new StreamSource(from)); + return ((Config) um.unmarshal(xsr)); + } catch (JAXBException | XMLStreamException e) { throw new PersistException("Unable to restore configuration", e); } }