This is an automated email from the ASF dual-hosted git repository.
buhhunyx pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/cxf.git The following commit(s) were added to refs/heads/master by this push: new 2447852 cxf-core: prevent lastModified check from opening stream (#749) 2447852 is described below commit 24478529c223d2b472eedf73259c639d37fcbefa Author: Alexey Markevich <[hidden email]> AuthorDate: Mon Feb 22 12:19:16 2021 +0000 cxf-core: prevent lastModified check from opening stream (#749) --- .../ControlledValidationXmlBeanDefinitionReader.java | 13 ++++++++----- .../org/apache/cxf/bus/spring/TunedDocumentLoader.java | 14 +++++++------- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/core/src/main/java/org/apache/cxf/bus/spring/ControlledValidationXmlBeanDefinitionReader.java b/core/src/main/java/org/apache/cxf/bus/spring/ControlledValidationXmlBeanDefinitionReader.java index 086dca5..168673c 100644 --- a/core/src/main/java/org/apache/cxf/bus/spring/ControlledValidationXmlBeanDefinitionReader.java +++ b/core/src/main/java/org/apache/cxf/bus/spring/ControlledValidationXmlBeanDefinitionReader.java @@ -19,9 +19,10 @@ package org.apache.cxf.bus.spring; +import java.io.File; import java.io.IOException; +import java.net.URISyntaxException; import java.net.URL; -import java.net.URLConnection; import java.security.AccessController; import java.security.PrivilegedActionException; import java.security.PrivilegedExceptionAction; @@ -174,10 +175,12 @@ public class ControlledValidationXmlBeanDefinitionReader extends XmlBeanDefiniti // if we are in unpacked files, we take some extra time // to ensure that we aren't using a stale Fastinfoset file. if ("file".equals(protocol)) { - URLConnection resCon = resUrl.openConnection(); - URLConnection fixCon = fixmlUrl.openConnection(); - if (resCon.getLastModified() > fixCon.getLastModified()) { - throw new StaleFastinfosetException(); + try { + if (new File(resUrl.toURI()).lastModified() > new File(fixmlUrl.toURI()).lastModified()) { + throw new StaleFastinfosetException(); + } + } catch (URISyntaxException e) { + // ignore } } diff --git a/core/src/main/java/org/apache/cxf/bus/spring/TunedDocumentLoader.java b/core/src/main/java/org/apache/cxf/bus/spring/TunedDocumentLoader.java index 9b9b26b..0ec7ec2 100644 --- a/core/src/main/java/org/apache/cxf/bus/spring/TunedDocumentLoader.java +++ b/core/src/main/java/org/apache/cxf/bus/spring/TunedDocumentLoader.java @@ -138,13 +138,13 @@ class TunedDocumentLoader extends DefaultDocumentLoader { static Document loadFastinfosetDocument(URL url) throws IOException, ParserConfigurationException, XMLStreamException { - InputStream is = url.openStream(); - InputStream in = new BufferedInputStream(is); - XMLStreamReader staxReader = new StAXDocumentParser(in); - W3CDOMStreamWriter writer = new W3CDOMStreamWriter(); - StaxUtils.copy(staxReader, writer); - in.close(); - return writer.getDocument(); + try (InputStream in = new BufferedInputStream(url.openStream())) { + XMLStreamReader staxReader = new StAXDocumentParser(in); + W3CDOMStreamWriter writer = new W3CDOMStreamWriter(); + StaxUtils.copy(staxReader, writer); + staxReader.close(); + return writer.getDocument(); + } } } |
Free forum by Nabble | Edit this page |