Search in sources :

Example 81 with Resource

use of org.eclipse.jetty.util.resource.Resource in project jetty.project by eclipse.

the class WebXmlConfiguration method preConfigure.

/* ------------------------------------------------------------------------------- */
/**
     * 
     */
@Override
public void preConfigure(WebAppContext context) throws Exception {
    //parse webdefault.xml
    String defaultsDescriptor = context.getDefaultsDescriptor();
    if (defaultsDescriptor != null && defaultsDescriptor.length() > 0) {
        Resource dftResource = Resource.newSystemResource(defaultsDescriptor);
        if (dftResource == null)
            dftResource = context.newResource(defaultsDescriptor);
        context.getMetaData().setDefaults(dftResource);
    }
    //parse, but don't process web.xml
    Resource webxml = findWebXml(context);
    if (webxml != null) {
        context.getMetaData().setWebXml(webxml);
        context.getServletContext().setEffectiveMajorVersion(context.getMetaData().getWebXml().getMajorVersion());
        context.getServletContext().setEffectiveMinorVersion(context.getMetaData().getWebXml().getMinorVersion());
    }
    //parse but don't process override-web.xml
    for (String overrideDescriptor : context.getOverrideDescriptors()) {
        if (overrideDescriptor != null && overrideDescriptor.length() > 0) {
            Resource orideResource = Resource.newSystemResource(overrideDescriptor);
            if (orideResource == null)
                orideResource = context.newResource(overrideDescriptor);
            context.getMetaData().addOverride(orideResource);
        }
    }
}
Also used : Resource(org.eclipse.jetty.util.resource.Resource)

Example 82 with Resource

use of org.eclipse.jetty.util.resource.Resource in project jetty.project by eclipse.

the class WebXmlConfiguration method findWebXml.

/* ------------------------------------------------------------------------------- */
protected Resource findWebXml(WebAppContext context) throws IOException, MalformedURLException {
    String descriptor = context.getDescriptor();
    if (descriptor != null) {
        Resource web = context.newResource(descriptor);
        if (web.exists() && !web.isDirectory())
            return web;
    }
    Resource web_inf = context.getWebInf();
    if (web_inf != null && web_inf.isDirectory()) {
        // do web.xml file
        Resource web = web_inf.addPath("web.xml");
        if (web.exists())
            return web;
        if (LOG.isDebugEnabled())
            LOG.debug("No WEB-INF/web.xml in " + context.getWar() + ". Serving files and default/dynamic servlets only");
    }
    return null;
}
Also used : Resource(org.eclipse.jetty.util.resource.Resource)

Example 83 with Resource

use of org.eclipse.jetty.util.resource.Resource in project jetty.project by eclipse.

the class ClasspathPatternTest method testExcludeLocations.

/**
     * 
     */
@SuppressWarnings("restriction")
@Test
public void testExcludeLocations() throws Exception {
    // jar from JVM classloader
    Resource loc_string = TypeUtil.getLoadedFrom(String.class);
    // System.err.println(loc_string);
    // another jar from JVM classloader
    Resource loc_jsse = TypeUtil.getLoadedFrom(Sun.class);
    // System.err.println(loc_jsse);
    // a jar from maven repo jar
    Resource loc_junit = TypeUtil.getLoadedFrom(Test.class);
    // System.err.println(loc_junit);
    // a jar from another maven repo jar
    Resource loc_tool = TypeUtil.getLoadedFrom(JDK.class);
    // System.err.println(loc_tool);
    // class file 
    Resource loc_test = TypeUtil.getLoadedFrom(ClasspathPatternTest.class);
    // System.err.println(loc_test);
    ClasspathPattern pattern = new ClasspathPattern();
    // include everything
    pattern.include(".");
    assertThat(pattern.match(String.class), is(true));
    assertThat(pattern.match(Sun.class), is(true));
    assertThat(pattern.match(Test.class), is(true));
    assertThat(pattern.match(JDK.class), is(true));
    assertThat(pattern.match(ClasspathPatternTest.class), is(true));
    // Add directory for both JVM classes
    pattern.exclude(loc_string.getFile().getParentFile().toURI().toString());
    // Add jar for individual class and classes directory
    pattern.exclude(loc_junit.toString(), loc_test.toString());
    assertThat(pattern.match(String.class), is(false));
    assertThat(pattern.match(Sun.class), is(false));
    assertThat(pattern.match(Test.class), is(false));
    assertThat(pattern.match(JDK.class), is(true));
    assertThat(pattern.match(ClasspathPatternTest.class), is(false));
}
Also used : JDK(org.eclipse.jetty.toolchain.test.JDK) Test(org.junit.Test) Resource(org.eclipse.jetty.util.resource.Resource) Sun(sun.security.provider.Sun) Test(org.junit.Test)

Example 84 with Resource

use of org.eclipse.jetty.util.resource.Resource in project jetty.project by eclipse.

the class OrderingTest method testAbsoluteOrdering1.

