You can find the all the code below, started the tomcat server and It's perfectly working. But While making websocket request I'm getting 404 error. This is the error in chrome console :
WebSocket connection to 'ws://localhost:8088/websocket-example/websocket' failed: Error during WebSocket handshake: Unexpected response code: 404
and there is no server log.
Java WebSocket Code : WebSocketTest.java
package com.websockets;
import java.io.IOException;
import javax.websocket.OnClose;
import javax.websocket.OnMessage;
import javax.websocket.OnOpen;
import javax.websocket.Session;
import javax.websocket.server.ServerEndpoint;
@ServerEndpoint("/websocket")
public class WebSocketTest {
@OnMessage
public void onMessage(String message, Session session) throws IOException,
InterruptedException {
System.out.println("Message: " + message);
session.getBasicRemote().sendText("Hello Mr. " + message);
}
@OnOpen
public void onOpen() {
System.out.println("Client connected");
}
@OnClose
public void onClose() {
System.out.println("Connection closed");
}
}
JS Code : hello.html
var webSocket = new WebSocket('ws://localhost:8088/websocket-example/websocket');
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_3_0.xsd"
version="3.0">
<welcome-file-list>
<welcome-file>hello.html</welcome-file>
</welcome-file-list>
</web-app>
Folder structure unders tomcat/webapps..
->webapps
->websocket-example
->hello.html
->WEB-INF
->classes
->com
->websockets
-> WebSocketTest.class
->web.xml
more info :
java version "1.7.0_75"
apache-tomcat-8.0.32
server running port : 8088
I'm not sure this information is enough,Let me know any other details need to debug?