Search in sources :

Example 46 with Resource

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

the class QuickStartWebApp method doStart.

@Override
protected void doStart() throws Exception {
    // unpack and Adjust paths.
    Resource war = null;
    Resource dir = null;
    Resource base = getBaseResource();
    if (base == null)
        base = Resource.newResource(getWar());
    if (base.isDirectory())
        dir = base;
    else if (base.toString().toLowerCase(Locale.ENGLISH).endsWith(".war")) {
        war = base;
        String w = war.toString();
        dir = Resource.newResource(w.substring(0, w.length() - 4));
        if (!dir.exists()) {
            LOG.info("Quickstart Extract " + war + " to " + dir);
            dir.getFile().mkdirs();
            JarResource.newJarResource(war).copyTo(dir.getFile());
        }
        setWar(null);
        setBaseResource(dir);
    } else
        throw new IllegalArgumentException();
    Resource qswebxml = dir.addPath("/WEB-INF/quickstart-web.xml");
    if (isPreconfigure()) {
        _preconfigProcessor = new PreconfigureDescriptorProcessor();
        getMetaData().addDescriptorProcessor(_preconfigProcessor);
        _startWebapp = false;
    } else if (qswebxml.exists()) {
        setConfigurationClasses(__configurationClasses);
        _startWebapp = true;
    } else if (_autoPreconfigure) {
        LOG.info("Quickstart preconfigure: {}(war={},dir={})", this, war, dir);
        _preconfigProcessor = new PreconfigureDescriptorProcessor();
        getMetaData().addDescriptorProcessor(_preconfigProcessor);
        setPreconfigure(true);
        _startWebapp = true;
    } else
        _startWebapp = true;
    super.doStart();
}
Also used : JarResource(org.eclipse.jetty.util.resource.JarResource) Resource(org.eclipse.jetty.util.resource.Resource)

Example 47 with Resource

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

the class JDBCLoginService method doStart.

/* ------------------------------------------------------------ */
@Override
protected void doStart() throws Exception {
    Properties properties = new Properties();
    Resource resource = Resource.newResource(_config);
    try (InputStream in = resource.getInputStream()) {
        properties.load(in);
    }
    _jdbcDriver = properties.getProperty("jdbcdriver");
    _url = properties.getProperty("url");
    _userName = properties.getProperty("username");
    _password = properties.getProperty("password");
    String _userTable = properties.getProperty("usertable");
    _userTableKey = properties.getProperty("usertablekey");
    String _userTableUserField = properties.getProperty("usertableuserfield");
    _userTablePasswordField = properties.getProperty("usertablepasswordfield");
    String _roleTable = properties.getProperty("roletable");
    String _roleTableKey = properties.getProperty("roletablekey");
    _roleTableRoleField = properties.getProperty("roletablerolefield");
    String _userRoleTable = properties.getProperty("userroletable");
    String _userRoleTableUserKey = properties.getProperty("userroletableuserkey");
    String _userRoleTableRoleKey = properties.getProperty("userroletablerolekey");
    if (_jdbcDriver == null || _jdbcDriver.equals("") || _url == null || _url.equals("") || _userName == null || _userName.equals("") || _password == null) {
        LOG.warn("UserRealm " + getName() + " has not been properly configured");
    }
    _userSql = "select " + _userTableKey + "," + _userTablePasswordField + " from " + _userTable + " where " + _userTableUserField + " = ?";
    _roleSql = "select r." + _roleTableRoleField + " from " + _roleTable + " r, " + _userRoleTable + " u where u." + _userRoleTableUserKey + " = ?" + " and r." + _roleTableKey + " = u." + _userRoleTableRoleKey;
    Loader.loadClass(_jdbcDriver).newInstance();
    super.doStart();
}
Also used : InputStream(java.io.InputStream) Resource(org.eclipse.jetty.util.resource.Resource) Properties(java.util.Properties)

Example 48 with Resource

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

the class SpnegoLoginService method doStart.

@Override
protected void doStart() throws Exception {
    Properties properties = new Properties();
    Resource resource = Resource.newResource(_config);
    properties.load(resource.getInputStream());
    _targetName = properties.getProperty("targetName");
    LOG.debug("Target Name {}", _targetName);
    super.doStart();
}
Also used : Resource(org.eclipse.jetty.util.resource.Resource) Properties(java.util.Properties)

Example 49 with Resource

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

the class ContextHandlerGetResourceTest method testSymlinkKnown.

@Test
public void testSymlinkKnown() throws Exception {
    Assume.assumeTrue(OS.IS_UNIX);
    try {
        allowSymlinks.set(true);
        final String path = "/other/other.txt";
        Resource resource = context.getResource(path);
        assertNotNull(resource);
        assertEquals("other.txt", resource.getFile().getName());
        assertEquals(docroot, resource.getFile().getParentFile().getParentFile());
        assertTrue(resource.exists());
        URL url = context.getServletContext().getResource(path);
        assertEquals(docroot, new File(url.toURI()).getParentFile().getParentFile());
    } finally {
        allowSymlinks.set(false);
    }
}
Also used : Resource(org.eclipse.jetty.util.resource.Resource) File(java.io.File) URL(java.net.URL) Test(org.junit.Test)

Example 50 with Resource

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

the class ContextHandlerGetResourceTest method testAliasedFileAllowed.

@Test
public void testAliasedFileAllowed() throws Exception {
    Assume.assumeTrue("OS Supports 8.3 Aliased / Alternate References", OS_ALIAS_SUPPORTED);
    try {
        allowAliases.set(true);
        final String path = "/subdir/TEXTFI~1.TXT";
        Resource resource = context.getResource(path);
        assertNotNull(resource);
        assertEquals(context.getResource("/subdir/TextFile.Long.txt").getURI(), resource.getAlias());
        URL url = context.getServletContext().getResource(path);
        assertNotNull(url);
        assertEquals(docroot, new File(url.toURI()).getParentFile().getParentFile());
    } finally {
        allowAliases.set(false);
    }
}
Also used : Resource(org.eclipse.jetty.util.resource.Resource) File(java.io.File) URL(java.net.URL) 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