use of org.eclipse.jetty.webapp.WebDescriptor in project jetty.project by eclipse.
the class QuickStartTest method testStandardTestWar.
@Test
public void testStandardTestWar() throws Exception {
PreconfigureStandardTestWar.main(new String[] {});
WebDescriptor descriptor = new WebDescriptor(Resource.newResource("./target/test-standard-preconfigured/WEB-INF/quickstart-web.xml"));
descriptor.setValidating(true);
descriptor.parse();
Node node = descriptor.getRoot();
assertThat(node, Matchers.notNullValue());
System.setProperty("jetty.home", "target");
//war file or dir to start
String war = "target/test-standard-preconfigured";
//optional jetty context xml file to configure the webapp
Resource contextXml = Resource.newResource("src/test/resources/test.xml");
Server server = new Server(0);
QuickStartWebApp webapp = new QuickStartWebApp();
webapp.setAutoPreconfigure(true);
webapp.setWar(war);
webapp.setContextPath("/");
//apply context xml file
if (contextXml != null) {
// System.err.println("Applying "+contextXml);
XmlConfiguration xmlConfiguration = new XmlConfiguration(contextXml.getURL());
xmlConfiguration.configure(webapp);
}
server.setHandler(webapp);
server.start();
URL url = new URL("http://127.0.0.1:" + server.getBean(NetworkConnector.class).getLocalPort() + "/test/dump/info");
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
assertEquals(200, connection.getResponseCode());
assertThat(IO.toString((InputStream) connection.getContent()), Matchers.containsString("Dump Servlet"));
server.stop();
}
use of org.eclipse.jetty.webapp.WebDescriptor in project jetty.project by eclipse.
the class PlusDescriptorProcessorTest method testWebXmlResourceDeclarations.
@Test
public void testWebXmlResourceDeclarations() throws Exception {
//if declared in web.xml, fragment declarations ignored
ClassLoader oldLoader = Thread.currentThread().getContextClassLoader();
Thread.currentThread().setContextClassLoader(context.getClassLoader());
try {
PlusDescriptorProcessor pdp = new PlusDescriptorProcessor();
pdp.process(context, webDescriptor);
Descriptor d = context.getMetaData().getOriginDescriptor("resource-ref.jdbc/mydatasource");
assertNotNull(d);
assertTrue(d == webDescriptor);
pdp.process(context, fragDescriptor1);
pdp.process(context, fragDescriptor2);
} finally {
Thread.currentThread().setContextClassLoader(oldLoader);
}
}
use of org.eclipse.jetty.webapp.WebDescriptor in project jetty.project by eclipse.
the class QuickStartTest method testSpecWar.
@Test
public void testSpecWar() throws Exception {
PreconfigureSpecWar.main(new String[] {});
WebDescriptor descriptor = new WebDescriptor(Resource.newResource("./target/test-spec-preconfigured/WEB-INF/quickstart-web.xml"));
descriptor.setValidating(true);
descriptor.parse();
Node node = descriptor.getRoot();
assertThat(node, Matchers.notNullValue());
System.setProperty("jetty.home", "target");
//war file or dir to start
String war = "target/test-spec-preconfigured";
//optional jetty context xml file to configure the webapp
Resource contextXml = Resource.newResource("src/test/resources/test-spec.xml");
Server server = new Server(0);
QuickStartWebApp webapp = new QuickStartWebApp();
webapp.setAutoPreconfigure(true);
webapp.setWar(war);
webapp.setContextPath("/");
//apply context xml file
if (contextXml != null) {
// System.err.println("Applying "+contextXml);
XmlConfiguration xmlConfiguration = new XmlConfiguration(contextXml.getURL());
xmlConfiguration.configure(webapp);
}
server.setHandler(webapp);
server.start();
URL url = new URL("http://127.0.0.1:" + server.getBean(NetworkConnector.class).getLocalPort() + "/");
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
assertEquals(200, connection.getResponseCode());
assertThat(IO.toString((InputStream) connection.getContent()), Matchers.containsString("Test Specification WebApp"));
server.stop();
}
use of org.eclipse.jetty.webapp.WebDescriptor in project jetty.project by eclipse.
the class QuickStartTest method testJNDIWar.
@Test
public void testJNDIWar() throws Exception {
PreconfigureJNDIWar.main(new String[] {});
WebDescriptor descriptor = new WebDescriptor(Resource.newResource("./target/test-jndi-preconfigured/WEB-INF/quickstart-web.xml"));
descriptor.setValidating(true);
descriptor.parse();
Node node = descriptor.getRoot();
assertThat(node, Matchers.notNullValue());
System.setProperty("jetty.home", "target");
//war file or dir to start
String war = "target/test-jndi-preconfigured";
//optional jetty context xml file to configure the webapp
Resource contextXml = Resource.newResource("src/test/resources/test-jndi.xml");
Server server = new Server(0);
QuickStartWebApp webapp = new QuickStartWebApp();
webapp.setAutoPreconfigure(true);
webapp.setWar(war);
webapp.setContextPath("/");
//apply context xml file
if (contextXml != null) {
// System.err.println("Applying "+contextXml);
XmlConfiguration xmlConfiguration = new XmlConfiguration(contextXml.getURI().toURL());
xmlConfiguration.configure(webapp);
}
server.setHandler(webapp);
server.start();
URL url = new URL("http://127.0.0.1:" + server.getBean(NetworkConnector.class).getLocalPort() + "/");
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
assertEquals(200, connection.getResponseCode());
String content = IO.toString((InputStream) connection.getContent());
assertThat(content, Matchers.containsString("JNDI Test WebApp"));
server.stop();
}
use of org.eclipse.jetty.webapp.WebDescriptor in project jetty.project by eclipse.
the class PlusDescriptorProcessorTest method setUp.
@Before
public void setUp() throws Exception {
context = new WebAppContext();
context.setClassLoader(new WebAppClassLoader(Thread.currentThread().getContextClassLoader(), context));
ClassLoader oldLoader = Thread.currentThread().getContextClassLoader();
Thread.currentThread().setContextClassLoader(context.getClassLoader());
Context icontext = new InitialContext();
Context compCtx = (Context) icontext.lookup("java:comp");
compCtx.createSubcontext("env");
Thread.currentThread().setContextClassLoader(oldLoader);
org.eclipse.jetty.plus.jndi.Resource ds = new org.eclipse.jetty.plus.jndi.Resource(context, "jdbc/mydatasource", new Object());
URL webXml = Thread.currentThread().getContextClassLoader().getResource("web.xml");
webDescriptor = new WebDescriptor(org.eclipse.jetty.util.resource.Resource.newResource(webXml));
webDescriptor.parse();
URL frag1Xml = Thread.currentThread().getContextClassLoader().getResource("web-fragment-1.xml");
fragDescriptor1 = new FragmentDescriptor(org.eclipse.jetty.util.resource.Resource.newResource(frag1Xml));
fragDescriptor1.parse();
URL frag2Xml = Thread.currentThread().getContextClassLoader().getResource("web-fragment-2.xml");
fragDescriptor2 = new FragmentDescriptor(org.eclipse.jetty.util.resource.Resource.newResource(frag2Xml));
fragDescriptor2.parse();
URL frag3Xml = Thread.currentThread().getContextClassLoader().getResource("web-fragment-3.xml");
fragDescriptor3 = new FragmentDescriptor(org.eclipse.jetty.util.resource.Resource.newResource(frag3Xml));
fragDescriptor3.parse();
URL frag4Xml = Thread.currentThread().getContextClassLoader().getResource("web-fragment-4.xml");
fragDescriptor4 = new FragmentDescriptor(org.eclipse.jetty.util.resource.Resource.newResource(frag4Xml));
fragDescriptor4.parse();
}
Aggregations