Skip to content

Commit

Permalink
workaround
Browse files Browse the repository at this point in the history
  • Loading branch information
stataru8 committed Nov 25, 2024
1 parent ee48faa commit 813b755
Showing 1 changed file with 15 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@
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;
Expand Down Expand Up @@ -366,17 +368,26 @@ 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));
Bundle bundle = FrameworkUtil.getBundle(this.getClass());
String fileName = "/jetty-empty.xml";
File emptyConfigFile = bundle.getDataFile(fileName);
if (emptyConfigFile != null) {
// by default the file is not physically there
if (!emptyConfigFile.createNewFile()) {
try (InputStream resourceStream = bundle.getResource(fileName).openStream();
FileOutputStream fos = new FileOutputStream(emptyConfigFile)) {
resourceStream.transferTo(fos);
}
}
URL emptyConfigURL = emptyConfigFile.toURL();
new XmlConfiguration(jettyFactory.newResource(emptyConfigURL));
}

// to load HttpFieldPreEncoder both for HTTP/1.1 and HTTP/2 we need to call static block
// of org.eclipse.jetty.http.PreEncodedHttpField class within proper ClassLoader
ClassLoader tccl = Thread.currentThread().getContextClassLoader();
try {
OsgiServletContextClassLoader cl = new OsgiServletContextClassLoader();
Bundle bundle = FrameworkUtil.getBundle(this.getClass());
if (bundle != null) {
// non unit-test
cl.addBundle(bundle);
Expand Down

0 comments on commit 813b755

Please sign in to comment.