Java Code Examples for org.apache.tomcat.util.compat.JreCompat#isJre7Available()

The following examples show how to use org.apache.tomcat.util.compat.JreCompat#isJre7Available() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: WebappClassLoaderBase.java    From Tomcat7.0.67 with Apache License 2.0 5 votes vote down vote up
private Object getClassLoadingLockInternal(String className) {
    if (JreCompat.isJre7Available() && GET_CLASSLOADING_LOCK_METHOD != null) {
        try {
            return GET_CLASSLOADING_LOCK_METHOD.invoke(this, className);
        } catch (Exception e) {
            // ignore
        }
    }
    return this;
}
 
Example 2
Source File: TestParallelWebappClassLoader.java    From Tomcat7.0.67 with Apache License 2.0 5 votes vote down vote up
@Test
public void testParallelCapableOnJre7() {
    if (!JreCompat.isJre7Available()) {
        // ignore on Jre6 or lower
        return;
    }
    try {
        Tomcat tomcat = getTomcatInstance();
        Context ctx = tomcat.addContext("", null);

        WebappLoader webappLoader = new WebappLoader();
        webappLoader.setLoaderClass(PARALLEL_CLASSLOADER);
        ctx.setLoader(webappLoader);

        tomcat.start();

        ClassLoader classloader = ctx.getLoader().getClassLoader();

        Assert.assertTrue(classloader instanceof ParallelWebappClassLoader);

        // parallel class loading capable
        Method getClassLoadingLock =
                getDeclaredMethod(classloader.getClass(), "getClassLoadingLock", String.class);
        // make sure we have getClassLoadingLock on JRE7.
        Assert.assertNotNull(getClassLoadingLock);
        // give us permission to access protected method
        getClassLoadingLock.setAccessible(true);

        Object lock = getClassLoadingLock.invoke(classloader, DUMMY_SERVLET);
        // make sure it is not a ParallelWebappClassLoader object lock
        Assert.assertNotEquals(lock, classloader);
    } catch (Exception e) {
        e.printStackTrace();
        Assert.fail("testParallelCapableOnJre7 fails.");
    }
}
 
Example 3
Source File: TestParallelWebappClassLoader.java    From Tomcat7.0.67 with Apache License 2.0 5 votes vote down vote up
@Test
public void testParallelIncapableOnJre6() {
    if (JreCompat.isJre7Available()) {
        // ignore on Jre7 or above
        return;
    }
    try {
        Tomcat tomcat = getTomcatInstance();
        // Must have a real docBase - just use temp
        Context ctx = tomcat.addContext("",
                System.getProperty("java.io.tmpdir"));

        WebappLoader webappLoader = new WebappLoader();
        webappLoader.setLoaderClass(PARALLEL_CLASSLOADER);
        ctx.setLoader(webappLoader);

        tomcat.start();

        ClassLoader classloader = ctx.getLoader().getClassLoader();

        Assert.assertTrue(classloader instanceof ParallelWebappClassLoader);

        // parallel class loading capable
        Method getClassLoadingLock =
                getDeclaredMethod(classloader.getClass(), "getClassLoadingLock", String.class);
        // make sure we don't have getClassLoadingLock on JRE6.
        Assert.assertNull(getClassLoadingLock);
    } catch (Exception e) {
        e.printStackTrace();
        Assert.fail("testParallelIncapableOnJre6 fails.");
    }
}
 
Example 4
Source File: WebappClassLoaderBase.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
private Object getClassLoadingLockInternal(String className) {
    if (JreCompat.isJre7Available() && GET_CLASSLOADING_LOCK_METHOD != null) {
        try {
            return GET_CLASSLOADING_LOCK_METHOD.invoke(this, className);
        } catch (Exception e) {
            // ignore
        }
    }
    return this;
}
 
Example 5
Source File: TestParallelWebappClassLoader.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
@Test
public void testParallelCapableOnJre7() {
    if (!JreCompat.isJre7Available()) {
        // ignore on Jre6 or lower
        return;
    }
    try {
        Tomcat tomcat = getTomcatInstance();
        Context ctx = tomcat.addContext("", null);

        WebappLoader webappLoader = new WebappLoader();
        webappLoader.setLoaderClass(PARALLEL_CLASSLOADER);
        ctx.setLoader(webappLoader);

        tomcat.start();

        ClassLoader classloader = ctx.getLoader().getClassLoader();

        Assert.assertTrue(classloader instanceof ParallelWebappClassLoader);

        // parallel class loading capable
        Method getClassLoadingLock =
                getDeclaredMethod(classloader.getClass(), "getClassLoadingLock", String.class);
        // make sure we have getClassLoadingLock on JRE7.
        Assert.assertNotNull(getClassLoadingLock);
        // give us permission to access protected method
        getClassLoadingLock.setAccessible(true);

        Object lock = getClassLoadingLock.invoke(classloader, DUMMY_SERVLET);
        // make sure it is not a ParallelWebappClassLoader object lock
        Assert.assertNotEquals(lock, classloader);
    } catch (Exception e) {
        e.printStackTrace();
        Assert.fail("testParallelCapableOnJre7 fails.");
    }
}
 
Example 6
Source File: TestParallelWebappClassLoader.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
@Test
public void testParallelIncapableOnJre6() {
    if (JreCompat.isJre7Available()) {
        // ignore on Jre7 or above
        return;
    }
    try {
        Tomcat tomcat = getTomcatInstance();
        // Must have a real docBase - just use temp
        Context ctx = tomcat.addContext("",
                System.getProperty("java.io.tmpdir"));

        WebappLoader webappLoader = new WebappLoader();
        webappLoader.setLoaderClass(PARALLEL_CLASSLOADER);
        ctx.setLoader(webappLoader);

        tomcat.start();

        ClassLoader classloader = ctx.getLoader().getClassLoader();

        Assert.assertTrue(classloader instanceof ParallelWebappClassLoader);

        // parallel class loading capable
        Method getClassLoadingLock =
                getDeclaredMethod(classloader.getClass(), "getClassLoadingLock", String.class);
        // make sure we don't have getClassLoadingLock on JRE6.
        Assert.assertNull(getClassLoadingLock);
    } catch (Exception e) {
        e.printStackTrace();
        Assert.fail("testParallelIncapableOnJre6 fails.");
    }
}