0
votes

Did somebody managed to run Websockets on Microsoft Azure WebApp-Service using Tomcat? I tried to run the Tomcat 7 chat-application-example, but I can't connect to the Websocket Endpoint. I allways receive this message:

WebSocket connection to 'ws://mywebapp.azurewebsites.net/websocket-example/websocket/chat' failed: Error during WebSocket handshake: Unexpected response code: 404

When running it locally everythings works fine. Locally and on Azure I'm using Tomcat 7 together with Java 7 (32bit) and enabled the Websocket option in the Azure App-Settings, as described here.

What else do I need to do, to get Websockets working on Azure with a Java WebApp?

Are Websockets on Azure only working with Node.js and ASP.NET?

UPDATE:

Websockets are working on Azure with Tomcat! You have to make shure that Websockets are enabled in the Azure Portal and that you select the correct Java,Tomcat and Plattform version that your .war file has been compiled for. In addition to that you have to make shure your ServerEndpoints are loaded correctly as described here!

2

2 Answers

2
votes

I had also a problem configuring websocket connection for azure web app running a tomcat 9 webserver setup. I add this answer here, because this page is the first google result I get on various searches.

My problem was, that no asynchronous requests like websockets would work and the webserver would tell me that I need to enable async support for all filters and the servlet. (For websockets I got to see this message only on the network tab in the browser dev tools when issuing the very first call to the website after restart)

I found that the following filters need to be configured for async support in your applications web.xml. EasyAuth might only be necessary, when you configure Authentication for the webservice.

<filter>
<filter-name>EasyAuthFilter</filter-name>
<filter-class>com.microsoft.azure.appservice.EasyAuthFilter</filter-class>
<async-supported>true</async-supported>
</filter>

<filter>
<filter-name>AppServiceFilter</filter-name>
<filter-class>com.microsoft.azure.appservice.filters.AppServiceFilter</filter-class>
<async-supported>true</async-supported>
</filter>

These filters are not obvious as they are added by Microsoft in the web.xml located in the installation directory of the tomcat server, but lacking the <async-supported> tags. you can check the web.xml in the installation folder using kudu ssh and navigate to /usr/local/tomcat/config. As you can not change the file in the installation directory (it will be overridden when the application is restarted) you need to configure async support for these filters in your applications web.xml instead.

0
votes

Please try to refer to the doc section Application Configuration Examples for Tomcat in the web.config and add -Dorg.apache.tomcat.websocket.DISABLE_BUILTIN_EXTENSIONS=true in the Tomcat startup options.