View | Details | Raw Unified | Return to bug 56777
Collapse All | Expand All

(-)java/org/apache/catalina/realm/MemoryRealm.java (-23 / +36 lines)
Lines 19-35 Link Here
19
package org.apache.catalina.realm;
19
package org.apache.catalina.realm;
20
20
21
21
22
import java.io.File;
22
import java.io.IOException;
23
import java.io.InputStream;
23
import java.security.Principal;
24
import java.security.Principal;
24
import java.util.ArrayList;
25
import java.util.ArrayList;
25
import java.util.HashMap;
26
import java.util.HashMap;
26
import java.util.Map;
27
import java.util.Map;
27
28
28
import org.apache.catalina.Globals;
29
import org.apache.catalina.LifecycleException;
29
import org.apache.catalina.LifecycleException;
30
import org.apache.juli.logging.Log;
30
import org.apache.juli.logging.Log;
31
import org.apache.juli.logging.LogFactory;
31
import org.apache.juli.logging.LogFactory;
32
import org.apache.tomcat.util.digester.Digester;
32
import org.apache.tomcat.util.digester.Digester;
33
import org.apache.tomcat.util.file.ConfigFileLoader;
33
34
34
35
35
/**
36
/**
Lines 282-311 public class MemoryRealm extends RealmBase { Link Here
282
    @Override
283
    @Override
283
    protected void startInternal() throws LifecycleException {
284
    protected void startInternal() throws LifecycleException {
284
285
285
        // Validate the existence of our database file
286
        String pathName = getPathname();
286
        File file = new File(pathname);
287
        InputStream is = null;
287
        if (!file.isAbsolute())
288
288
            file = new File(System.getProperty(Globals.CATALINA_BASE_PROP), pathname);
289
        if (!file.exists() || !file.canRead())
290
            throw new LifecycleException
291
                (sm.getString("memoryRealm.loadExist",
292
                              file.getAbsolutePath()));
293
294
        // Load the contents of the database file
295
        if (log.isDebugEnabled())
296
            log.debug(sm.getString("memoryRealm.loadPath",
297
                             file.getAbsolutePath()));
298
        Digester digester = getDigester();
299
        try {
289
        try {
300
            synchronized (digester) {
290
            is = ConfigFileLoader.getInputStream(pathName);
301
                digester.push(this);
291
302
                digester.parse(file);
292
            // Load the contents of the database file
293
            if (log.isDebugEnabled()) {
294
                log.debug(sm.getString("memoryRealm.loadPath", pathName));
303
            }
295
            }
304
        } catch (Exception e) {
296
305
            throw new LifecycleException
297
            Digester digester = getDigester();
306
                (sm.getString("memoryRealm.readXml"), e);
298
            try {
299
                synchronized (digester) {
300
                    digester.push(this);
301
                    digester.parse(is);
302
                }
303
            } catch (Exception e) {
304
                throw new LifecycleException
305
                        (sm.getString("memoryRealm.readXml"), e);
306
            } finally {
307
                digester.reset();
308
            }
309
310
        } catch (IOException ioe) {
311
            throw new LifecycleException(sm.getString("memoryRealm.loadExist",
312
                            pathName), ioe);
313
307
        } finally {
314
        } finally {
308
            digester.reset();
315
            if (is != null) {
316
                try {
317
                    is.close();
318
                } catch (IOException e) {
319
                    // ignore
320
                }
321
            }
309
        }
322
        }
310
323
311
        super.startInternal();
324
        super.startInternal();
(-)java/org/apache/catalina/users/MemoryUserDatabase.java (-38 / +31 lines)
Lines 17-25 Link Here
17
package org.apache.catalina.users;
17
package org.apache.catalina.users;
18
18
19
import java.io.File;
19
import java.io.File;
20
import java.io.FileInputStream;
21
import java.io.FileOutputStream;
20
import java.io.FileOutputStream;
22
import java.io.IOException;
21
import java.io.IOException;
22
import java.io.InputStream;
23
import java.io.OutputStreamWriter;
23
import java.io.OutputStreamWriter;
24
import java.io.PrintWriter;
24
import java.io.PrintWriter;
25
import java.util.HashMap;
25
import java.util.HashMap;
Lines 34-39 import org.apache.juli.logging.Log; Link Here
34
import org.apache.juli.logging.LogFactory;
34
import org.apache.juli.logging.LogFactory;
35
import org.apache.tomcat.util.digester.AbstractObjectCreationFactory;
35
import org.apache.tomcat.util.digester.AbstractObjectCreationFactory;
36
import org.apache.tomcat.util.digester.Digester;
36
import org.apache.tomcat.util.digester.Digester;
37
import org.apache.tomcat.util.file.ConfigFileLoader;
37
import org.apache.tomcat.util.res.StringManager;
38
import org.apache.tomcat.util.res.StringManager;
38
import org.xml.sax.Attributes;
39
import org.xml.sax.Attributes;
39
40
Lines 394-445 public class MemoryUserDatabase implements UserDatabase { Link Here
394
                groups.clear();
395
                groups.clear();
395
                roles.clear();
396
                roles.clear();
396
397
397
                // Construct a reader for the XML input file (if it exists)
398
                String pathName = getPathname();
398
                File file = new File(pathname);
399
                InputStream is = null;
399
                if (!file.isAbsolute()) {
400
                    file = new File(System.getProperty(Globals.CATALINA_BASE_PROP),
401
                                    pathname);
402
                }
403
                if (!file.exists()) {
404
                    log.error(sm.getString("memoryUserDatabase.fileNotFound",
405
                            file.getAbsolutePath()));
406
                    return;
407
                }
408
400
409
                // Construct a digester to read the XML input file
410
                Digester digester = new Digester();
411
                try {
412
                    digester.setFeature(
413
                            "http://apache.org/xml/features/allow-java-encodings",
414
                            true);
415
                } catch (Exception e) {
416
                    log.warn(sm.getString("memoryUserDatabase.xmlFeatureEncoding"), e);
417
                }
418
                digester.addFactoryCreate
419
                    ("tomcat-users/group",
420
                     new MemoryGroupCreationFactory(this), true);
421
                digester.addFactoryCreate
422
                    ("tomcat-users/role",
423
                     new MemoryRoleCreationFactory(this), true);
424
                digester.addFactoryCreate
425
                    ("tomcat-users/user",
426
                     new MemoryUserCreationFactory(this), true);
427
428
                // Parse the XML input file to load this database
429
                FileInputStream fis = null;
430
                try {
401
                try {
431
                    fis =  new FileInputStream(file);
402
                    is = ConfigFileLoader.getInputStream(pathName);
432
                    digester.parse(fis);
403
404
                    // Construct a digester to read the XML input file
405
                    Digester digester = new Digester();
406
                    try {
407
                        digester.setFeature(
408
                                "http://apache.org/xml/features/allow-java-encodings",
409
                                true);
410
                    } catch (Exception e) {
411
                        log.warn(sm.getString("memoryUserDatabase.xmlFeatureEncoding"), e);
412
                    }
413
                    digester.addFactoryCreate
414
                            ("tomcat-users/group",
415
                                    new MemoryGroupCreationFactory(this), true);
416
                    digester.addFactoryCreate
417
                            ("tomcat-users/role",
418
                                    new MemoryRoleCreationFactory(this), true);
419
                    digester.addFactoryCreate
420
                            ("tomcat-users/user",
421
                                    new MemoryUserCreationFactory(this), true);
422
423
                    // Parse the XML input to load this database
424
                    digester.parse(is);
425
                } catch (IOException ioe) {
426
                    log.error(sm.getString("memoryUserDatabase.fileNotFound", pathName));
433
                } finally {
427
                } finally {
434
                    if (fis != null) {
428
                    if (is != null) {
435
                        try {
429
                        try {
436
                            fis.close();
430
                            is.close();
437
                        } catch (IOException ioe) {
431
                        } catch (IOException ioe) {
438
                            // Ignore
432
                            // Ignore
439
                        }
433
                        }
440
                    }
434
                    }
441
                }
435
                }
442
443
            }
436
            }
444
        }
437
        }
445
438
(-)java/org/apache/naming/resources/ClasspathURLStreamHandler.java (+50 lines)
Line 0 Link Here
1
/*
2
 * Licensed to the Apache Software Foundation (ASF) under one or more
3
 * contributor license agreements.  See the NOTICE file distributed with
4
 * this work for additional information regarding copyright ownership.
5
 * The ASF licenses this file to You under the Apache License, Version 2.0
6
 * (the "License"); you may not use this file except in compliance with
7
 * the License.  You may obtain a copy of the License at
8
 *
9
 *      http://www.apache.org/licenses/LICENSE-2.0
10
 *
11
 * Unless required by applicable law or agreed to in writing, software
12
 * distributed under the License is distributed on an "AS IS" BASIS,
13
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
 * See the License for the specific language governing permissions and
15
 * limitations under the License.
16
 */
