Open jfarcand opened 9 years ago
WebSocket connection to 'ws://127.0.0.1:8080/myapp-0.0.1-SNAPSHOT/websocket/activity?X-Atmosphere-tracking-id=0&X-Atmosphere-Framework=2.2.5-javascript&X-Atmosphere-Transport=websocket&X-Atmosphere-TrackMessageSize=true&Content-Type=application/json&X-atmo-protocol=true' failed: Error during WebSocket handshake: Unexpected response code: 404
atmosphere.js:3117 Websocket failed. Downgrading to Comet and resending
Is /websocket/activity
defined?
Have you started the application using spring-boot or dropper the war in tomcat?
This issue occurs when launching like this: mvn spring-boot:run
Yes. There is an ActivityService defined as
@ManagedService( path = "/websocket/activity") public class ActivityService
I'm also getting the handshake error when dropping the war directly in tomcat
There is serious issue here :-) Websocket is not available at all
DEBUG] pro.tremblay.myapp.aop.logging.LoggingAspect - Exit: pro.tremblay.myapp.repository.CustomAuditEventRepository.auditEventRepository() with result = pro.tremblay.myapp.repository.CustomAuditEventRepository$1@236b4a44
[WARN] org.atmosphere.util.IOUtils - META-INF/services/org.atmosphere.cpr.AtmosphereFramework not found in class loader
[ERROR] org.atmosphere.cpr.DefaultAsyncSupportResolver - failed to create comet support class: org.atmosphere.container.JSR356AsyncSupport, error: null
[ERROR] org.atmosphere.cpr.AtmosphereFramework - Failed to initialize Atmosphere Framework
java.lang.IllegalArgumentException: Unable to createorg.atmosphere.container.JSR356AsyncSupport
at org.atmosphere.cpr.DefaultAsyncSupportResolver.newCometSupport(DefaultAsyncSupportResolver.java:242) ~[atmosphere-runtime-native-2.2.3.jar:2.2.3]
at org.atmosphere.cpr.AtmosphereFramework.doInitParams(AtmosphereFramework.java:1330) [atmosphere-runtime-native-2.2.3.jar:2.2.3]
at org.atmosphere.cpr.AtmosphereFramework.doInitParams(AtmosphereFramework.java:1305) [atmosphere-runtime-native-2.2.3.jar:2.2.3]
And
[ERROR] org.apache.catalina.core.ContainerBase.[Tomcat].[localhost].[/] - Servlet threw load() exception
java.lang.IllegalStateException: ServerContainer is null. Make sure you are using JDK7 and your server has websocket support enabled
at org.atmosphere.container.JSR356AsyncSupport.<init>(JSR356AsyncSupport.java:43) ~[atmosphere-runtime-native-2.2.3.jar:2.2.3]
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[na:1.8.0_25]
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) ~[na:1.8.0_25]
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[na:1.8.0_25]
at java.lang.reflect.Constructor.newInstance(Constructor.java:408) ~[na:1.8.0_25]
at org.atmosphere.cpr.DefaultAsyncSupportResolver.newCometSupport(DefaultAsyncSupportResolver.java:238) ~[atmosphere-runtime-native-2.2.3.jar:2.2.3]
I don't know how Spring Boot works, but normally the first class executed should be org.atmosphere.cpr.AtmosphereInitializer
as this is where Tomcat's JSR 356 ServerContainer is retrieved.
Spring Boot is seems to be broken: https://github.com/spring-projects/spring-boot/issues/1722
Use
private void initAtmosphereServlet(ServletContext servletContext) {
log.error("Registering Atmosphere Servlet");
AtmosphereServlet servlet = new AtmosphereServlet();
Field frameworkField = ReflectionUtils.findField(AtmosphereServlet.class, "framework");
ReflectionUtils.makeAccessible(frameworkField);
NoAnalyticsAtmosphereFramework atmosphereFramework = new NoAnalyticsAtmosphereFramework();
ReflectionUtils.setField(frameworkField, servlet, atmosphereFramework);
ServletRegistration.Dynamic atmosphereServlet =
servletContext.addServlet("atmosphereServlet", servlet);
servletContext.setAttribute("AtmosphereServlet", atmosphereFramework);
atmosphereServlet.setInitParameter("org.atmosphere.cpr.packages", "pro.tremblay.myapp.web.websocket");
atmosphereServlet.setInitParameter("org.atmosphere.cpr.asyncSupport", Servlet30CometSupport.class.getName());
servletContext.addListener(new org.atmosphere.cpr.SessionSupport());
atmosphereServlet.addMapping("/websocket/*");
atmosphereServlet.setLoadOnStartup(3);
atmosphereServlet.setAsyncSupported(true);
}
but there are serious issue with SpringBoot + WebSocket.
Ok. But I don't seem to have any @ServerEndpoint.
How is the AtmosphereInitializer supposed to by called?
AtmosphereInitializer is supposed to be called by the server itself. e.g any application deployed in a J2EE Container will be initialized when a META-INF/services is defined. This is Servlet Spec basic. Unclear to me why Spring Boot breaks that.
Wow. That's much better. Now I'm getting some live results. Thanks!
spring-boot seems to require to emulate some J2EE behavior manually. There is a SpringBootServletInitializer. So the AtmosphereInitializer should probably be called somewhere around there.
However, I'm getting a bunch of
[WARN] org.atmosphere.util.IOUtils - java.io.IOException: Stream closed at org.apache.catalina.connector.InputBuffer.read(InputBuffer.java:360) ~[tomcat-embed-core-8.0.15.jar:8.0.15] at org.apache.catalina.connector.CoyoteInputStream.read(CoyoteInputStream.java:190) ~[tomcat-embed-core-8.0.15.jar:8.0.15] at sun.nio.cs.StreamDecoder.readBytes(StreamDecoder.java:284) ~[na:1.8.0_20] at sun.nio.cs.StreamDecoder.implRead(StreamDecoder.java:326) ~[na:1.8.0_20] at sun.nio.cs.StreamDecoder.read(StreamDecoder.java:178) ~[na:1.8.0_20] at java.io.InputStreamReader.read(InputStreamReader.java:184) ~[na:1.8.0_20] at java.io.BufferedReader.read1(BufferedReader.java:210) ~[na:1.8.0_20] at java.io.BufferedReader.read(BufferedReader.java:286) ~[na:1.8.0_20] at java.io.Reader.read(Reader.java:140) ~[na:1.8.0_20]
Hum. The SpringBootServletInitializer isn't called either. They must be called only when deployed on a server. I think initAtmosphereServlet is supposed to replace the AtmosphereInitializer but doesn't work very well.
At least I should be able to work now. Thanks!
Hum... The world is not saved yet. After a while, it freezes the browser and I'm getting these:
WARN] org.atmosphere.config.managed.ManagedAtmosphereHandler - AtmosphereRequest{ method=POST contextPath= servletPath=/websocket pathInfo=/activity requestURI=/websocket/activity requestURL=http://localhost:8080/websocket/activity AtmosphereResource UUID=33540705-9766-44ae-b31d-4874776b91d3 destroyable=true} received an empty body [WARN] org.atmosphere.util.IOUtils - java.io.IOException: Stream closed
But it kinda looks like the tracker is tracking the websocket themselves or something weird like that.
the issue. I've deployed on Tomcat 8.0.15 and everything seems to starts properly. What is the next steps?