Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Spring Boot] Atmosphere can't scan its annotations when packaged into an executable WAR file #1706

Closed
jdubois opened this issue Aug 31, 2014 · 21 comments

Comments

@jdubois
Copy link

jdubois commented Aug 31, 2014

This comes from this ticket in JHipster:

jhipster/generator-jhipster#471

Atmosphere runs fine when we do a "mvn spring-boot:run", but if we package it into an executable WAR file with Spring Boot, even if we use the "requireUnpack" trick (see http://stackoverflow.com/questions/24117886/jhipster-executable-war-not-executable-in-combination-with-atmosphere ), it cannot scan its annotations, and hence fails at startup.

It's easy to reproduce: create a project with JHipster, selecting the Atmosphere option (of course!), and then do a "mvn package". Then try to execute the generated executable WAR file.

@gdrouet
Copy link
Member

gdrouet commented Sep 2, 2014

Salut Julien,

I reproduced the issue. I deploy under tomcat 8 so atmosphere relies on Servlet 3 support to detect annotation.

But when atmosphere selects the implementation at this step and then calls configure, the underlying implementation does nothing.

@jfarcand do you know why? Maybe I'm checking in the wrong place.

@gdrouet
Copy link
Member

gdrouet commented Sep 2, 2014

@jdubois please confirm you have the issue described in #1663, this is what I reproduced...

@jfarcand
Copy link
Member

jfarcand commented Sep 2, 2014

@gdrouet I need to debug but I suspect the classes aren't at the normal location, e.g not under WEB-INF/classes or WEB-INF/lib.

@jfarcand jfarcand changed the title Atmosphere can't scan its annotations when packaged into an executable WAR file [Spring Boot] Atmosphere can't scan its annotations when packaged into an executable WAR file Sep 2, 2014
@jfarcand
Copy link
Member

jfarcand commented Sep 2, 2014

Changed the title as all Atmosphere's sample works fine, without any issue with Tomcat 8.0.x

@gdrouet
Copy link
Member

gdrouet commented Sep 2, 2014

Hum no. The classes are located under WEB-INF/classes

Actually the WAR seems well packaged. What really differs from samples is that no web.xm exists.

@jfarcand
Copy link
Member

jfarcand commented Sep 2, 2014

Then the issue is org.atmosphere.cpr.packages property must be defined in web.xml or somewhere in the application itself. I'm completety swamped this week but will try to look as soon as I can.

@jdubois
Copy link
Author

jdubois commented Sep 3, 2014

@gdrouet no, the error (as seen in jhipster/generator-jhipster#471 ) is a " java.lang.IllegalArgumentException: URI is not hierarchical"

@jfarcand no, this is configured in Java, in the "WebConfigurer" class we do:
atmosphereServlet.setInitParameter("org.atmosphere.cpr.packages", "com.mycompany.myapp.web.websocket");

You can find below a sample generated project. The whole code is there (it's a Maven project, easy to open!), and in the target/ directory you have the executable WAR file (run it with java -jar *.war):
https://www.dropbox.com/s/jvnx595ocgkrsme/jhipster-sample-app-atmosphere.zip?dl=0

@jfarcand
Copy link
Member

jfarcand commented Sep 3, 2014

@jdubois Is this a regression or that new code? I'm curious to isolate it that's a regression. My blindly guess is the classloading is different. Anyway will take a look as soon as I can next week. Merci!

@jfarcand
Copy link
Member

jfarcand commented Sep 4, 2014

It seems the META-INF/services/javax.servlet.ServletContainerInitializer is not read by Tomcat, hence Atmosphere isn't initialized properly and classes aren't scanned.

@jdubois
Copy link
Author

jdubois commented Sep 4, 2014

As I updated to the latest version of Spring Boot, and that Spring Boot provides Tomcat, it is highly possible that this new version of Tomcat causes the bug.
I didn't change my code, and didn't change the Atmosphere version anyway...
@jfarcand what do you recommend? Do we "accept" that Atmosphere doesn't work on the latest Tomcat version? Do you have a way to patch it?

@jfarcand
Copy link
Member

jfarcand commented Sep 4, 2014

@jdubois Atmosphere works with the latest Tomcat version. I do vote on every Tomcat release (like the new 8.0.12) :-)...the issue is when the embedded API is used. I'm investigating solution right now, but first I try with Atmosphere 2.1.8 and your code. More to come...

@jfarcand
Copy link
Member

jfarcand commented Sep 4, 2014

So to recap, META-INF/services/javax.servlet.ServletContainerInitializer is not honored when Tomcat embedded is used. Normally this file honored and annotation scanning is done by Tomcat, not Atmosphere.

Atmosphere fallback to use it's own Annotation scanner but fail with the exception above. The scanner normally assume it runs on an exploded war (most server does that or properly configure the classloader based on that fact), hence fails miserably. I'm trying to see if I can fix that but keep in mind the real issue is Tomcat/Spring Boot. Not sure yet which one is causing issue, but I suspect Spring Boot :-)

jfarcand added a commit that referenced this issue Sep 4, 2014
jfarcand added a commit that referenced this issue Sep 4, 2014
jfarcand added a commit that referenced this issue Sep 4, 2014
@jfarcand jfarcand added 2.1.9 and removed 2.1.8 labels Sep 4, 2014
@jfarcand
Copy link
Member

jfarcand commented Sep 4, 2014

OK found a workaround, will be available in 2.1.9, 2.2.1 + . @jdubois Can you test with 2.1.9-SNAPSHOT to make sure all functionalities are working? Now annotations are scanned, but I suspect other issue may arise because of the failure to process the META/services.

@jfarcand jfarcand closed this as completed Sep 4, 2014
@jdubois
Copy link
Author

jdubois commented Sep 4, 2014

Great, thanks @jfarcand !
I'll add a comment here when I have tested

@slovdahl
Copy link
Contributor

@jdubois have you had the time to test it out yet? Planning to release 2.1.9 as soon as possible.

@jdubois
Copy link
Author

jdubois commented Sep 15, 2014

@slovdahl no... I'm currently trying to, but found a bunch of other issues... Hopefully I will do it tomorrow. Don't wait for me!

@jfarcand
Copy link
Member

@jdubois If you can share the workspace/sample you are working on, I can take a look ASAP. You shoudn't have so many issues.

@jdubois
Copy link
Author

jdubois commented Sep 15, 2014

@jfarcand I won't be able to do it until tomorrow... If you have time, just generate a JHipster project with the "atmosphere" option

@slovdahl
Copy link
Contributor

@jdubois Any progress on this yet? Aiming for a release on monday the 22th of September.

@jdubois
Copy link
Author

jdubois commented Sep 18, 2014

@jfarcand here is my sample project:

https://www.dropbox.com/s/widhpbtogf5f7rl/jhipster-sample-app-atmosphere.tar.gz?dl=0

You can run it with "mvn spring-boot:run" or package it with "mvn package". And run the generated WAR file with "java -jar file.war".
It's with Atmosphere 2.2.0, with the error mentionned in this thread.

@jdubois
Copy link
Author

jdubois commented Sep 19, 2014

@slovdahl yes, see my above comment. I've also commited my code if you want to test and have a look: jhipster/generator-jhipster@f849a80

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants