Custom notFound is not working if webSocket is enabled
fatduckling opened this issue · comments
fatduckling commented
Hi,
Thanks for the great library!
I think I found a bug:
The notFound("<html><body><h1>Custom 404 handling</h1></body></html>");
does not work when websocket()
is used.
Here is my sample code:
import static spark.Spark.awaitInitialization;
import static spark.Spark.get;
import static spark.Spark.init;
import static spark.Spark.notFound;
import static spark.Spark.port;
import static spark.Spark.webSocket;
import java.io.IOException;
import java.util.Queue;
import java.util.concurrent.ConcurrentLinkedQueue;
import org.eclipse.jetty.websocket.api.Session;
import org.eclipse.jetty.websocket.api.annotations.OnWebSocketClose;
import org.eclipse.jetty.websocket.api.annotations.OnWebSocketConnect;
import org.eclipse.jetty.websocket.api.annotations.OnWebSocketMessage;
import org.eclipse.jetty.websocket.api.annotations.WebSocket;
public class Main {
public static void main(final String[] args) {
port(8080);
webSocket("/", EchoWebSocket.class); // deleting this line would make notFound() work
init();
notFound("not found custom page");
get("/hello", (request, response) -> "hello world");
awaitInitialization();
}
}
@WebSocket
class EchoWebSocket {
// Store sessions if you want to, for example, broadcast a message to all users
private static final Queue<Session> sessions = new ConcurrentLinkedQueue<>();
@OnWebSocketConnect
public void connected(Session session) {
sessions.add(session);
}
@OnWebSocketClose
public void closed(Session session, int statusCode, String reason) {
sessions.remove(session);
}
@OnWebSocketMessage
public void message(Session session, String message) throws IOException {
System.out.println("Got: " + message); // Print message
session.getRemote().sendString(message); // and send it back
}
}
fatduckling commented
Duplicate of #783
Closing