Skip to content

Commit

Permalink
DPE-443: Fix Jetty wrapper configuration at startup
Browse files Browse the repository at this point in the history
  • Loading branch information
stataru8 authored Nov 28, 2024
1 parent 53c4997 commit 03a51f8
Showing 1 changed file with 17 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,13 @@
import org.slf4j.LoggerFactory;

import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.lang.reflect.Field;
import java.net.InetSocketAddress;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
Expand Down Expand Up @@ -366,9 +370,19 @@ private void applyJettyConfiguration() throws Exception {
// PAXWEB-1112: TCCL to perform static initialization of XmlConfiguration with proper TCCL
// needed for org.eclipse.jetty.xml.XmlConfiguration.__factoryLoader
Thread.currentThread().setContextClassLoader(jettyXmlCl);
URL emptyConfig = getClass().getResource("/jetty-empty.xml");
if (emptyConfig != null) {
new XmlConfiguration(jettyFactory.newResource(emptyConfig));
String emptyConfigFile = "jetty-empty.xml";
try (InputStream inStream = getClass().getResourceAsStream("/" + emptyConfigFile)) {
if (inStream != null) {
Path emptyConfig = Files.createTempFile(emptyConfigFile, ".tmp");
try (FileOutputStream outStream = new FileOutputStream(new File(emptyConfig.toUri()))) {
inStream.transferTo(outStream);
new XmlConfiguration(jettyFactory.newResource(emptyConfig.toUri().toURL()));
} finally {
// the tmp file can be safely deleted as it was only used to initialize XmlConfiguration,
// and no actual configuration will be applied from it
Files.delete(emptyConfig);
}
}
}

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

0 comments on commit 03a51f8

Please sign in to comment.