Search in sources :

Example 1 with WebDescriptor

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();
}
Also used : WebDescriptor(org.eclipse.jetty.webapp.WebDescriptor) HttpURLConnection(java.net.HttpURLConnection) Server(org.eclipse.jetty.server.Server) InputStream(java.io.InputStream) Node(org.eclipse.jetty.xml.XmlParser.Node) Resource(org.eclipse.jetty.util.resource.Resource) XmlConfiguration(org.eclipse.jetty.xml.XmlConfiguration) URL(java.net.URL) Test(org.junit.Test)

Example 2 with WebDescriptor

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);
    }
}
Also used : WebAppClassLoader(org.eclipse.jetty.webapp.WebAppClassLoader) Descriptor(org.eclipse.jetty.webapp.Descriptor) FragmentDescriptor(org.eclipse.jetty.webapp.FragmentDescriptor) WebDescriptor(org.eclipse.jetty.webapp.WebDescriptor) Test(org.junit.Test)

Example 3 with WebDescriptor

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();
}
Also used : WebDescriptor(org.eclipse.jetty.webapp.WebDescriptor) HttpURLConnection(java.net.HttpURLConnection) Server(org.eclipse.jetty.server.Server) InputStream(java.io.InputStream) Node(org.eclipse.jetty.xml.XmlParser.Node) Resource(org.eclipse.jetty.util.resource.Resource) XmlConfiguration(org.eclipse.jetty.xml.XmlConfiguration) URL(java.net.URL) Test(org.junit.Test)

Example 4 with WebDescriptor

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();
}
Also used : WebDescriptor(org.eclipse.jetty.webapp.WebDescriptor) HttpURLConnection(java.net.HttpURLConnection) Server(org.eclipse.jetty.server.Server) Node(org.eclipse.jetty.xml.XmlParser.Node) Resource(org.eclipse.jetty.util.resource.Resource) XmlConfiguration(org.eclipse.jetty.xml.XmlConfiguration) URL(java.net.URL) Test(org.junit.Test)

Example 5 with WebDescriptor

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();
}
Also used : InitialContext(javax.naming.InitialContext) WebAppContext(org.eclipse.jetty.webapp.WebAppContext) Context(javax.naming.Context) WebDescriptor(org.eclipse.jetty.webapp.WebDescriptor) WebAppClassLoader(org.eclipse.jetty.webapp.WebAppClassLoader) InitialContext(javax.naming.InitialContext) URL(java.net.URL) WebAppContext(org.eclipse.jetty.webapp.WebAppContext) WebAppClassLoader(org.eclipse.jetty.webapp.WebAppClassLoader) FragmentDescriptor(org.eclipse.jetty.webapp.FragmentDescriptor) Before(org.junit.Before)

Aggregations

WebDescriptor (org.eclipse.jetty.webapp.WebDescriptor)5 URL (java.net.URL)4 Test (org.junit.Test)4 HttpURLConnection (java.net.HttpURLConnection)3 Server (org.eclipse.jetty.server.Server)3 Resource (org.eclipse.jetty.util.resource.Resource)3 XmlConfiguration (org.eclipse.jetty.xml.XmlConfiguration)3 Node (org.eclipse.jetty.xml.XmlParser.Node)3 InputStream (java.io.InputStream)2 FragmentDescriptor (org.eclipse.jetty.webapp.FragmentDescriptor)2 WebAppClassLoader (org.eclipse.jetty.webapp.WebAppClassLoader)2 Context (javax.naming.Context)1 InitialContext (javax.naming.InitialContext)1 Descriptor (org.eclipse.jetty.webapp.Descriptor)1 WebAppContext (org.eclipse.jetty.webapp.WebAppContext)1 Before (org.junit.Before)1