I would like to use web socket, and I started looking to do so with tomcat API. I'm currently using Tomcat 7.0.37.
I tried to follow the example code from tomcat documentation.
I'm also using maven for the project, so I added this to my pom.xml :
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-catalina</artifactId>
<version>7.0.39</version>
<scope>provided</scope>
</dependency>
First thing that's weird, I get an error message in Eclipse for this line :
private class MyMessageInbound extends MessageInbound
The error message is "The hierarchy of the type MyMessageInbound is inconsistent", but I'm still able to compile and launch the webapp.
I also added the configuration in the web.xml as follow:
<servlet>
<servlet-name>wsChat</servlet-name>
<servlet-class>websocket.chat.ChatWebSocketServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>wsChat</servlet-name>
<url-pattern>/websocket/chat</url-pattern>
</servlet-mapping>
So, I'm able to launch the webapp, but when I go to the chat page, I get an error on the chat board saying "Info: WebSocket closed.". Tomcat log give me the following message:
SEVERE: Servlet.service() for servlet [wsChat] in context with path [/websocket-tuto] threw exception [L''exécution de la servlet a lancé une exception] with root cause
java.lang.NoSuchMethodError: websocket.chat.ChatWebSocketServlet$MyMessageInbound.<init>(Lwebsocket/chat/ChatWebSocketServlet;Luwebsocket/chat/ChatWebSocketServlet$MyMessageInbound;)V
at websocket.chat.ChatWebSocketServlet.createWebSocketInbound(ChatWebSocketServlet.java:34)
at org.apache.catalina.websocket.WebSocketServlet.doGet(WebSocketServlet.java:121)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:936)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1004)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
I think the only missing information here is the source of the chat page.
Anyone see what I'm doing wrong ??
Thanks
I solved the issue !
I tried to package the project with Maven on command line, and get this error:
[ERROR] class file for org.apache.coyote.http11.upgrade.UpgradeInbound not found
From this, I just added the following to the pom.xml:
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-coyote</artifactId>
<version>7.0.39</version>
<scope>provided</scope>
</dependency>
I hope this will help others with the same issue.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With