17
package org.apache.naming.resources;
18
19
import java.io.FileNotFoundException;
20
import java.io.IOException;
21
import java.net.URL;
22
import java.net.URLConnection;
23
import java.net.URLStreamHandler;
24
25
import org.apache.tomcat.util.res.StringManager;
26
27
public class ClasspathURLStreamHandler extends URLStreamHandler {
28
29
    private static final StringManager sm =
30
            StringManager.getManager(Constants.Package);
31
32
33
    @Override
34
    protected URLConnection openConnection(URL u) throws IOException {
35
        String path = u.getPath();
36
37
        // Thread context class loader first
38
        URL classpathUrl = Thread.currentThread().getContextClassLoader().getResource(path);
39
        if (classpathUrl == null) {
40
            // This class's class loader if no joy with the tccl
41
            classpathUrl = ClasspathURLStreamHandler.class.getResource(path);
42
        }
43
44
        if (classpathUrl == null) {
45
            throw new FileNotFoundException(sm.getString("classpathUrlStreamHandler.notFound", u));
46
        }
47
48
        return classpathUrl.openConnection();
49
    }
50
}
(-)java/org/apache/naming/resources/DirContextURLStreamHandlerFactory.java (-2 / +5 lines)
Lines 23-30 import java.util.List; Link Here
23
import java.util.concurrent.CopyOnWriteArrayList;
23
import java.util.concurrent.CopyOnWriteArrayList;
24
24
25
/**
25
/**
26
 * Factory for Stream handlers to a JNDI directory context that also supports
26
 * Factory for Stream handlers to a JNDI directory context,
27
 * users specifying additional stream handler.
27
 * or for Stream handlers to a classpath url,
28
 * which also supports users specifying additional stream handler.
28
 * 
29
 * 
29
 * @author <a href="mailto:remm@apache.org">Remy Maucherat</a>
30
 * @author <a href="mailto:remm@apache.org">Remy Maucherat</a>
30
 */
