Bug 55312 - No SCI scan in embedded Tomcat
Summary: No SCI scan in embedded Tomcat
Status: RESOLVED FIXED
Alias: None
Product: Tomcat 8
Classification: Unclassified
Component: Catalina (show other bugs)
Version: 8.0.x-trunk
Hardware: PC Linux
: P2 normal (vote)
Target Milestone: ----
Assignee: Tomcat Developers Mailing List
URL:
Keywords:
Depends on: 55287
Blocks:
  Show dependency tree
 
Reported: 2013-07-26 15:37 UTC by Dave Syer
Modified: 2013-07-31 13:14 UTC (History)
0 users



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Dave Syer 2013-07-26 15:37:46 UTC
I like the fact that SCI scanning is off by default in a Tomcat embedded instance, but I'd lik eto be able to switch it on. It might even be possible already, but the API is non-obvious.  Maybe a method in Tomcat or associated friendly helper?

Would also be nice in Tomcat 7.
Comment 1 Dave Syer 2013-07-28 16:18:56 UTC
I played around with the Tomcat embedded server a bit more and found that it actually is relatively easy (if obscure) to switch on SCI:

		ContextConfig contextConfig = new ContextConfig();
		context.addLifecycleListener(contextConfig);

The biggest problem is that the classpath scanner only scans certain well-known locations (/WEB-INF/lib/*.jar, /WEB-INF/classes I am guessing) so it doesn't pick up anything else by default that happens to be on the classpath but in a different location (e.g. if you launch with java -jar, or from inside an IDE). I think that's a bigger problem than the obscure API for setting it up. There are some mentions in comments about /WEB-INF/classes being bound to multiple locations to help Eclipse tooling, so there is some precedence for the required generalization, but again no obvious API for adding bindings.
Comment 2 Jeremy Boynes 2013-07-28 17:52:01 UTC
I'm working on a fix for 55287 and as part of that I have separated the SCI discovery from ContextConfig. That would allow an embedder to perform their own scan for SCIs based on just the ServletContext obtained from the Context they are initializing.
Comment 3 Jeremy Boynes 2013-07-29 00:12:45 UTC
I committed the change to decouple SCI loading in http://svn.apache.org/r1507870

This should allow you to perform SCI detection separately from full ContextConfig. Does that help for your application?
Comment 4 Dave Syer 2013-07-29 08:50:56 UTC
It helps a bit. But it's actually the scan for HandlesTypes references that I need  to modify (populating the initializerClassMap in ContextConfig) - the SCIs are all discovered correctly, but their handlers are not unless they are in /WEB-INF/classes or /WEB-INF/lib/*.jar.
Comment 5 Mark Thomas 2013-07-29 17:49:12 UTC
(In reply to Dave Syer from comment #1)
> I played around with the Tomcat embedded server a bit more and found that it
> actually is relatively easy (if obscure) to switch on SCI:
> 
> 		ContextConfig contextConfig = new ContextConfig();
> 		context.addLifecycleListener(contextConfig);

Aside:

This is as expected if you are using addContext() vs addWebapp(). I have updated the Javadocs for the Tomcat class to try an make that clearer. I'm sure there is scope for further improvement to the docs. Patches welcome.
Comment 6 Mark Thomas 2013-07-30 10:04:30 UTC
Changing back to a bug as all classes should be scanned unless excluded via JARs to skip.

We should also check that classes deployed to CATALIBA_[BASE/|HOME]lib are scanned for matches to @HandlesTypes
Comment 7 Mark Thomas 2013-07-31 13:14:01 UTC
This has been fixed in trunk. All class path entries are now scanned for matches to @HandlesTypes.