tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Mark Thomas <ma...@apache.org>
Subject Re: Unable to establish WebSocket connection on Tomcat Embed (9.0.24)
Date Mon, 04 Nov 2019 13:55:36 GMT
On 04/11/2019 12:59, Alexander Stöcker wrote:
> My code is basically just:
> 
>         Tomcat tomcat = new Tomcat();
>         tomcat.getConnector();
>         tomcat.setPort(8080);
> 
>         Context context = tomcat.addContext("/context", new
> File(".").getAbsolutePath());
> 
>         // servlet
>         Tomcat.addServlet(context, "myServlet", new MyServlet());
>         context.addServletMappingDecoded("/hello", "myServlet");
> 
>         // websocket
>         context.addApplicationListener(MyWSContextListener.class.getName());
> 
>         // run
>         tomcat.start();
>         tomcat.getServer().await();
> 
> 
> The WsContextListener is adding an Endpoint when contextInitialized()
> is called. Setting a Breakpoint shows that the code is actually
> executed. The Servlet is working but when I'm trying to connect to the
> endpoint ("ws://localhost:8080/context/endpoint") I get a 404. On Fine
> debug output I can see, that this exception is thrown, whenever a
> connection is requested:

You need to configure the default servlet. Otherwise the mapper looks at
the URI, sees that it doesn't match any known servlets and rejects the
request with a 404 before the WebSocket filter has a chance to handle
the request.

Mark

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Mime
View raw message