Signed-off-by: Jan Bartel <janb@webtide.com>
This commit is contained in:
parent
5f94f249a7
commit
a2032701ef
|
@ -203,6 +203,9 @@ public class QuickStartGeneratorConfiguration extends AbstractConfiguration
|
||||||
//the META-INF/resources discovered
|
//the META-INF/resources discovered
|
||||||
addContextParamFromAttribute(context,out,MetaInfConfiguration.METAINF_RESOURCES,normalizer);
|
addContextParamFromAttribute(context,out,MetaInfConfiguration.METAINF_RESOURCES,normalizer);
|
||||||
|
|
||||||
|
// the default-context-path, if presernt
|
||||||
|
String defaultContextPath = (String) context.getAttribute("default-context-path");
|
||||||
|
if (defaultContextPath != null) out.tag("default-context-path", defaultContextPath);
|
||||||
|
|
||||||
//add the name of the origin attribute, if it is being used
|
//add the name of the origin attribute, if it is being used
|
||||||
if (_generateOrigin)
|
if (_generateOrigin)
|
||||||
|
|
|
@ -22,6 +22,8 @@ package org.eclipse.jetty.quickstart;
|
||||||
import static org.junit.jupiter.api.Assertions.*;
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.net.URLClassLoader;
|
||||||
|
|
||||||
import org.eclipse.jetty.server.Server;
|
import org.eclipse.jetty.server.Server;
|
||||||
import org.eclipse.jetty.servlet.ListenerHolder;
|
import org.eclipse.jetty.servlet.ListenerHolder;
|
||||||
|
@ -53,7 +55,6 @@ public class TestQuickStart
|
||||||
@Test
|
@Test
|
||||||
public void testProgrammaticOverrideOfDefaultServletMapping() throws Exception
|
public void testProgrammaticOverrideOfDefaultServletMapping() throws Exception
|
||||||
{
|
{
|
||||||
|
|
||||||
File quickstartXml = new File(webInf, "quickstart-web.xml");
|
File quickstartXml = new File(webInf, "quickstart-web.xml");
|
||||||
assertFalse(quickstartXml.exists());
|
assertFalse(quickstartXml.exists());
|
||||||
|
|
||||||
|
@ -81,7 +82,7 @@ public class TestQuickStart
|
||||||
QuickStartWebApp webapp = new QuickStartWebApp();
|
QuickStartWebApp webapp = new QuickStartWebApp();
|
||||||
webapp.setResourceBase(testDir.getAbsolutePath());
|
webapp.setResourceBase(testDir.getAbsolutePath());
|
||||||
webapp.setMode(QuickStartConfiguration.Mode.QUICKSTART);
|
webapp.setMode(QuickStartConfiguration.Mode.QUICKSTART);
|
||||||
webapp.setClassLoader(Thread.currentThread().getContextClassLoader()); //only necessary for junit testing
|
webapp.setClassLoader(new URLClassLoader(new URL[0], Thread.currentThread().getContextClassLoader()));
|
||||||
server.setHandler(webapp);
|
server.setHandler(webapp);
|
||||||
|
|
||||||
server.start();
|
server.start();
|
||||||
|
@ -90,7 +91,47 @@ public class TestQuickStart
|
||||||
ServletHolder sh = webapp.getServletHandler().getMappedServlet("/").getResource();
|
ServletHolder sh = webapp.getServletHandler().getMappedServlet("/").getResource();
|
||||||
assertNotNull(sh);
|
assertNotNull(sh);
|
||||||
assertEquals("foo", sh.getName());
|
assertEquals("foo", sh.getName());
|
||||||
|
|
||||||
server.stop();
|
server.stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testDefaultContextPath() throws Exception
|
||||||
|
{
|
||||||
|
File quickstartXml = new File(webInf, "quickstart-web.xml");
|
||||||
|
assertFalse(quickstartXml.exists());
|
||||||
|
|
||||||
|
Server server = new Server();
|
||||||
|
|
||||||
|
// generate a quickstart-web.xml
|
||||||
|
QuickStartWebApp quickstart = new QuickStartWebApp();
|
||||||
|
quickstart.setResourceBase(testDir.getAbsolutePath());
|
||||||
|
quickstart.setMode(QuickStartConfiguration.Mode.GENERATE);
|
||||||
|
quickstart.setGenerateOrigin(true);
|
||||||
|
quickstart.setDescriptor(MavenTestingUtils.getTestResourceFile("web.xml").getAbsolutePath());
|
||||||
|
quickstart.setContextPath("/foo");
|
||||||
|
server.setHandler(quickstart);
|
||||||
|
server.start();
|
||||||
|
|
||||||
|
assertEquals("/foo", quickstart.getContextPath());
|
||||||
|
assertFalse(quickstart.isContextPathDefault());
|
||||||
|
server.stop();
|
||||||
|
|
||||||
|
assertTrue(quickstartXml.exists());
|
||||||
|
|
||||||
|
// quick start
|
||||||
|
QuickStartWebApp webapp = new QuickStartWebApp();
|
||||||
|
webapp.setResourceBase(testDir.getAbsolutePath());
|
||||||
|
webapp.setMode(QuickStartConfiguration.Mode.QUICKSTART);
|
||||||
|
webapp.setClassLoader(new URLClassLoader(new URL[0], Thread.currentThread().getContextClassLoader()));
|
||||||
|
server.setHandler(webapp);
|
||||||
|
|
||||||
|
server.start();
|
||||||
|
|
||||||
|
// verify the context path is the default-context-path
|
||||||
|
assertEquals("/thisIsTheDefault", webapp.getContextPath());
|
||||||
|
assertTrue(webapp.isContextPathDefault());
|
||||||
|
|
||||||
|
server.stop();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,16 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<web-app
|
||||||
|
xmlns="http://xmlns.jcp.org/xml/ns/javaee"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"
|
||||||
|
metadata-complete="false"
|
||||||
|
version="4.0">
|
||||||
|
|
||||||
|
<display-name>Test WebApp</display-name>
|
||||||
|
|
||||||
|
|
||||||
|
<default-context-path>/thisIsTheDefault</default-context-path>
|
||||||
|
|
||||||
|
</web-app>
|
||||||
|
|
||||||
|
|
|
@ -1967,9 +1967,11 @@ public class StandardDescriptorProcessor extends IterativeDescriptorProcessor
|
||||||
{
|
{
|
||||||
if (!(descriptor instanceof FragmentDescriptor))
|
if (!(descriptor instanceof FragmentDescriptor))
|
||||||
{
|
{
|
||||||
|
String path = node.toString(false, true);
|
||||||
|
context.setAttribute("default-context-path", path);
|
||||||
if (context.isContextPathDefault())
|
if (context.isContextPathDefault())
|
||||||
{
|
{
|
||||||
context.setContextPath(node.toString(false, true));
|
context.setDefaultContextPath(path);
|
||||||
context.getMetaData().setOrigin("default-context-path", descriptor);
|
context.getMetaData().setOrigin("default-context-path", descriptor);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue