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();
}
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());
}
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
}
}
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);
}
}
}
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");
}
Aggregations