From 006bd5dacc6f8e0d853a5e08865c77bacefdb239 Mon Sep 17 00:00:00 2001 From: Daniel Kec Date: Tue, 15 Sep 2020 13:00:57 +0200 Subject: [PATCH 1/5] ClassPathContentHandler can survive tmp folder cleanup Signed-off-by: Daniel Kec --- .../webserver/ClassPathContentHandler.java | 20 ++- .../helidon/webserver/UnstableTempTest.java | 131 ++++++++++++++++++ 2 files changed, 145 insertions(+), 6 deletions(-) create mode 100644 webserver/webserver/src/test/java/io/helidon/webserver/UnstableTempTest.java diff --git a/webserver/webserver/src/main/java/io/helidon/webserver/ClassPathContentHandler.java b/webserver/webserver/src/main/java/io/helidon/webserver/ClassPathContentHandler.java index 602f37440a0..600dc6c2b09 100644 --- a/webserver/webserver/src/main/java/io/helidon/webserver/ClassPathContentHandler.java +++ b/webserver/webserver/src/main/java/io/helidon/webserver/ClassPathContentHandler.java @@ -146,15 +146,16 @@ boolean doHandle(Http.RequestMethod method, String requestedPath, ServerRequest return true; } - private boolean sendJar(Http.RequestMethod method, - String requestedResource, - URL url, - ServerRequest request, - ServerResponse response) { + boolean sendJar(Http.RequestMethod method, + String requestedResource, + URL url, + ServerRequest request, + ServerResponse response) { LOGGER.fine(() -> "Sending static content from classpath: " + url); - ExtractedJarEntry extrEntry = extracted.computeIfAbsent(requestedResource, thePath -> extractJarEntry(url)); + ExtractedJarEntry extrEntry = extracted + .compute(requestedResource, (key, entry) -> existOrCreate(url, entry)); if (extrEntry.tempFile == null) { return false; } @@ -179,6 +180,13 @@ private boolean sendJar(Http.RequestMethod method, return true; } + private ExtractedJarEntry existOrCreate(URL url, ExtractedJarEntry entry) { + if (entry == null) return extractJarEntry(url); + if (entry.tempFile == null) return entry; + if (Files.notExists(entry.tempFile)) return extractJarEntry(url); + return entry; + } + private void sendUrlStream(Http.RequestMethod method, URL url, ServerRequest request, ServerResponse response) throws IOException { diff --git a/webserver/webserver/src/test/java/io/helidon/webserver/UnstableTempTest.java b/webserver/webserver/src/test/java/io/helidon/webserver/UnstableTempTest.java new file mode 100644 index 00000000000..d5629a3edac --- /dev/null +++ b/webserver/webserver/src/test/java/io/helidon/webserver/UnstableTempTest.java @@ -0,0 +1,131 @@ +/* + * Copyright (c) 2020 Oracle and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.helidon.webserver; + +import java.io.BufferedOutputStream; +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.net.URISyntaxException; +import java.net.URL; +import java.nio.ByteBuffer; +import java.nio.file.Path; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Objects; +import java.util.concurrent.Flow; +import java.util.function.Function; +import java.util.jar.Attributes; +import java.util.jar.JarEntry; +import java.util.jar.JarOutputStream; +import java.util.jar.Manifest; +import java.util.logging.Logger; + +import io.helidon.common.http.DataChunk; +import io.helidon.common.http.HashParameters; +import io.helidon.common.http.Http; +import io.helidon.common.reactive.Single; +import io.helidon.media.common.MessageBodyWriterContext; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.containsInAnyOrder; +import static org.hamcrest.Matchers.equalTo; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +import org.junit.jupiter.api.Test; +import org.mockito.Mockito; + +public class UnstableTempTest { + + private static final Logger LOGGER = Logger.getLogger(UnstableTempTest.class.getName()); + + private static final String JAR_NAME = "test.jar"; + private static final String FILE_NAME = "test.js"; + private static final String FILE_CONTENT = "alert(\"Hello, World!\");"; + + @Test + void cleanedTmpDuringRuntime() throws IOException { + List contents = new ArrayList<>(2); + + Path jar = createJar(); + URL jarUrl = new URL("jar:file:" + jar.toUri().getPath() + "!/" + FILE_NAME); + LOGGER.info("Generated test jar url: " + jarUrl.toString()); + ClassPathContentHandler classPathContentHandler = + new ClassPathContentHandler("index.html", + new ContentTypeSelector(null), + "/", + Thread.currentThread().getContextClassLoader()); + + // Empty headers + RequestHeaders headers = mock(RequestHeaders.class); + when(headers.isAccepted(any())).thenReturn(true); + when(headers.acceptedTypes()).thenReturn(Collections.emptyList()); + ResponseHeaders responseHeaders = mock(ResponseHeaders.class); + + ServerRequest request = Mockito.mock(ServerRequest.class); + Mockito.when(request.headers()).thenReturn(headers); + ServerResponse response = Mockito.mock(ServerResponse.class); + MessageBodyWriterContext ctx = MessageBodyWriterContext.create(HashParameters.create()); + ctx.registerFilter(dataChunkPub -> { + String fileContent = new String(Single.create(dataChunkPub).await().bytes()); + contents.add(fileContent); + return Single.just(DataChunk.create(ByteBuffer.wrap(fileContent.getBytes()))); + }); + Mockito.when(response.headers()).thenReturn(responseHeaders); + Mockito.when(response.send(Mockito.any(Function.class))).then(mock -> { + Function> argument = mock.getArgument(0); + return Single.create(argument.apply(ctx)).onError(throwable -> throwable.printStackTrace()); + }); + + classPathContentHandler.sendJar(Http.Method.GET, FILE_NAME, jarUrl, request, response); + deleteTmpFiles(); + classPathContentHandler.sendJar(Http.Method.GET, FILE_NAME, jarUrl, request, response); + + assertThat(contents, containsInAnyOrder(FILE_CONTENT, FILE_CONTENT)); + } + + private void deleteTmpFiles() throws IOException { + File tempDir = File.createTempFile("tempLocator", "je").getParentFile(); + LOGGER.info("Temp dir: " + tempDir.getAbsolutePath()); + //Delete all temp files + for (File file : Objects.requireNonNull(tempDir.listFiles((dir, name) -> name.endsWith(".je")))) { + assertThat("Unable to delete " + file.getName(), file.delete(), equalTo(Boolean.TRUE)); + LOGGER.info("File " + file.getName() + " deleted."); + } + } + + private Path createJar() { + try { + Path testJar = Path.of(UnstableTempTest.class.getResource("").toURI()).resolve(JAR_NAME); + Manifest manifest = new Manifest(); + manifest.getMainAttributes().put(Attributes.Name.MANIFEST_VERSION, "1.0"); + JarOutputStream target = new JarOutputStream(new FileOutputStream(testJar.toFile()), manifest); + JarEntry entry = new JarEntry(FILE_NAME); + BufferedOutputStream bos = new BufferedOutputStream(target); + target.putNextEntry(entry); + bos.write(FILE_CONTENT.getBytes()); + bos.close(); + target.close(); + return testJar; + } catch (IOException | URISyntaxException e) { + throw new RuntimeException(e); + } + } +} From 243f3fc2970404ed7692b39e868e0185ec75fadf Mon Sep 17 00:00:00 2001 From: Daniel Kec Date: Tue, 15 Sep 2020 15:51:08 +0200 Subject: [PATCH 2/5] Configurable temp dir for extracting static content from jar Signed-off-by: Daniel Kec --- .../server/ServerCdiExtension.java | 3 +++ .../webserver/ClassPathContentHandler.java | 8 +++++-- .../webserver/StaticContentSupport.java | 14 ++++++++++- .../webserver/StaticContentHandlerTest.java | 2 +- .../helidon/webserver/UnstableTempTest.java | 24 +++++++++++++------ 5 files changed, 40 insertions(+), 11 deletions(-) diff --git a/microprofile/server/src/main/java/io/helidon/microprofile/server/ServerCdiExtension.java b/microprofile/server/src/main/java/io/helidon/microprofile/server/ServerCdiExtension.java index f998e1ab24c..319d74d9dca 100644 --- a/microprofile/server/src/main/java/io/helidon/microprofile/server/ServerCdiExtension.java +++ b/microprofile/server/src/main/java/io/helidon/microprofile/server/ServerCdiExtension.java @@ -212,6 +212,9 @@ private void registerClasspathStaticContent(Config config) { cpBuilder.welcomeFileName(config.get("welcome") .asString() .orElse("index.html")); + config.get("tempFolder") + .as(Path.class) + .ifPresent(cpBuilder::tempFolder); StaticContentSupport staticContent = cpBuilder.build(); if (context.exists()) { diff --git a/webserver/webserver/src/main/java/io/helidon/webserver/ClassPathContentHandler.java b/webserver/webserver/src/main/java/io/helidon/webserver/ClassPathContentHandler.java index 600dc6c2b09..c7ebac7e5cc 100644 --- a/webserver/webserver/src/main/java/io/helidon/webserver/ClassPathContentHandler.java +++ b/webserver/webserver/src/main/java/io/helidon/webserver/ClassPathContentHandler.java @@ -49,14 +49,17 @@ class ClassPathContentHandler extends StaticContentHandler { private final Map extracted = new ConcurrentHashMap<>(); private final String root; private final String rootWithTrailingSlash; + private final Path tempDir; ClassPathContentHandler(String welcomeFilename, ContentTypeSelector contentTypeSelector, String root, + Path tempDir, ClassLoader classLoader) { super(welcomeFilename, contentTypeSelector); this.classLoader = (classLoader == null) ? this.getClass().getClassLoader() : classLoader; + this.tempDir = tempDir; this.root = root; this.rootWithTrailingSlash = root + '/'; } @@ -64,6 +67,7 @@ class ClassPathContentHandler extends StaticContentHandler { public static StaticContentHandler create(String welcomeFileName, ContentTypeSelector selector, String clRoot, + Path tempDir, ClassLoader classLoader) { ClassLoader contentClassloader = (classLoader == null) ? ClassPathContentHandler.class.getClassLoader() @@ -79,7 +83,7 @@ public static StaticContentHandler create(String welcomeFileName, throw new IllegalArgumentException("Cannot serve full classpath, please configure a classpath prefix"); } - return new ClassPathContentHandler(welcomeFileName, selector, clRoot, contentClassloader); + return new ClassPathContentHandler(welcomeFileName, selector, clRoot, tempDir, contentClassloader); } @SuppressWarnings("checkstyle:RegexpSinglelineJava") @@ -236,7 +240,7 @@ private ExtractedJarEntry extractJarEntry(URL url) { // Extract JAR entry to file try (InputStream is = jarFile.getInputStream(jarEntry)) { - Path tempFile = Files.createTempFile("ws", ".je"); + Path tempFile = Files.createTempFile(tempDir,"ws", ".je"); Files.copy(is, tempFile, StandardCopyOption.REPLACE_EXISTING); return new ExtractedJarEntry(tempFile, lastModified, jarEntry.getName()); } finally { diff --git a/webserver/webserver/src/main/java/io/helidon/webserver/StaticContentSupport.java b/webserver/webserver/src/main/java/io/helidon/webserver/StaticContentSupport.java index 42c59879984..af43379adb7 100644 --- a/webserver/webserver/src/main/java/io/helidon/webserver/StaticContentSupport.java +++ b/webserver/webserver/src/main/java/io/helidon/webserver/StaticContentSupport.java @@ -166,6 +166,7 @@ public static class Builder implements io.helidon.common.Builder specificContentTypes = new TreeMap<>(String.CASE_INSENSITIVE_ORDER); private String welcomeFileName; + private Path tempFolder; Builder(Path fsRoot) { Objects.requireNonNull(fsRoot, "Attribute fsRoot is null!"); @@ -195,6 +196,17 @@ public Builder welcomeFileName(String welcomeFileName) { return this; } + /** + * Sets custom temporary folder for extracting static content from a jar. + * + * @param tempFolder custom temporary folder + * @return updated builder + */ + public Builder tempFolder(Path tempFolder) { + this.tempFolder = tempFolder; + return this; + } + /** * Maps a filename extension to the response content type. * @@ -230,7 +242,7 @@ public StaticContentSupport build() { if (fsRoot != null) { handler = FileSystemContentHandler.create(welcomeFileName, selector, fsRoot); } else if (clRoot != null) { - handler = ClassPathContentHandler.create(welcomeFileName, selector, clRoot, classLoader); + handler = ClassPathContentHandler.create(welcomeFileName, selector, clRoot, tempFolder, classLoader); } else { throw new IllegalArgumentException("Builder was created without specified static content root!"); } diff --git a/webserver/webserver/src/test/java/io/helidon/webserver/StaticContentHandlerTest.java b/webserver/webserver/src/test/java/io/helidon/webserver/StaticContentHandlerTest.java index f99be7cab68..1ccd75ceb2d 100644 --- a/webserver/webserver/src/test/java/io/helidon/webserver/StaticContentHandlerTest.java +++ b/webserver/webserver/src/test/java/io/helidon/webserver/StaticContentHandlerTest.java @@ -261,7 +261,7 @@ static class TestClassPathContentHandler extends ClassPathContentHandler { final boolean returnValue; TestClassPathContentHandler(String welcomeFilename, ContentTypeSelector contentTypeSelector, Path root, boolean returnValue) { - super(welcomeFilename, contentTypeSelector, root.toString(), null); + super(welcomeFilename, contentTypeSelector, root.toString(), null, null); this.returnValue = returnValue; } diff --git a/webserver/webserver/src/test/java/io/helidon/webserver/UnstableTempTest.java b/webserver/webserver/src/test/java/io/helidon/webserver/UnstableTempTest.java index d5629a3edac..46d836d89d8 100644 --- a/webserver/webserver/src/test/java/io/helidon/webserver/UnstableTempTest.java +++ b/webserver/webserver/src/test/java/io/helidon/webserver/UnstableTempTest.java @@ -23,7 +23,9 @@ import java.net.URISyntaxException; import java.net.URL; import java.nio.ByteBuffer; +import java.nio.file.Files; import java.nio.file.Path; +import java.nio.file.Paths; import java.util.ArrayList; import java.util.Collections; import java.util.List; @@ -49,6 +51,7 @@ import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; +import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; import org.mockito.Mockito; @@ -59,6 +62,13 @@ public class UnstableTempTest { private static final String JAR_NAME = "test.jar"; private static final String FILE_NAME = "test.js"; private static final String FILE_CONTENT = "alert(\"Hello, World!\");"; + private static Path TEMP_DIR; + + @BeforeAll + static void beforeAll() throws IOException, URISyntaxException { + TEMP_DIR = Paths.get(UnstableTempTest.class.getResource("").toURI()).resolve("tmp"); + Files.createDirectories(TEMP_DIR); + } @Test void cleanedTmpDuringRuntime() throws IOException { @@ -66,11 +76,12 @@ void cleanedTmpDuringRuntime() throws IOException { Path jar = createJar(); URL jarUrl = new URL("jar:file:" + jar.toUri().getPath() + "!/" + FILE_NAME); - LOGGER.info("Generated test jar url: " + jarUrl.toString()); + LOGGER.fine(() -> "Generated test jar url: " + jarUrl.toString()); ClassPathContentHandler classPathContentHandler = - new ClassPathContentHandler("index.html", + new ClassPathContentHandler(null, new ContentTypeSelector(null), "/", + TEMP_DIR, Thread.currentThread().getContextClassLoader()); // Empty headers @@ -101,13 +112,12 @@ void cleanedTmpDuringRuntime() throws IOException { assertThat(contents, containsInAnyOrder(FILE_CONTENT, FILE_CONTENT)); } - private void deleteTmpFiles() throws IOException { - File tempDir = File.createTempFile("tempLocator", "je").getParentFile(); - LOGGER.info("Temp dir: " + tempDir.getAbsolutePath()); + private void deleteTmpFiles() { + LOGGER.fine(() -> "Temp dir: " + TEMP_DIR); //Delete all temp files - for (File file : Objects.requireNonNull(tempDir.listFiles((dir, name) -> name.endsWith(".je")))) { + for (File file : Objects.requireNonNull(TEMP_DIR.toFile().listFiles((dir, name) -> name.endsWith(".je")))) { assertThat("Unable to delete " + file.getName(), file.delete(), equalTo(Boolean.TRUE)); - LOGGER.info("File " + file.getName() + " deleted."); + LOGGER.fine("File " + file.getName() + " deleted."); } } From cc26f8ad08c6a97f629b39081853e38deb30ea3e Mon Sep 17 00:00:00 2001 From: Daniel Kec Date: Tue, 15 Sep 2020 16:11:50 +0200 Subject: [PATCH 3/5] NPE fix Signed-off-by: Daniel Kec --- .../webserver/ClassPathContentHandler.java | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/webserver/webserver/src/main/java/io/helidon/webserver/ClassPathContentHandler.java b/webserver/webserver/src/main/java/io/helidon/webserver/ClassPathContentHandler.java index c7ebac7e5cc..7397d70741e 100644 --- a/webserver/webserver/src/main/java/io/helidon/webserver/ClassPathContentHandler.java +++ b/webserver/webserver/src/main/java/io/helidon/webserver/ClassPathContentHandler.java @@ -240,7 +240,7 @@ private ExtractedJarEntry extractJarEntry(URL url) { // Extract JAR entry to file try (InputStream is = jarFile.getInputStream(jarEntry)) { - Path tempFile = Files.createTempFile(tempDir,"ws", ".je"); + Path tempFile = createTempFile("ws", ".je"); Files.copy(is, tempFile, StandardCopyOption.REPLACE_EXISTING); return new ExtractedJarEntry(tempFile, lastModified, jarEntry.getName()); } finally { @@ -253,6 +253,22 @@ private ExtractedJarEntry extractJarEntry(URL url) { } } + /** + * Create temp file in provided temp folder, or default one. + * + * @param prefix string to be used in generating the file's name. + * @param suffix string to be used in generating the file's name. + * @return the path to the newly created file + * @throws IOException + */ + private Path createTempFile(String prefix, String suffix) throws IOException { + if (tempDir != null) { + return Files.createTempFile(tempDir, prefix, suffix); + } else { + return Files.createTempFile(prefix, suffix); + } + } + private Instant getLastModified(String path) throws IOException { Path file = Paths.get(path); From 010e4235698a164ba0f379b714ea9b9a85de68fc Mon Sep 17 00:00:00 2001 From: Daniel Kec Date: Tue, 15 Sep 2020 16:25:23 +0200 Subject: [PATCH 4/5] Use Path instead of File Signed-off-by: Daniel Kec --- .../helidon/webserver/UnstableTempTest.java | 21 ++++++++++--------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/webserver/webserver/src/test/java/io/helidon/webserver/UnstableTempTest.java b/webserver/webserver/src/test/java/io/helidon/webserver/UnstableTempTest.java index 46d836d89d8..80fe973bfee 100644 --- a/webserver/webserver/src/test/java/io/helidon/webserver/UnstableTempTest.java +++ b/webserver/webserver/src/test/java/io/helidon/webserver/UnstableTempTest.java @@ -17,7 +17,6 @@ package io.helidon.webserver; import java.io.BufferedOutputStream; -import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.net.URISyntaxException; @@ -29,7 +28,6 @@ import java.util.ArrayList; import java.util.Collections; import java.util.List; -import java.util.Objects; import java.util.concurrent.Flow; import java.util.function.Function; import java.util.jar.Attributes; @@ -46,7 +44,7 @@ import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.containsInAnyOrder; -import static org.hamcrest.Matchers.equalTo; +import static org.junit.jupiter.api.Assertions.fail; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -112,13 +110,16 @@ void cleanedTmpDuringRuntime() throws IOException { assertThat(contents, containsInAnyOrder(FILE_CONTENT, FILE_CONTENT)); } - private void deleteTmpFiles() { - LOGGER.fine(() -> "Temp dir: " + TEMP_DIR); - //Delete all temp files - for (File file : Objects.requireNonNull(TEMP_DIR.toFile().listFiles((dir, name) -> name.endsWith(".je")))) { - assertThat("Unable to delete " + file.getName(), file.delete(), equalTo(Boolean.TRUE)); - LOGGER.fine("File " + file.getName() + " deleted."); - } + private void deleteTmpFiles() throws IOException { + LOGGER.fine(() -> "Cleaning temp dir: " + TEMP_DIR); + Files.list(TEMP_DIR) + .forEach(path -> { + try { + Files.deleteIfExists(path); + } catch (IOException e) { + fail("Unable to delete " + path.getFileName(), e); + } + }); } private Path createJar() { From c56c303a6b569ea7484293573013b9ea7bd5065f Mon Sep 17 00:00:00 2001 From: Daniel Kec Date: Mon, 28 Sep 2020 20:50:53 +0200 Subject: [PATCH 5/5] Review issues Signed-off-by: Daniel Kec --- .../microprofile/server/ServerCdiExtension.java | 4 ++-- .../io/helidon/webserver/StaticContentSupport.java | 10 +++++----- .../java/io/helidon/webserver/UnstableTempTest.java | 12 ++++++------ 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/microprofile/server/src/main/java/io/helidon/microprofile/server/ServerCdiExtension.java b/microprofile/server/src/main/java/io/helidon/microprofile/server/ServerCdiExtension.java index 319d74d9dca..417c6764fe0 100644 --- a/microprofile/server/src/main/java/io/helidon/microprofile/server/ServerCdiExtension.java +++ b/microprofile/server/src/main/java/io/helidon/microprofile/server/ServerCdiExtension.java @@ -212,9 +212,9 @@ private void registerClasspathStaticContent(Config config) { cpBuilder.welcomeFileName(config.get("welcome") .asString() .orElse("index.html")); - config.get("tempFolder") + config.get("tmp-dir") .as(Path.class) - .ifPresent(cpBuilder::tempFolder); + .ifPresent(cpBuilder::tmpDir); StaticContentSupport staticContent = cpBuilder.build(); if (context.exists()) { diff --git a/webserver/webserver/src/main/java/io/helidon/webserver/StaticContentSupport.java b/webserver/webserver/src/main/java/io/helidon/webserver/StaticContentSupport.java index af43379adb7..4f2b4ef9f0c 100644 --- a/webserver/webserver/src/main/java/io/helidon/webserver/StaticContentSupport.java +++ b/webserver/webserver/src/main/java/io/helidon/webserver/StaticContentSupport.java @@ -166,7 +166,7 @@ public static class Builder implements io.helidon.common.Builder specificContentTypes = new TreeMap<>(String.CASE_INSENSITIVE_ORDER); private String welcomeFileName; - private Path tempFolder; + private Path tmpDir; Builder(Path fsRoot) { Objects.requireNonNull(fsRoot, "Attribute fsRoot is null!"); @@ -199,11 +199,11 @@ public Builder welcomeFileName(String welcomeFileName) { /** * Sets custom temporary folder for extracting static content from a jar. * - * @param tempFolder custom temporary folder + * @param tmpDir custom temporary folder * @return updated builder */ - public Builder tempFolder(Path tempFolder) { - this.tempFolder = tempFolder; + public Builder tmpDir(Path tmpDir) { + this.tmpDir = tmpDir; return this; } @@ -242,7 +242,7 @@ public StaticContentSupport build() { if (fsRoot != null) { handler = FileSystemContentHandler.create(welcomeFileName, selector, fsRoot); } else if (clRoot != null) { - handler = ClassPathContentHandler.create(welcomeFileName, selector, clRoot, tempFolder, classLoader); + handler = ClassPathContentHandler.create(welcomeFileName, selector, clRoot, tmpDir, classLoader); } else { throw new IllegalArgumentException("Builder was created without specified static content root!"); } diff --git a/webserver/webserver/src/test/java/io/helidon/webserver/UnstableTempTest.java b/webserver/webserver/src/test/java/io/helidon/webserver/UnstableTempTest.java index 80fe973bfee..aa6501daa90 100644 --- a/webserver/webserver/src/test/java/io/helidon/webserver/UnstableTempTest.java +++ b/webserver/webserver/src/test/java/io/helidon/webserver/UnstableTempTest.java @@ -60,12 +60,12 @@ public class UnstableTempTest { private static final String JAR_NAME = "test.jar"; private static final String FILE_NAME = "test.js"; private static final String FILE_CONTENT = "alert(\"Hello, World!\");"; - private static Path TEMP_DIR; + private static Path tmpDir; @BeforeAll static void beforeAll() throws IOException, URISyntaxException { - TEMP_DIR = Paths.get(UnstableTempTest.class.getResource("").toURI()).resolve("tmp"); - Files.createDirectories(TEMP_DIR); + tmpDir = Paths.get(UnstableTempTest.class.getResource("").toURI()).resolve("tmp"); + Files.createDirectories(tmpDir); } @Test @@ -79,7 +79,7 @@ void cleanedTmpDuringRuntime() throws IOException { new ClassPathContentHandler(null, new ContentTypeSelector(null), "/", - TEMP_DIR, + tmpDir, Thread.currentThread().getContextClassLoader()); // Empty headers @@ -111,8 +111,8 @@ void cleanedTmpDuringRuntime() throws IOException { } private void deleteTmpFiles() throws IOException { - LOGGER.fine(() -> "Cleaning temp dir: " + TEMP_DIR); - Files.list(TEMP_DIR) + LOGGER.fine(() -> "Cleaning temp dir: " + tmpDir); + Files.list(tmpDir) .forEach(path -> { try { Files.deleteIfExists(path);