This works:
String webappDir = "...";
context = tomcat.addWebapp("/", new File(webappDir).getAbsolutePath());
This doesn't:
context = tomcat.addContext("/", new File("").getAbsolutePath());
I don't really need a webappDir
in this instance because I am not serving any JSP pages or client-side resources, I'm simply using response.getWriter().println(...);
server-side only.
There is no exception being thrown, the websocket simply does not open.
Can I assume that this is a tomcat bug?
By definition websockets like normal sockets are client-server so yes, you need a server.
- In Control Panel, click Programs and Features, and then click Turn Windows features on or off. Expand Internet Information Services, expand World Wide Web Services, expand Application Development Features, and then select WebSocket Protocol. Click OK. Click Close.
Websockets are largely obsolete because nowadays, if you create a HTTP/2 fetch request, any existing keepalive connection to that server is used, so the overhead that pre-HTTP/2 XHR connections needed is lost and with it the advantage of Websockets.
Avoid using WebSockets if only a small number of messages will be sent or if the messaging is very infrequent. Unless the client must quickly receive or act upon updates, maintaining the open connection may be an unnecessary waste of resources.
well, those two are completely different function. If you look at the javadoc for the function addContext
, you can see that, you need to setup the context to be able to use websocket. this is retrieved from the api doc.
Add a context - programmatic mode, no default web.xml used. This means that there is no JSP support (no JSP servlet), no default servlet and no web socket support unless explicitly enabled via the programmatic interface.
So, in your case, I guess you can follow the test case in this link how to add an end point into the context.
As for whether you can assume that this is a bug or not. Personally, I don't think this is a bug as the developer itself already mention that they don't provide the web socket connection. But, to make sure, you may contact them and ask ;).
If you look into the tests (test/org/apache/tomcat/websocket in the source code), they do
tomcat.addContext("", null);
Note that passing null
instead of a context path needs a recent Tomcat 8 (no older than several months). The current version is 8.0.22.
Can I assume that this is a tomcat bug?
The rule "before filing a bug" is to ask on the users' mailing list, not on stackoverflow.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With