Reputation: 31815
Is there any way to use websockets in tomcat 6 (business requirement)?
I've been trying using javax.websocket.jar but I can't get it to work
Here's my code:
import java.io.IOException;
import java.nio.ByteBuffer;
import javax.websocket.OnMessage;
import javax.websocket.Session;
import javax.websocket.server.ServerEndpoint;
@ServerEndpoint("/echoAnnotation")
public class EchoAnnotation { @OnMessage
public void echoTextMessage(Session session, String msg, boolean last) {
try {
if (session.isOpen()) {
session.getBasicRemote().sendText(msg, last);
}
} catch (IOException e) {
try {
session.close();
} catch (IOException e1) {
// Ignore
}
}
}
}
And my web.xml:
<?xml version="1.0" encoding="ISO-8859-1"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
version="2.5">
<description>
Servlet and JSP Examples.
</description>
<display-name>Servlet and JSP Examples</display-name>
<servlet>
<servlet-name>echoAnnotation</servlet-name>
<servlet-class>EchoAnnotation</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>echoAnnotation</servlet-name>
<url-pattern>/echoAnnotation</url-pattern>
</servlet-mapping>
</web-app>
However I cannot make a websocket connection, I get an error message Firefox can't establish a connection to the server at ws://192.168.1.101:8080/prototypes/echoAnnotation
and going directly to the page results in HTTP Status 404 - Servlet echoAnnotation is not available
Is this possible? What am I doing wrong?
Upvotes: 1
Views: 2338
Reputation: 980
As I found tomcat 6 doesn't support Java WebSockets. See http://tomcat.apache.org/whichversion.html
Upvotes: 3