On Mon, Nov 4, 2019 at 2:55 PM Mark Thomas <ma...@apache.org> wrote: > > 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-unsubscr...@tomcat.apache.org > For additional commands, e-mail: users-h...@tomcat.apache.org >
Indeed, that solved the Problem. I would have never been able to solve that just from documentation or examples... After some googling on "default servlet" I found this SO thread which gave me the solution: https://stackoverflow.com/questions/6349472/embedded-tomcat-not-serving-static-content TL;DR: You could either write: Wrapper defaultServlet = context.createWrapper(); defaultServlet.setName("default"); defaultServlet.setServletClass("org.apache.catalina.servlets.DefaultServlet"); defaultServlet.setLoadOnStartup(1); context.addChild(defaultServlet); context.addServletMappingDecoded("/", "default"); or just Tomcat.initWebappDefaults(context); thanks & best regards --------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org For additional commands, e-mail: users-h...@tomcat.apache.org