diff --git a/api/src/main/java/com/redhat/insights/InsightsCustomScheduledExecutor.java b/api/src/main/java/com/redhat/insights/InsightsCustomScheduledExecutor.java index af7e4a1..0fa7f6e 100644 --- a/api/src/main/java/com/redhat/insights/InsightsCustomScheduledExecutor.java +++ b/api/src/main/java/com/redhat/insights/InsightsCustomScheduledExecutor.java @@ -18,6 +18,7 @@ public class InsightsCustomScheduledExecutor extends ScheduledThreadPoolExecutor private InsightsCustomScheduledExecutor( InsightsLogger logger, InsightsConfiguration configuration) { super(1); + setKeepAliveTime(10L, TimeUnit.MILLISECONDS); this.logger = logger; this.configuration = configuration; } diff --git a/api/src/main/java/com/redhat/insights/jars/JarUtils.java b/api/src/main/java/com/redhat/insights/jars/JarUtils.java index 417344a..4118a5a 100644 --- a/api/src/main/java/com/redhat/insights/jars/JarUtils.java +++ b/api/src/main/java/com/redhat/insights/jars/JarUtils.java @@ -23,12 +23,14 @@ public final class JarUtils { private static final Map EMBEDDED_FORMAT_TO_EXTENSION = getEmbeddedFormatToExtension("ear", "war", "jar"); private static final int DEFAULT_BUFFER_SIZE = 1024 * 8; + private static final String JAR_PROTOCOL = "jar:"; + private static final String BANG_SEPARATOR = "!/"; private JarUtils() {} private static Map getEmbeddedFormatToExtension(String... fileExtensions) { Map out = new HashMap<>(); - Stream.of(fileExtensions).forEach(ext -> out.put('.' + ext + "!/", ext)); + Stream.of(fileExtensions).forEach(ext -> out.put('.' + ext + BANG_SEPARATOR, ext)); return out; } @@ -37,6 +39,7 @@ private static Map getEmbeddedFormatToExtension(String... fileEx * input stream starting at the embedded jar. * * @param url + * @return a Stream to the specified URL. * @throws IOException */ public static InputStream getInputStream(URL url) throws IOException { @@ -48,10 +51,16 @@ public static InputStream getInputStream(URL url) throws IOException { // jar content. if (index > 0 && (index + entry.getKey().length()) < jarLocation.length()) { String path = url.toExternalForm().substring(index + entry.getKey().length()); + if (path.endsWith(BANG_SEPARATOR)) { + path = path.substring(0, path.length() - BANG_SEPARATOR.length()); + } // add 1 to skip past the `.` and the value length, which is the length of the file // extension - jarURL = - new URL(jarURL.toExternalForm().substring(0, index + 1 + entry.getValue().length())); + String jar = jarURL.toExternalForm().substring(0, index + 1 + entry.getValue().length()); + if (jarLocation.startsWith(JAR_PROTOCOL)) { + jar = jar.substring(JAR_PROTOCOL.length()); + } + jarURL = new URL(jar); InputStream inputStream = jarURL.openStream(); JarInputStream jarStream = new JarInputStream(inputStream); @@ -63,8 +72,8 @@ public static InputStream getInputStream(URL url) throws IOException { return jarStream; } } - if (jarLocation.startsWith("jar:") && jarLocation.endsWith("!/")) { - String jarLoc = jarLocation.substring(4, jarLocation.length() - 2); + if (jarLocation.startsWith(JAR_PROTOCOL) && jarLocation.endsWith(BANG_SEPARATOR)) { + String jarLoc = jarLocation.substring(4, jarLocation.length() - BANG_SEPARATOR.length()); jarURL = new URL(jarLoc); } return jarURL.openStream(); diff --git a/api/src/test/java/com/redhat/insights/jars/TestJarUtils.java b/api/src/test/java/com/redhat/insights/jars/TestJarUtils.java index 5b69e0b..aa00cef 100644 --- a/api/src/test/java/com/redhat/insights/jars/TestJarUtils.java +++ b/api/src/test/java/com/redhat/insights/jars/TestJarUtils.java @@ -8,6 +8,7 @@ import static org.junit.jupiter.api.Assertions.*; import java.io.ByteArrayOutputStream; +import java.io.File; import java.io.IOException; import java.io.InputStream; import java.net.URISyntaxException; @@ -53,5 +54,14 @@ public void basicCheckJarUrls() throws NoSuchAlgorithmException, IOException, UR } catch (Exception ex) { fail(ex); } + file = + "jar:file:" + + new File(System.getProperty("basedir")).toPath().toAbsolutePath().toString() + + "/target/test-classes/com/redhat/insights/jars/sti-sb-tomcat.jar!/BOOT-INF/lib/jackson-databind-2.13.5.jar!/"; + try { + getInputStream(new URL(file)); + } catch (Exception ex) { + fail(ex); + } } }