Skip to content

Commit 03a51f8

Browse files
authored
DPE-443: Fix Jetty wrapper configuration at startup
1 parent 53c4997 commit 03a51f8

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

pax-web-jetty/src/main/java/org/ops4j/pax/web/service/jetty/internal/JettyServerWrapper.java

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,9 +123,13 @@
123123
import org.slf4j.LoggerFactory;
124124

125125
import java.io.File;
126+
import java.io.FileOutputStream;
127+
import java.io.InputStream;
126128
import java.lang.reflect.Field;
127129
import java.net.InetSocketAddress;
128130
import java.net.URL;
131+
import java.nio.file.Files;
132+
import java.nio.file.Path;
129133
import java.util.ArrayList;
130134
import java.util.Arrays;
131135
import java.util.Collection;
@@ -366,9 +370,19 @@ private void applyJettyConfiguration() throws Exception {
366370
// PAXWEB-1112: TCCL to perform static initialization of XmlConfiguration with proper TCCL
367371
// needed for org.eclipse.jetty.xml.XmlConfiguration.__factoryLoader
368372
Thread.currentThread().setContextClassLoader(jettyXmlCl);
369-
URL emptyConfig = getClass().getResource("/jetty-empty.xml");
370-
if (emptyConfig != null) {
371-
new XmlConfiguration(jettyFactory.newResource(emptyConfig));
373+
String emptyConfigFile = "jetty-empty.xml";
374+
try (InputStream inStream = getClass().getResourceAsStream("/" + emptyConfigFile)) {
375+
if (inStream != null) {
376+
Path emptyConfig = Files.createTempFile(emptyConfigFile, ".tmp");
377+
try (FileOutputStream outStream = new FileOutputStream(new File(emptyConfig.toUri()))) {
378+
inStream.transferTo(outStream);
379+
new XmlConfiguration(jettyFactory.newResource(emptyConfig.toUri().toURL()));
380+
} finally {
381+
// the tmp file can be safely deleted as it was only used to initialize XmlConfiguration,
382+
// and no actual configuration will be applied from it
383+
Files.delete(emptyConfig);
384+
}
385+
}
372386
}
373387

374388
// to load HttpFieldPreEncoder both for HTTP/1.1 and HTTP/2 we need to call static block

0 commit comments

Comments
 (0)