Search in sources :

Example 1 with JarScanFilter

use of org.apache.tomcat.JarScanFilter in project spring-boot by spring-projects.

the class TomcatServletWebServerFactoryTests method tldSkipPatternsShouldBeAppliedToContextJarScanner.

@Test
void tldSkipPatternsShouldBeAppliedToContextJarScanner() {
    TomcatServletWebServerFactory factory = getFactory();
    factory.addTldSkipPatterns("foo.jar", "bar.jar");
    this.webServer = factory.getWebServer();
    this.webServer.start();
    Tomcat tomcat = ((TomcatWebServer) this.webServer).getTomcat();
    Context context = (Context) tomcat.getHost().findChildren()[0];
    JarScanFilter jarScanFilter = context.getJarScanner().getJarScanFilter();
    assertThat(jarScanFilter.check(JarScanType.TLD, "foo.jar")).isFalse();
    assertThat(jarScanFilter.check(JarScanType.TLD, "bar.jar")).isFalse();
    assertThat(jarScanFilter.check(JarScanType.TLD, "test.jar")).isTrue();
}
Also used : InitialContext(javax.naming.InitialContext) ServletContext(jakarta.servlet.ServletContext) StandardContext(org.apache.catalina.core.StandardContext) Context(org.apache.catalina.Context) Tomcat(org.apache.catalina.startup.Tomcat) JarScanFilter(org.apache.tomcat.JarScanFilter) StandardJarScanFilter(org.apache.tomcat.util.scan.StandardJarScanFilter) Test(org.junit.jupiter.api.Test)

Example 2 with JarScanFilter

use of org.apache.tomcat.JarScanFilter in project tomee by apache.

the class TomcatWebAppBuilder method init.

/**
 * {@inheritDoc}
 */
