This commit is contained in:
Justin Bertram 2023-12-05 10:57:08 -06:00
commit 6ebd611ed0
No known key found for this signature in database
GPG Key ID: F41830B875BB8633
2 changed files with 43 additions and 10 deletions

View File

@ -379,7 +379,9 @@ public class WebServerComponent implements ExternalComponent, WebServerComponent
webapp.setWar(warDirectory.resolve(warFile).toString());
webapp.setAttribute("org.eclipse.jetty.webapp.basetempdir", temporaryWarDir.toFile().getAbsolutePath());
String baseTempDir = temporaryWarDir.toFile().getAbsolutePath();
webapp.setAttribute("org.eclipse.jetty.webapp.basetempdir", baseTempDir);
webapp.setTempDirectory(new File(baseTempDir + File.separator + warFile));
// Set the default authenticator factory to avoid NPE due to the following commit:
// https://github.com/eclipse/jetty.project/commit/7e91d34177a880ecbe70009e8f200d02e3a0c5dd

View File

@ -560,15 +560,8 @@ public class WebServerComponentTest extends Assert {
createTestWar(warName);
final String url = "simple-app/";
AppDTO app = new AppDTO();
app.url = url;
app.war = warName;
BindingDTO bindingDTO = new BindingDTO();
bindingDTO.uri = "http://localhost:0";
bindingDTO.apps = new ArrayList<>();
WebServerDTO webServerDTO = new WebServerDTO();
webServerDTO.setBindings(Collections.singletonList(bindingDTO));
webServerDTO.path = "";
WebServerDTO webServerDTO = createDefaultWebServerDTO(warName, url);
WebServerComponent webServerComponent = new WebServerComponent();
Assert.assertFalse(webServerComponent.isStarted());
testedComponents.add(webServerComponent);
@ -603,6 +596,30 @@ public class WebServerComponentTest extends Assert {
Assert.assertFalse(webServerComponent.isStarted());
}
@Test
public void testServerDeterministicWebappName() throws Exception {
final String warName = "simple-app.war";
createTestWar(warName);
final String url = "simple-app/";
WebServerDTO webServerDTO = createDefaultWebServerDTO(warName, url);
WebServerComponent webServerComponent = new WebServerComponent();
webServerComponent.configure(webServerDTO, "./target", "./target");
WebAppContext ctxt = WebServerComponentTestAccessor.createWebAppContext(webServerComponent, url, warName, Paths.get(".").resolve("target").toAbsolutePath(), null);
testedComponents.add(webServerComponent);
Assert.assertFalse(webServerComponent.isStarted());
webServerComponent.start();
File tmpDir = ctxt.getTempDirectory();
Assert.assertTrue(tmpDir.getParentFile().listFiles().length == 1);
Assert.assertEquals(tmpDir.getName(), warName);
Assert.assertTrue(webServerComponent.isStarted());
webServerComponent.stop(true);
Assert.assertFalse(webServerComponent.isStarted());
}
@Test
public void testDefaultRootRedirect() throws Exception {
testRootRedirect(null, 404, null);
@ -642,6 +659,20 @@ public class WebServerComponentTest extends Assert {
}
}
private static WebServerDTO createDefaultWebServerDTO(String warName, String url) {
AppDTO app = new AppDTO();
app.url = url;
app.war = warName;
BindingDTO bindingDTO = new BindingDTO();
bindingDTO.uri = "http://localhost:0";
bindingDTO.apps = new ArrayList<>();
bindingDTO.apps.add(app);
WebServerDTO webServerDTO = new WebServerDTO();
webServerDTO.setBindings(Collections.singletonList(bindingDTO));
webServerDTO.path = "";
return webServerDTO;
}
private void createTestWar(String warName) throws Exception {
File warFile = new File("target", warName);
File srcFile = new File("src/test/webapp");