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:
parent
d6015606ea
commit
dc96d91eef
|
@ -48,7 +48,6 @@ public class QuickStartConfiguration extends AbstractConfiguration
|
|||
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 MODE = "org.eclipse.jetty.quickstart.mode";
|
||||
public static final String QUICKSTART_ENABLED = "org.eclipse.jetty.quickstart.enabled";
|
||||
|
||||
static
|
||||
{
|
||||
|
@ -78,6 +77,7 @@ public class QuickStartConfiguration extends AbstractConfiguration
|
|||
}
|
||||
|
||||
private Mode _mode = Mode.AUTO;
|
||||
private boolean _quickStart;
|
||||
|
||||
public QuickStartConfiguration()
|
||||
{
|
||||
|
@ -86,14 +86,6 @@ public class QuickStartConfiguration extends AbstractConfiguration
|
|||
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
|
||||
public void preConfigure(WebAppContext context) throws Exception
|
||||
{
|
||||
|
@ -110,10 +102,9 @@ public class QuickStartConfiguration extends AbstractConfiguration
|
|||
Mode mode = (Mode)context.getAttribute(MODE);
|
||||
if (mode != null)
|
||||
_mode = mode;
|
||||
|
||||
// disable quickstart for this context (it is only enabled if AUTO or QUICKSTART mode succeeds)
|
||||
context.setAttribute(QUICKSTART_ENABLED, false);
|
||||
|
||||
|
||||
_quickStart = false;
|
||||
|
||||
switch (_mode)
|
||||
{
|
||||
case GENERATE:
|
||||
|
@ -148,9 +139,7 @@ public class QuickStartConfiguration extends AbstractConfiguration
|
|||
if (quickStartWebXml.exists())
|
||||
quickStart(context);
|
||||
else
|
||||
{
|
||||
LOG.warn("Skipping {} for {} as it does not contain {}", this.getClass().getName(), context, quickStartWebXml);
|
||||
}
|
||||
throw new IllegalStateException("No " + quickStartWebXml);
|
||||
break;
|
||||
|
||||
default:
|
||||
|
@ -171,42 +160,37 @@ public class QuickStartConfiguration extends AbstractConfiguration
|
|||
@Override
|
||||
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
|
||||
context.getMetaData().addDescriptorProcessor(new StandardDescriptorProcessor());
|
||||
//add a processor to handle extended web.xml format
|
||||
context.getMetaData().addDescriptorProcessor(new QuickStartDescriptorProcessor());
|
||||
|
||||
//add a processor to handle extended web.xml format
|
||||
context.getMetaData().addDescriptorProcessor(new QuickStartDescriptorProcessor());
|
||||
//add a decorator that will find introspectable annotations
|
||||
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
|
||||
context.getObjectFactory().addDecorator(new AnnotationDecorator(context)); //this must be the last Decorator because they are run in reverse order!
|
||||
//add a context bean that will run ServletContainerInitializers as the context starts
|
||||
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
|
||||
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);
|
||||
LOG.debug("configured {}", this);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void postConfigure(WebAppContext context) throws Exception
|
||||
{
|
||||
if (!isQuickStartEnabled(context))
|
||||
{
|
||||
super.postConfigure(context);
|
||||
return;
|
||||
}
|
||||
|
||||
context.removeAttribute(QUICKSTART_ENABLED);
|
||||
|
||||
super.postConfigure(context);
|
||||
ServletContainerInitializersStarter starter = (ServletContainerInitializersStarter)context.getAttribute(AnnotationConfiguration.CONTAINER_INITIALIZER_STARTER);
|
||||
if (starter != null)
|
||||
{
|
||||
|
@ -219,7 +203,7 @@ public class QuickStartConfiguration extends AbstractConfiguration
|
|||
throws Exception
|
||||
{
|
||||
LOG.info("Quickstarting {}", context);
|
||||
context.setAttribute(QUICKSTART_ENABLED, true);
|
||||
_quickStart = true;
|
||||
context.setConfigurations(context.getConfigurations().stream()
|
||||
.filter(c -> !__replacedConfigurations.contains(c.replaces()) && !__replacedConfigurations.contains(c.getClass()))
|
||||
.collect(Collectors.toList()).toArray(new Configuration[]{}));
|
||||
|
@ -245,10 +229,7 @@ public class QuickStartConfiguration extends AbstractConfiguration
|
|||
if (webInf == null || !webInf.exists())
|
||||
{
|
||||
File tmp = new File(context.getBaseResource().getFile(), "WEB-INF");
|
||||
if (!tmp.mkdirs())
|
||||
{
|
||||
throw new IllegalStateException("Unable to create directory " + tmp);
|
||||
}
|
||||
tmp.mkdirs();
|
||||
webInf = context.getWebInf();
|
||||
}
|
||||
|
||||
|
|
|
@ -24,8 +24,6 @@ import org.eclipse.jetty.plus.webapp.EnvConfiguration;
|
|||
import org.eclipse.jetty.plus.webapp.PlusConfiguration;
|
||||
import org.eclipse.jetty.server.NetworkConnector;
|
||||
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.util.IO;
|
||||
import org.eclipse.jetty.util.resource.PathResource;
|
||||
|
@ -43,41 +41,6 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
|
|||
|
||||
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
|
||||
public void testStandardTestWar() throws Exception
|
||||
|
|
|
@ -1 +0,0 @@
|
|||
<p>Contents of no-web-xml</p>
|
Loading…
Reference in New Issue