@Override
public void init(final StandardContext standardContext) {
    if (isIgnored(standardContext)) {
        return;
    }
    // just adding a carriage return to get logs more readable
    LOGGER.info("------------------------- " + Contexts.getHostname(standardContext).replace("_", hosts.getDefaultHost()) + " -> " + finalName(standardContext.getPath()));
    if (FORCE_RELOADABLE) {
        final ContextInfo ctxInfo = getContextInfo(standardContext);
        if (ctxInfo == null || (ctxInfo.appInfo != null && ctxInfo.appInfo.webAppAlone)) {
            // don't do it for ears
            standardContext.setReloadable(true);
        }
    }
    if (SKIP_TLD) {
        if (standardContext.getJarScanner() != null && standardContext.getJarScanner().getJarScanFilter() != null) {
            final JarScanFilter jarScanFilter = standardContext.getJarScanner().getJarScanFilter();
            if (StandardJarScanFilter.class.isInstance(jarScanFilter)) {
                StandardJarScanFilter.class.cast(jarScanFilter).setDefaultTldScan(false);
            }
        }
    }
    final String name = standardContext.getName();
    initJ2EEInfo(standardContext);
    File warFile = Contexts.warPath(standardContext);
    if (!warFile.exists()) {
        return;
    }
    if (!warFile.isDirectory()) {
        try {
            warFile = DeploymentLoader.unpack(warFile);
        } catch (final OpenEJBException e) {
            LOGGER.error("can't unpack '" + warFile.getAbsolutePath() + "'");
        }
    }
    standardContext.setCrossContext(SystemInstance.get().getOptions().get(OPENEJB_CROSSCONTEXT_PROPERTY, false));
    standardContext.setNamingResources(new OpenEJBNamingResource(standardContext.getNamingResources()));
    String sessionManager = SystemInstance.get().getOptions().get(OPENEJB_SESSION_MANAGER_PROPERTY + "." + name, (String) null);
    if (sessionManager == null) {
        sessionManager = SystemInstance.get().getOptions().get(OPENEJB_SESSION_MANAGER_PROPERTY, (String) null);
    }
    if (sessionManager != null) {
        if (sessionManagerClass == null) {
            try {
                // the manager should be in standardclassloader
                sessionManagerClass = ParentClassLoaderFinder.Helper.get().loadClass(sessionManager);
            } catch (final ClassNotFoundException e) {
                LOGGER.error("can't find '" + sessionManager + "', StandardManager will be used", e);
                sessionManagerClass = StandardManager.class;
            }
        }
        try {
            final Manager mgr = (Manager) sessionManagerClass.newInstance();
            standardContext.setManager(mgr);
        } catch (final Exception e) {
            LOGGER.error("can't instantiate '" + sessionManager + "', StandardManager will be used", e);
        }
    }
    final LifecycleListener[] listeners = standardContext.findLifecycleListeners();
    for (final LifecycleListener l : listeners) {
        if (l instanceof ContextConfig) {
            standardContext.removeLifecycleListener(l);
        }
    }
    standardContext.addLifecycleListener(new OpenEJBContextConfig(new StandardContextInfo(standardContext)));
    // force manually the namingContextListener to merge jndi in an easier way
    final NamingContextListener ncl = new NamingContextListener();
    try {
        ncl.setName((String) GET_NAMING_CONTEXT_NAME.invoke(standardContext));
    } catch (final Exception e) {
        ncl.setName(getId(standardContext));
    }
    ncl.setExceptionOnFailedWrite(standardContext.getJndiExceptionOnFailedWrite());
    standardContext.setNamingContextListener(ncl);
    standardContext.addLifecycleListener(ncl);
    standardContext.addLifecycleListener(new TomcatJavaJndiBinder());
    // listen some events
    standardContext.addContainerListener(new TomEEContainerListener());
}
Also used : OpenEJBException(org.apache.openejb.OpenEJBException) StandardManager(org.apache.catalina.session.StandardManager) JarScanFilter(org.apache.tomcat.JarScanFilter) StandardJarScanFilter(org.apache.tomcat.util.scan.StandardJarScanFilter) OpenEJBContextConfig(org.apache.catalina.startup.OpenEJBContextConfig) LifecycleListener(org.apache.catalina.LifecycleListener) Manager(org.apache.catalina.Manager) InstanceManager(org.apache.tomcat.InstanceManager) StandardManager(org.apache.catalina.session.StandardManager) DeploymentExceptionManager(org.apache.openejb.assembler.classic.DeploymentExceptionManager) TransactionManager(javax.transaction.TransactionManager) StandardJarScanFilter(org.apache.tomcat.util.scan.StandardJarScanFilter) LifecycleException(org.apache.catalina.LifecycleException) NameNotFoundException(javax.naming.NameNotFoundException) IOException(java.io.IOException) NamingException(javax.naming.NamingException) OpenEJBException(org.apache.openejb.OpenEJBException) OpenEJBRuntimeException(org.apache.openejb.OpenEJBRuntimeException) ContextConfig(org.apache.catalina.startup.ContextConfig) OpenEJBContextConfig(org.apache.catalina.startup.OpenEJBContextConfig) NamingContextListener(org.apache.catalina.core.NamingContextListener) File(java.io.File) JarFile(java.util.jar.JarFile)

Example 3 with JarScanFilter

use of org.apache.tomcat.JarScanFilter in project tomee by apache.

the class TomcatHelper method configureJarScanner.

public static void configureJarScanner(final Context standardContext) {
    try {
        // override only if default
        final JarScanner originalJarScanner = standardContext.getJarScanner();
        if ("true".equalsIgnoreCase(SystemInstance.get().getProperty("tomee.tomcat.override.jar-scanner", "true")) && !TomEEJarScanner.class.isInstance(originalJarScanner) && StandardJarScanner.class.isInstance(originalJarScanner)) {
            final TomEEJarScanner jarScanner = new TomEEJarScanner();
            final Properties properties = SystemInstance.get().getProperties();
            final String scanClasspath = properties.getProperty(TomEEJarScanner.class.getName() + ".scanClassPath");
            if (scanClasspath != null) {
                jarScanner.setScanClassPath(Boolean.parseBoolean(scanClasspath));
            }
            final String scanBootstrap = properties.getProperty(TomEEJarScanner.class.getName() + ".scanBootstrapClassPath");
            if (scanBootstrap != null) {
                jarScanner.setScanBootstrapClassPath(Boolean.parseBoolean(scanBootstrap));
            }
            final JarScanFilter jarScanFilter = originalJarScanner.getJarScanFilter();
            if (jarScanFilter != null && Boolean.parseBoolean(properties.getProperty(TomEEJarScanner.class.getName() + ".useOriginalJarScannerFilter", "true"))) {
                jarScanner.setJarScanFilter(jarScanFilter);
            }
            standardContext.setJarScanner(jarScanner);
        }
    } catch (final Exception e) {
    // ignore
    }
}
Also used : StandardJarScanner(org.apache.tomcat.util.scan.StandardJarScanner) JarScanFilter(org.apache.tomcat.JarScanFilter) Properties(java.util.Properties) JarScanner(org.apache.tomcat.JarScanner) StandardJarScanner(org.apache.tomcat.util.scan.StandardJarScanner)

