Atmosphere servlet classloading conflict with java

36 views Asked by At

I am not sure how to title this question but I'll try to explain what the issue is. I am currently testing out Atmosphere framework in a web application. I started by reading the documentation and then testing the chat-multiroom sample. I am running it in eclipse using tomcat 8.5. When the atmosphere servlet initializes it will scan a package for any classes that have certain annotations and if it finds the annothions it will add the class to a map using a path as the key. For this to work it must first scan its own packages looking for what annotations it should use and add them to a map of available annotations. This list has to be populated for the annotated classes to be initialised. The code for this looks like this:

 public Class<? extends Processor> handleProcessor(Class<?> clazz) {
        if (Processor.class.isAssignableFrom(clazz)) {
            Class<Processor> p = (Class<Processor>) clazz;
            if (logger.isTraceEnabled()) {
                logger.trace("Processor {} associated with {}", p, p.getAnnotation(AtmosphereAnnotation.class).value());
            }
            annotations.put(p.getAnnotation(AtmosphereAnnotation.class).value(), p);
            return p;
        }
        return null;
    }

So it goes though every class it finds and checks if it implements Processor. Processeor is an interface provided by atmosphere imported with import org.atmosphere.annotation.Processor;

However when I debug this code it is instead compareing clazz with the jdk:s interface javax.annotation.processing.Processor instead of org.atmosphere.annotation.Processor. This is causing the map to be empty. This results in the endpoints are not loaded because there are no annotations to look for.

If I download the atmosphere code and copy it to my src folder it works correctly.

I am using Eclipse IDE at the moment and I am wondering if there is a way to configure the project or the tomcat server in some way to make it understand which interface it should use.

1

There are 1 answers

0
scaryxited On

[EDIT] After some more research the problem isn't due to the class comparision instead it is about how tomcat loads classes. Atmosphere relies on that the container loads the annotation classes and passes it into Atmosphere ServletContainerInitializer however tomcat will not pass the classes that exisit in the package jar files under the webapps lib folder. It will only pass in the classes that are in the webapps WEB-INF/classes folder and not the WEB-INF/lib folder. That is why it works if I add the Atmosphere src to the webapps src folder in eclipse.

[EDIT2] It turns out I had disabled jar scanning in catalina.properties. Enabling the jar scanning again solved the issue.