31
 */
Lines 64-69 public class DirContextURLStreamHandlerFactory Link Here
64
    public URLStreamHandler createURLStreamHandler(String protocol) {
65
    public URLStreamHandler createURLStreamHandler(String protocol) {
65
        if (protocol.equals("jndi")) {
66
        if (protocol.equals("jndi")) {
66
            return new DirContextURLStreamHandler();
67
            return new DirContextURLStreamHandler();
68
        } else if (protocol.equals("classpath")) {
69
            return new ClasspathURLStreamHandler();
67
        } else {
70
        } else {
68
            for (URLStreamHandlerFactory factory : userFactories) {
71
            for (URLStreamHandlerFactory factory : userFactories) {
69
                URLStreamHandler handler =
72
                URLStreamHandler handler =
(-)java/org/apache/naming/resources/LocalStrings.properties (+1 lines)
Lines 43-45 standardResources.exists=File base {0} does not exist Link Here
43
standardResources.notStarted=Resources has not yet been started
43
standardResources.notStarted=Resources has not yet been started
44
standardResources.null=Document base cannot be null
44
standardResources.null=Document base cannot be null
45
standardResources.slash=Document base {0} must not end with a slash
45
standardResources.slash=Document base {0} must not end with a slash
46
classpathUrlStreamHandler.notFound=Unable to load the resource [{0}] using the thread context class loader or the current class's class loader
(-)java/org/apache/tomcat/util/file/ConfigFileLoader.java (+85 lines)
Line 0 Link Here
1
/*
2
 *  Licensed to the Apache Software Foundation (ASF) under one or more
3
 *  contributor license agreements.  See the NOTICE file distributed with
4
 *  this work for additional information regarding copyright ownership.
5
 *  The ASF licenses this file to You under the Apache License, Version 2.0
6
 *  (the "License"); you may not use this file except in compliance with
7
 *  the License.  You may obtain a copy of the License at
8
 *
9
 *      http://www.apache.org/licenses/LICENSE-2.0
10
 *
11
 *  Unless required by applicable law or agreed to in writing, software
12
 *  distributed under the License is distributed on an "AS IS" BASIS,
13
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
 *  See the License for the specific language governing permissions and
15
 *  limitations under the License.
16
 *
17
 */
18
package org.apache.tomcat.util.file;
19
20
import java.io.File;
21
import java.io.FileInputStream;
22
import java.io.IOException;
23
import java.io.InputStream;
24
import java.net.URI;
25
26
/**
27
 * This class is used to obtain {@link InputStream}s for configuration files
28
 * from a given location String. This allows greater flexibility than these
29
 * files having to be loaded directly from a file system.
30
 */
31
public class ConfigFileLoader {
32
33
    private static final File CATALINA_BASE_FILE;
34
    private static final URI CATALINA_BASE_URI;
35
36
    static {
37
        CATALINA_BASE_FILE = new File(System.getProperty("catalina.base"));
38
        CATALINA_BASE_URI = CATALINA_BASE_FILE.toURI();
39
    }
40
41
    private ConfigFileLoader() {
42
        // Utility class. Hide the default constructor.
43
    }
44
45
46
    /**
47
     * Load the resource from the specified location.
48
     *
49
     * @param location The location for the resource of interest. The location
50
     *                 may be a URL or a file path. Relative paths will be
51
     *                 resolved against CATALINA_BASE.
52
     *
53
     * @return The InputStream for the given resource. The caller is responsible
54
     *         for closing this stream when it is no longer used.
55
     *
56
     * @throws IOException If an InputStream cannot be created using the
57
     *                     provided location
58
     */
59
    public static InputStream getInputStream(String location) throws IOException {
60
        // Absolute URIs will be left alone
61
        // Relative files will be resolved relative to catalina base
62
        // Absolute files will be converted to URIs
63
64
        // Location was originally always a file before URI support was added so
65
        // try file first.
66
67
        // First guess, an absolute file path
68
        File file = new File(location);
69
70
        if (!file.isAbsolute()) {
71
            // Second guess, a file path relative to CATALINA_BASE
72
            file = new File(CATALINA_BASE_FILE, location);
73
        }
74
75
        if (file.isFile()) {
76
            return new FileInputStream(file);
77
        }
78
79
        // Third and final guess, a URI
80
        URI uri = CATALINA_BASE_URI.resolve(location);
81
        return uri.toURL().openStream();
82
    }
83
84
85
}
(-)java/org/apache/tomcat/util/net/AbstractEndpoint.java (-24 / +2 lines)
Lines 16-22 Link Here
16
 */
16
 */
17
package org.apache.tomcat.util.net;
17
package org.apache.tomcat.util.net;
18
18
19
import java.io.File;
20
import java.io.OutputStreamWriter;
19
import java.io.OutputStreamWriter;
21
import java.net.InetAddress;
20
import java.net.InetAddress;
22
import java.net.InetSocketAddress;
21
import java.net.InetSocketAddress;
Lines 728-752 public abstract class AbstractEndpoint<S> { Link Here
728
        }
727
        }
729
    }
728
    }
730
729
731
732
    public String adjustRelativePath(String path, String relativeTo) {
733
        // Empty or null path can't point to anything useful. The assumption is
734
        // that the value is deliberately empty / null so leave it that way.
735
        if (path == null || path.length() == 0) {
736
            return path;
737
        }
738
        String newPath = path;
739
        File f = new File(newPath);
740
        if ( !f.isAbsolute()) {
741
            newPath = relativeTo + File.separator + newPath;
742
            f = new File(newPath);
743
        }
744
        if (!f.exists()) {
745
            getLog().warn("configured file:["+newPath+"] does not exist.");
746
        }
747
        return newPath;
748
    }
749
750
    protected abstract Log getLog();
730
    protected abstract Log getLog();
751
    // Flags to indicate optional feature support
731
    // Flags to indicate optional feature support
752
    // Some of these are always hard-coded, some are hard-coded to false (i.e.
732
    // Some of these are always hard-coded, some are hard-coded to false (i.e.
Lines 833-840 public abstract class AbstractEndpoint<S> { Link Here
833
    private String keystoreFile = System.getProperty("user.home")+"/.keystore";
813
    private String keystoreFile = System.getProperty("user.home")+"/.keystore";
834
    public String getKeystoreFile() { return keystoreFile;}
814
    public String getKeystoreFile() { return keystoreFile;}
835
    public void setKeystoreFile(String s ) {
815
    public void setKeystoreFile(String s ) {
836
        keystoreFile = adjustRelativePath(s,
816
        keystoreFile = s;
837
                System.getProperty(Constants.CATALINA_BASE_PROP));
838
    }
817
    }
839
818
840
    private String keystorePass = null;
819
    private String keystorePass = null;
Lines 874-881 public abstract class AbstractEndpoint<S> { Link Here
874
    private String truststoreFile = System.getProperty("javax.net.ssl.trustStore");
853
    private String truststoreFile = System.getProperty("javax.net.ssl.trustStore");
875
    public String getTruststoreFile() {return truststoreFile;}
854
    public String getTruststoreFile() {return truststoreFile;}
876
    public void setTruststoreFile(String s) {
855
    public void setTruststoreFile(String s) {
877
        truststoreFile = adjustRelativePath(s,
856
        truststoreFile = s;
878
                System.getProperty(Constants.CATALINA_BASE_PROP));
879
    }
857
    }
880
858
881
    private String truststorePass =
859
    private String truststorePass =
(-)java/org/apache/tomcat/util/net/jsse/JSSESocketFactory.java (-14 / +3 lines)
Lines 17-24 Link Here
17
17
18
package org.apache.tomcat.util.net.jsse;
18
package org.apache.tomcat.util.net.jsse;
19
19
20
import java.io.File;
21
import java.io.FileInputStream;
22
import java.io.FileNotFoundException;
20
import java.io.FileNotFoundException;
23
import java.io.IOException;
21
import java.io.IOException;
24
import java.io.InputStream;
22
import java.io.InputStream;
Lines 63-68 import javax.net.ssl.X509KeyManager; Link Here
63
61
64
import org.apache.tomcat.util.compat.JreCompat;
62
import org.apache.tomcat.util.compat.JreCompat;
65
import org.apache.tomcat.util.compat.JreVendor;
63
import org.apache.tomcat.util.compat.JreVendor;
64
import org.apache.tomcat.util.file.ConfigFileLoader;
66
import org.apache.tomcat.util.net.AbstractEndpoint;
65
import org.apache.tomcat.util.net.AbstractEndpoint;
67
import org.apache.tomcat.util.net.Constants;
66
import org.apache.tomcat.util.net.Constants;
68
import org.apache.tomcat.util.net.SSLUtil;
67
import org.apache.tomcat.util.net.SSLUtil;
Lines 431-442 public class JSSESocketFactory implements ServerSocketFactory, SSLUtil { Link Here
431
            }
430
            }
432
            if(!("PKCS11".equalsIgnoreCase(type) ||
431
            if(!("PKCS11".equalsIgnoreCase(type) ||
433
                    "".equalsIgnoreCase(path))) {
432
                    "".equalsIgnoreCase(path))) {
434
                File keyStoreFile = new File(path);
433
                istream = ConfigFileLoader.getInputStream(path);
435
                if (!keyStoreFile.isAbsolute()) {
436
                    keyStoreFile = new File(System.getProperty(
437
                            Constants.CATALINA_BASE_PROP), path);
438
                }
439
                istream = new FileInputStream(keyStoreFile);
440
            }
434
            }
441
435
442
            char[] storePass = null;
436
            char[] storePass = null;
Lines 718-733 public class JSSESocketFactory implements ServerSocketFactory, SSLUtil { Link Here
718
    protected Collection<? extends CRL> getCRLs(String crlf)
712
    protected Collection<? extends CRL> getCRLs(String crlf)
719
        throws IOException, CRLException, CertificateException {
713
        throws IOException, CRLException, CertificateException {
720
714
721
        File crlFile = new File(crlf);
722
        if( !crlFile.isAbsolute() ) {
723
            crlFile = new File(
724
                    System.getProperty(Constants.CATALINA_BASE_PROP), crlf);
725
        }
726
        Collection<? extends CRL> crls = null;
715
        Collection<? extends CRL> crls = null;
727
        InputStream is = null;
716
        InputStream is = null;
728
        try {
717
        try {
729
            CertificateFactory cf = CertificateFactory.getInstance("X.509");
718
            CertificateFactory cf = CertificateFactory.getInstance("X.509");
730
            is = new FileInputStream(crlFile);
719
            is = ConfigFileLoader.getInputStream(crlf);
731
            crls = cf.generateCRLs(is);
720
            crls = cf.generateCRLs(is);
732
        } catch(IOException iex) {
721
        } catch(IOException iex) {
733
            throw iex;
722
            throw iex;
(-)test/org/apache/naming/resources/TestClasspathUrlStreamHandler.java (+44 lines)
Line 0 Link Here
1
/*
2
 * Licensed to the Apache Software Foundation (ASF) under one or more
3
 * contributor license agreements.  See the NOTICE file distributed with
4
 * this work for additional information regarding copyright ownership.
5
 * The ASF licenses this file to You under the Apache License, Version 2.0
6
 * (the "License"); you may not use this file except in compliance with
7
 * the License.  You may obtain a copy of the License at
8
 *
9
 *      http://www.apache.org/licenses/LICENSE-2.0
10
 *
11
 * Unless required by applicable law or agreed to in writing, software
12
 * distributed under the License is distributed on an "AS IS" BASIS,
13
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
 * See the License for the specific language governing permissions and
15
 * limitations under the License.
16
 */
17
package org.apache.naming.resources;
18
19
import java.io.IOException;
20
import java.io.InputStream;
21
import java.net.URL;
22
import java.util.Properties;
23
24
import org.junit.Assert;
25
import org.junit.BeforeClass;
26
import org.junit.Test;
27
28
public class TestClasspathUrlStreamHandler {
29
30
    @BeforeClass
31
    public static void setup() {
32
        URL.setURLStreamHandlerFactory(DirContextURLStreamHandlerFactory.getInstance());
33
    }
34
35
    @Test
36
    public void testClasspathURL01() throws IOException {
37
        URL u = new URL("classpath:/org/apache/naming/resources/LocalStrings.properties");
38
        InputStream is = u.openStream();
39
        Properties p = new Properties();
40
        p.load(is);
41
        String msg = (String) p.get("resources.null");
42
        Assert.assertEquals("Document base cannot be null",  msg);
43
    }
44
}
(-)test/org/apache/tomcat/util/file/TestConfigFileLoader.java (+84 lines)
Line 0 Link Here
1
/*
2
 *  Licensed to the Apache Software Foundation (ASF) under one or more
3
 *  contributor license agreements.  See the NOTICE file distributed with
4
 *  this work for additional information regarding copyright ownership.
5
 *  The ASF licenses this file to You under the Apache License, Version 2.0
6
 *  (the "License"); you may not use this file except in compliance with
7
 *  the License.  You may obtain a copy of the License at
8
 *
9
 *      http://www.apache.org/licenses/LICENSE-2.0
10
 *
11
 *  Unless required by applicable law or agreed to in writing, software
12
 *  distributed under the License is distributed on an "AS IS" BASIS,
13
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
 *  See the License for the specific language governing permissions and
15
 *  limitations under the License.
16
 *
17
 */
18
package org.apache.tomcat.util.file;
19
20
import java.io.File;
21
import java.io.FileNotFoundException;
22
import java.io.IOException;
23
import java.io.InputStream;
24
import java.net.URL;
25
26
import org.apache.naming.resources.DirContextURLStreamHandlerFactory;
27
import org.apache.tomcat.util.http.fileupload.FileUtils;
28
import org.junit.Assert;
29
import org.junit.BeforeClass;
30
import org.junit.Test;
31
32
public class TestConfigFileLoader {
33
34
    @BeforeClass
35
    public static void setup() {
36
        URL.setURLStreamHandlerFactory(
37
                DirContextURLStreamHandlerFactory.getInstance());
38
        File buildDir = new File(
39
                System.getProperty("tomcat.test.tomcatbuild", "output/build"));
40
        System.setProperty("catalina.base", buildDir.getAbsolutePath());
41
    }
42
43
    @Test
44
    public void test01() throws IOException {
45
        doTest("classpath:org/apache/catalina/mbeans-descriptors.xml");
46
    }
47
48
    @Test(expected=FileNotFoundException.class)
49
    public void test02() throws IOException {
50
        doTest("classpath:org/apache/catalina/foo");
51
    }
52
53
    @Test
54
    public void test03() throws IOException {
55
        doTest("conf/server.xml");
56
    }
57
58
    @Test(expected=FileNotFoundException.class)
59
    public void test04() throws IOException {
60
        doTest("conf/unknown");
61
    }
62
63
    @Test
64
    public void testAbsolutePath() throws IOException {
65
        File test = new File(System.getProperty("java.io.tmpdir"), "testAbsolutePath");
66
        if (test.exists()) {
67
            FileUtils.forceDelete(test);
68
        }
69
        test.createNewFile();
70
        doTest(test.getAbsolutePath());
71
    }
72
73
    private void doTest(String path) throws IOException {
74
        InputStream is = null;
75
        try {
76
            is = ConfigFileLoader.getInputStream(path);
77
            Assert.assertNotNull(is);
78
        } finally {
79
            if (is != null) {
80
                is.close();
81
            }
82
        }
83
    }
84
}

Return to bug 56777