Example 4 with JarScanFilter

use of org.apache.tomcat.JarScanFilter in project tomcat by apache.

the class JarScannerSF method storeChildren.

/**
 * Store the specified JarScanner properties and children
 * (JarScannerFilter)
 *
 * @param aWriter
 *            PrintWriter to which we are storing
 * @param indent
 *            Number of spaces to indent this element
 * @param aJarScanner
 *            JarScanner whose properties are being stored
 *
 * @exception Exception
 *                if an exception occurs while storing
 */
@Override
public void storeChildren(PrintWriter aWriter, int indent, Object aJarScanner, StoreDescription parentDesc) throws Exception {
    if (aJarScanner instanceof JarScanner) {
        JarScanner jarScanner = (JarScanner) aJarScanner;
        // Store nested <JarScanFilter> element
        JarScanFilter jarScanFilter = jarScanner.getJarScanFilter();
        if (jarScanFilter != null) {
            storeElement(aWriter, indent, jarScanFilter);
        }
    }
}
Also used : JarScanFilter(org.apache.tomcat.JarScanFilter) JarScanner(org.apache.tomcat.JarScanner)

Example 5 with JarScanFilter

use of org.apache.tomcat.JarScanFilter in project spring-boot by spring-projects.

the class TomcatServletWebServerFactoryTests method tldScanPatternsShouldBeAppliedToContextJarScanner.

@Test
void tldScanPatternsShouldBeAppliedToContextJarScanner() {
    TomcatServletWebServerFactory factory = getFactory();
    this.webServer = factory.getWebServer();
    this.webServer.start();
    Tomcat tomcat = ((TomcatWebServer) this.webServer).getTomcat();
    Context context = (Context) tomcat.getHost().findChildren()[0];
    JarScanFilter jarScanFilter = context.getJarScanner().getJarScanFilter();
    String tldScan = ((StandardJarScanFilter) jarScanFilter).getTldScan();
    assertThat(tldScan).isEqualTo("log4j-taglib*.jar,log4j-web*.jar,log4javascript*.jar,slf4j-taglib*.jar");
}
Also used : InitialContext(javax.naming.InitialContext) ServletContext(jakarta.servlet.ServletContext) StandardContext(org.apache.catalina.core.StandardContext) Context(org.apache.catalina.Context) Tomcat(org.apache.catalina.startup.Tomcat) JarScanFilter(org.apache.tomcat.JarScanFilter) StandardJarScanFilter(org.apache.tomcat.util.scan.StandardJarScanFilter) StandardJarScanFilter(org.apache.tomcat.util.scan.StandardJarScanFilter) Test(org.junit.jupiter.api.Test)

Aggregations

JarScanFilter (org.apache.tomcat.JarScanFilter)6 StandardJarScanFilter (org.apache.tomcat.util.scan.StandardJarScanFilter)3 ServletContext (jakarta.servlet.ServletContext)2 InitialContext (javax.naming.InitialContext)2 Context (org.apache.catalina.Context)2 StandardContext (org.apache.catalina.core.StandardContext)2 Tomcat (org.apache.catalina.startup.Tomcat)2 JarScanner (org.apache.tomcat.JarScanner)2 Test (org.junit.jupiter.api.Test)2 File (java.io.File)1 IOException (java.io.IOException)1 Properties (java.util.Properties)1 JarFile (java.util.jar.JarFile)1 NameNotFoundException (javax.naming.NameNotFoundException)1 NamingException (javax.naming.NamingException)1 TransactionManager (javax.transaction.TransactionManager)1 LifecycleException (org.apache.catalina.LifecycleException)1 LifecycleListener (org.apache.catalina.LifecycleListener)1 Manager (org.apache.catalina.Manager)1 NamingContextListener (org.apache.catalina.core.NamingContextListener)1