X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;ds=sidebyside;f=opendaylight%2Fconfig%2Fconfig-persister-directory-xml-adapter%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fconfig%2Fpersist%2Fstorage%2Fdirectory%2Fxml%2FXmlDirectoryPersister.java;h=ae7954f76a6147803d57496bf6363736e30d49b4;hb=e1e5e49a42a767530b96c4cacddd83eca303aee0;hp=85f70b9a01172f314fec16020d508e9769efeea7;hpb=08718bf4bc3cc5297dc7e918e9e8e97a45b74391;p=controller.git diff --git a/opendaylight/config/config-persister-directory-xml-adapter/src/main/java/org/opendaylight/controller/config/persist/storage/directory/xml/XmlDirectoryPersister.java b/opendaylight/config/config-persister-directory-xml-adapter/src/main/java/org/opendaylight/controller/config/persist/storage/directory/xml/XmlDirectoryPersister.java index 85f70b9a01..ae7954f76a 100644 --- a/opendaylight/config/config-persister-directory-xml-adapter/src/main/java/org/opendaylight/controller/config/persist/storage/directory/xml/XmlDirectoryPersister.java +++ b/opendaylight/config/config-persister-directory-xml-adapter/src/main/java/org/opendaylight/controller/config/persist/storage/directory/xml/XmlDirectoryPersister.java @@ -23,6 +23,10 @@ import java.util.SortedSet; import javax.xml.bind.JAXBContext; import javax.xml.bind.JAXBException; import javax.xml.bind.Unmarshaller; +import javax.xml.stream.XMLInputFactory; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; +import javax.xml.transform.stream.StreamSource; import org.opendaylight.controller.config.persist.api.ConfigSnapshotHolder; import org.opendaylight.controller.config.persist.api.Persister; import org.opendaylight.controller.config.persist.storage.file.xml.model.ConfigSnapshot; @@ -88,7 +92,7 @@ public class XmlDirectoryPersister implements Persister { private Optional fromXmlSnapshot(final File file) { try { return Optional.of(loadLastConfig(file)); - } catch (JAXBException e) { + } catch (final JAXBException e) { // In case of parse error, issue a warning, ignore and continue LOG.warn( "Unable to parse configuration snapshot from {}. Initial config from {} will be IGNORED in this run. ", @@ -105,8 +109,15 @@ public class XmlDirectoryPersister implements Persister { public static ConfigSnapshotHolder loadLastConfig(final File file) throws JAXBException { JAXBContext jaxbContext = JAXBContext.newInstance(ConfigSnapshot.class); Unmarshaller um = jaxbContext.createUnmarshaller(); - - return asHolder((ConfigSnapshot) um.unmarshal(file)); + XMLInputFactory xif = XMLInputFactory.newFactory(); + xif.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, false); + xif.setProperty(XMLInputFactory.SUPPORT_DTD, false); + try { + XMLStreamReader xsr = xif.createXMLStreamReader(new StreamSource(file)); + return asHolder((ConfigSnapshot) um.unmarshal(xsr)); + } catch (final XMLStreamException e) { + throw new JAXBException(e); + } } private static ConfigSnapshotHolder asHolder(final ConfigSnapshot unmarshalled) { @@ -131,12 +142,9 @@ public class XmlDirectoryPersister implements Persister { private static FilenameFilter getFilter(final SetfileExtensions) { checkArgument(fileExtensions.isEmpty() == false, "No file extension provided", fileExtensions); - return new FilenameFilter() { - @Override - public boolean accept(final File dir, final String name) { - String ext = Files.getFileExtension(name); - return fileExtensions.contains(ext); - } + return (dir, name) -> { + String ext = Files.getFileExtension(name); + return fileExtensions.contains(ext); }; } @@ -147,9 +155,6 @@ public class XmlDirectoryPersister implements Persister { @Override public String toString() { - final StringBuffer sb = new StringBuffer("XmlDirectoryPersister{"); - sb.append("storage=").append(storage); - sb.append('}'); - return sb.toString(); + return "XmlDirectoryPersister{storage=" + storage + "}"; } } \ No newline at end of file