Revert "Issue #11260 - Allow `QuickStartConfiguration` to be used in mixed contexts environment where some do not have a WEB-INF/quickstart-web.xml"

This reverts commit d6015606ea.
This commit is contained in:
Joakim Erdfelt 2024-01-11 11:17:06 -06:00
parent d6015606ea
commit dc96d91eef
No known key found for this signature in database
GPG Key ID: 2D0E1FB8FE4B68B4
3 changed files with 27 additions and 84 deletions

View File

@ -48,7 +48,6 @@ public class QuickStartConfiguration extends AbstractConfiguration
public static final String ORIGIN_ATTRIBUTE = "org.eclipse.jetty.quickstart.origin"; public static final String ORIGIN_ATTRIBUTE = "org.eclipse.jetty.quickstart.origin";
public static final String QUICKSTART_WEB_XML = "org.eclipse.jetty.quickstart.xml"; public static final String QUICKSTART_WEB_XML = "org.eclipse.jetty.quickstart.xml";
public static final String MODE = "org.eclipse.jetty.quickstart.mode"; public static final String MODE = "org.eclipse.jetty.quickstart.mode";
public static final String QUICKSTART_ENABLED = "org.eclipse.jetty.quickstart.enabled";
static static
{ {
@ -78,6 +77,7 @@ public class QuickStartConfiguration extends AbstractConfiguration
} }
private Mode _mode = Mode.AUTO; private Mode _mode = Mode.AUTO;
private boolean _quickStart;
public QuickStartConfiguration() public QuickStartConfiguration()
{ {
@ -86,14 +86,6 @@ public class QuickStartConfiguration extends AbstractConfiguration
addDependents(WebXmlConfiguration.class); addDependents(WebXmlConfiguration.class);
} }
private boolean isQuickStartEnabled(WebAppContext context)
{
Boolean enabled = (Boolean)context.getAttribute(QUICKSTART_ENABLED);
if (enabled == null)
return true; // default is true
return enabled;
}
@Override @Override
public void preConfigure(WebAppContext context) throws Exception public void preConfigure(WebAppContext context) throws Exception
{ {
@ -110,10 +102,9 @@ public class QuickStartConfiguration extends AbstractConfiguration
Mode mode = (Mode)context.getAttribute(MODE); Mode mode = (Mode)context.getAttribute(MODE);
if (mode != null) if (mode != null)
_mode = mode; _mode = mode;
// disable quickstart for this context (it is only enabled if AUTO or QUICKSTART mode succeeds) _quickStart = false;
context.setAttribute(QUICKSTART_ENABLED, false);
switch (_mode) switch (_mode)
{ {
case GENERATE: case GENERATE:
@ -148,9 +139,7 @@ public class QuickStartConfiguration extends AbstractConfiguration
if (quickStartWebXml.exists()) if (quickStartWebXml.exists())
quickStart(context); quickStart(context);
else else
{ throw new IllegalStateException("No " + quickStartWebXml);
LOG.warn("Skipping {} for {} as it does not contain {}", this.getClass().getName(), context, quickStartWebXml);
}
break; break;
default: default:
@ -171,42 +160,37 @@ public class QuickStartConfiguration extends AbstractConfiguration
@Override @Override
public void configure(WebAppContext context) throws Exception public void configure(WebAppContext context) throws Exception
{ {
if (!isQuickStartEnabled(context)) if (!_quickStart)
{ {
return; super.configure(context);
} }
else
{
//add the processor to handle normal web.xml content
context.getMetaData().addDescriptorProcessor(new StandardDescriptorProcessor());
//add the processor to handle normal web.xml content //add a processor to handle extended web.xml format
context.getMetaData().addDescriptorProcessor(new StandardDescriptorProcessor()); context.getMetaData().addDescriptorProcessor(new QuickStartDescriptorProcessor());
//add a processor to handle extended web.xml format //add a decorator that will find introspectable annotations
context.getMetaData().addDescriptorProcessor(new QuickStartDescriptorProcessor()); context.getObjectFactory().addDecorator(new AnnotationDecorator(context)); //this must be the last Decorator because they are run in reverse order!
//add a decorator that will find introspectable annotations //add a context bean that will run ServletContainerInitializers as the context starts
context.getObjectFactory().addDecorator(new AnnotationDecorator(context)); //this must be the last Decorator because they are run in reverse order! ServletContainerInitializersStarter starter = (ServletContainerInitializersStarter)context.getAttribute(AnnotationConfiguration.CONTAINER_INITIALIZER_STARTER);
if (starter != null)
throw new IllegalStateException("ServletContainerInitializersStarter already exists");
starter = new ServletContainerInitializersStarter(context);
context.setAttribute(AnnotationConfiguration.CONTAINER_INITIALIZER_STARTER, starter);
context.addBean(starter, true);
//add a context bean that will run ServletContainerInitializers as the context starts LOG.debug("configured {}", this);
ServletContainerInitializersStarter starter = (ServletContainerInitializersStarter)context.getAttribute(AnnotationConfiguration.CONTAINER_INITIALIZER_STARTER); }
if (starter != null)
throw new IllegalStateException("ServletContainerInitializersStarter already exists");
starter = new ServletContainerInitializersStarter(context);
context.setAttribute(AnnotationConfiguration.CONTAINER_INITIALIZER_STARTER, starter);
context.addBean(starter, true);
LOG.debug("configured {}", this);
} }
@Override @Override
public void postConfigure(WebAppContext context) throws Exception public void postConfigure(WebAppContext context) throws Exception
{ {
if (!isQuickStartEnabled(context)) super.postConfigure(context);
{
super.postConfigure(context);
return;
}
context.removeAttribute(QUICKSTART_ENABLED);
ServletContainerInitializersStarter starter = (ServletContainerInitializersStarter)context.getAttribute(AnnotationConfiguration.CONTAINER_INITIALIZER_STARTER); ServletContainerInitializersStarter starter = (ServletContainerInitializersStarter)context.getAttribute(AnnotationConfiguration.CONTAINER_INITIALIZER_STARTER);
if (starter != null) if (starter != null)
{ {
@ -219,7 +203,7 @@ public class QuickStartConfiguration extends AbstractConfiguration
throws Exception throws Exception
{ {
LOG.info("Quickstarting {}", context); LOG.info("Quickstarting {}", context);
context.setAttribute(QUICKSTART_ENABLED, true); _quickStart = true;
context.setConfigurations(context.getConfigurations().stream() context.setConfigurations(context.getConfigurations().stream()
.filter(c -> !__replacedConfigurations.contains(c.replaces()) && !__replacedConfigurations.contains(c.getClass())) .filter(c -> !__replacedConfigurations.contains(c.replaces()) && !__replacedConfigurations.contains(c.getClass()))
.collect(Collectors.toList()).toArray(new Configuration[]{})); .collect(Collectors.toList()).toArray(new Configuration[]{}));
@ -245,10 +229,7 @@ public class QuickStartConfiguration extends AbstractConfiguration
if (webInf == null || !webInf.exists()) if (webInf == null || !webInf.exists())
{ {
File tmp = new File(context.getBaseResource().getFile(), "WEB-INF"); File tmp = new File(context.getBaseResource().getFile(), "WEB-INF");
if (!tmp.mkdirs()) tmp.mkdirs();
{
throw new IllegalStateException("Unable to create directory " + tmp);
}
webInf = context.getWebInf(); webInf = context.getWebInf();
} }

View File

@ -24,8 +24,6 @@ import org.eclipse.jetty.plus.webapp.EnvConfiguration;
import org.eclipse.jetty.plus.webapp.PlusConfiguration; import org.eclipse.jetty.plus.webapp.PlusConfiguration;
import org.eclipse.jetty.server.NetworkConnector; import org.eclipse.jetty.server.NetworkConnector;
import org.eclipse.jetty.server.Server; import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.toolchain.test.FS;
import org.eclipse.jetty.toolchain.test.MavenPaths;
import org.eclipse.jetty.toolchain.test.MavenTestingUtils; import org.eclipse.jetty.toolchain.test.MavenTestingUtils;
import org.eclipse.jetty.util.IO; import org.eclipse.jetty.util.IO;
import org.eclipse.jetty.util.resource.PathResource; import org.eclipse.jetty.util.resource.PathResource;
@ -43,41 +41,6 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
public class QuickStartTest public class QuickStartTest
{ {
/**
* Test of an exploded webapp directory, no WEB-INF/quickstart-web.xml,
* with QuickStartConfiguration enabled.
*/
@Test
public void testExplodedWebAppDirNoWebXml() throws Exception
{
Path jettyHome = MavenPaths.targetDir();
Path webappDir = MavenPaths.targetTestDir("no-web-xml");
Path src = MavenPaths.projectBase().resolve("src/test/webapps/no-web-xml");
FS.ensureEmpty(webappDir);
org.eclipse.jetty.toolchain.test.IO.copyDir(src, webappDir);
System.setProperty("jetty.home", jettyHome.toString());
Server server = new Server(0);
WebAppContext webapp = new WebAppContext();
webapp.addConfiguration(new QuickStartConfiguration(),
new EnvConfiguration(),
new PlusConfiguration(),
new AnnotationConfiguration());
webapp.setAttribute(QuickStartConfiguration.MODE, QuickStartConfiguration.Mode.QUICKSTART);
webapp.setWarResource(new PathResource(webappDir));
webapp.setContextPath("/");
server.setHandler(webapp);
server.start();
URL url = new URL("http://127.0.0.1:" + server.getBean(NetworkConnector.class).getLocalPort() + "/index.html");
HttpURLConnection connection = (HttpURLConnection)url.openConnection();
assertEquals(200, connection.getResponseCode());
assertThat(IO.toString((InputStream)connection.getContent()), Matchers.containsString("<p>Contents of no-web-xml</p>"));
server.stop();
}
@Test @Test
public void testStandardTestWar() throws Exception public void testStandardTestWar() throws Exception

View File

@ -1 +0,0 @@
<p>Contents of no-web-xml</p>