@Test
public void testAbsoluteOrdering1() throws Exception {
    //
    // A,B,C,others
    //
    List<Resource> resources = new ArrayList<Resource>();
    MetaData metaData = new MetaData();
    metaData._ordering = new AbsoluteOrdering(metaData);
    ((AbsoluteOrdering) metaData._ordering).add("A");
    ((AbsoluteOrdering) metaData._ordering).add("B");
    ((AbsoluteOrdering) metaData._ordering).add("C");
    ((AbsoluteOrdering) metaData._ordering).addOthers();
    TestResource jar1 = new TestResource("A");
    resources.add(jar1);
    TestResource r1 = new TestResource("A/web-fragment.xml");
    FragmentDescriptor f1 = new FragmentDescriptor(r1);
    f1._name = "A";
    metaData._webFragmentNameMap.put(f1._name, f1);
    metaData._webFragmentResourceMap.put(jar1, f1);
    TestResource jar2 = new TestResource("B");
    resources.add(jar2);
    TestResource r2 = new TestResource("B/web-fragment.xml");
    FragmentDescriptor f2 = new FragmentDescriptor(r2);
    f2._name = "B";
    metaData._webFragmentNameMap.put(f2._name, f2);
    metaData._webFragmentResourceMap.put(jar2, f2);
    TestResource jar3 = new TestResource("C");
    resources.add(jar3);
    TestResource r3 = new TestResource("C/web-fragment.xml");
    FragmentDescriptor f3 = new FragmentDescriptor(r3);
    f3._name = "C";
    metaData._webFragmentNameMap.put(f3._name, f3);
    metaData._webFragmentResourceMap.put(jar3, f3);
    TestResource jar4 = new TestResource("D");
    resources.add(jar4);
    TestResource r4 = new TestResource("D/web-fragment.xml");
    FragmentDescriptor f4 = new FragmentDescriptor((Resource) null);
    f4._name = "D";
    metaData._webFragmentNameMap.put(f4._name, f4);
    metaData._webFragmentResourceMap.put(jar4, f4);
    TestResource jar5 = new TestResource("E");
    resources.add(jar5);
    TestResource r5 = new TestResource("E/web-fragment.xml");
    FragmentDescriptor f5 = new FragmentDescriptor((Resource) null);
    f5._name = "E";
    metaData._webFragmentNameMap.put(f5._name, f5);
    metaData._webFragmentResourceMap.put(jar5, f5);
    TestResource jar6 = new TestResource("plain");
    resources.add(jar6);
    TestResource r6 = new TestResource("plain/web-fragment.xml");
    FragmentDescriptor f6 = new FragmentDescriptor((Resource) null);
    f6._name = FragmentDescriptor.NAMELESS + "1";
    metaData._webFragmentNameMap.put(f6._name, f6);
    metaData._webFragmentResourceMap.put(jar6, f6);
    List<Resource> list = metaData._ordering.order(resources);
    String[] outcomes = { "ABCDEplain" };
    String result = "";
    for (Resource r : list) result += ((TestResource) r)._name;
    if (!checkResult(result, outcomes))
        fail("No outcome matched " + result);
}
Also used : ArrayList(java.util.ArrayList) Resource(org.eclipse.jetty.util.resource.Resource) Test(org.junit.Test)

Example 85 with Resource

use of org.eclipse.jetty.util.resource.Resource in project jetty.project by eclipse.

the class SslContextFactoryTest method testResourceTsResourceKsWrongPW.

@Test
public void testResourceTsResourceKsWrongPW() throws Exception {
    Resource keystoreResource = Resource.newSystemResource("keystore");
    Resource truststoreResource = Resource.newSystemResource("keystore");
    cf.setKeyStoreResource(keystoreResource);
    cf.setTrustStoreResource(truststoreResource);
    cf.setKeyStorePassword("storepwd");
    cf.setKeyManagerPassword("wrong_keypwd");
    cf.setTrustStorePassword("storepwd");
    try (StacklessLogging stackless = new StacklessLogging(AbstractLifeCycle.class)) {
        cf.start();
        Assert.fail();
    } catch (java.security.UnrecoverableKeyException e) {
        Assert.assertThat(e.toString(), Matchers.containsString("UnrecoverableKeyException"));
    }
}
Also used : Resource(org.eclipse.jetty.util.resource.Resource) StacklessLogging(org.eclipse.jetty.util.log.StacklessLogging) Test(org.junit.Test)

Aggregations

Resource (org.eclipse.jetty.util.resource.Resource)196 Test (org.junit.Test)79 File (java.io.File)46 URL (java.net.URL)39 ArrayList (java.util.ArrayList)38 Matchers.containsString (org.hamcrest.Matchers.containsString)31 IOException (java.io.IOException)28 ResourceCollection (org.eclipse.jetty.util.resource.ResourceCollection)18 JarResource (org.eclipse.jetty.util.resource.JarResource)16 XmlConfiguration (org.eclipse.jetty.xml.XmlConfiguration)16 Server (org.eclipse.jetty.server.Server)13 HashSet (java.util.HashSet)12 InputStream (java.io.InputStream)9 HashMap (java.util.HashMap)9 URI (java.net.URI)8 MalformedURLException (java.net.MalformedURLException)7 StringTokenizer (java.util.StringTokenizer)7 URISyntaxException (java.net.URISyntaxException)6 Properties (java.util.Properties)6 Set (java.util.Set)6