Websocket examples on Google Cloud do not work with a fresh installation of bitnami Tomcat

Keywords: Tomcat - Google Cloud Platform - Technical issue - Other
Deploy Bitnami Tomcat into Google. Try out the provided examples. The websocket connections all fail to connect

It appears that this is caused by the AJP connector.
I am proxying calls to the ws endpoint. Tomcat throws this error

java.lang.UnsupportedOperationException: HTTP upgrade is not supported by the AJP protocol
at org.apache.coyote.ajp.AbstractAjpProcessor.action(AbstractAjpProcessor.java:587)
at org.apache.coyote.Request.action(Request.java:379)
at org.apache.catalina.connector.Request.upgrade(Request.java:1886)
at org.apache.catalina.connector.RequestFacade.upgrade(RequestFacade.java:1114)
at org.apache.tomcat.websocket.server.UpgradeUtil.doUpgrade(UpgradeUtil.java:231)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:77)

And I am now looking into tomcat’s server.xml for connector configuration

Hi @mkujap,

A colleague will contact you soon to help you with this issue.l


Michiel D’Hont

Great, thanks. As far as I understand the tomcat.conf and its LocationMatch the existing definition is an exclusion of paths (i.e. when path does not include server-status or phpmyadmin) that are not ProxyPassed to ajp.

Thus in my case I added

<LocationMatch “^/(?!((server-status|phpmyadmin|<path/with websocket endpoint>)([^a-zA-Z0-9]|$))).*$”>
ProxyPass ajp://localhost:8009

<LocationMatch “^/<path/with websocket endpoint>.*$”>
ProxyPass ws://localhost:8080

but of course these do not make the examples to work. If you would like to have the examples work, wouldn’t you need to add the websocket endpoints into the “exclusion” and then proxypass those to ws://localhost…



I found a way to make it work. Indeed, ajp is not compatible with WebSockets, so I edited /opt/bitnami/apache-tomcat/conf/server.xml and uncommented one of the HTTP connectors (in my case, with port 8080.

    <Connector port="8080" URIEncoding="UTF-8" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443"/>

Then, in /opt/bitnami/apache-tomcat/conf/tomcat.conf, I set the conf like this:

<LocationMatch "^/(?!((server-status|phpmyadmin)([^a-zA-Z0-9]|$))).*$">
  ProxyPass ajp://localhost:8009

<LocationMatch "^/examples/websocket/.*$">
  ProxyPass ws://localhost:8080

<LocationMatch "^/examples/websocket/.*xhtml$">
  ProxyPass ajp://localhost:8009

Then, I restarted the server services:

sudo /opt/bitnami/ctlscript.sh restart

And with that the websocket examples are working

Hope it helps

Best regards,

Javier J. Salmerón

Was my answer helpful? Click on :heart:

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.