WebSockets through Apache and Tomcat: HTTP upgrade is not supported by the AJP protocol
Asked Answered
D

1

9

I am developing with WebSockets, and made a working web application running on Tomcat 8. However, when testing with Apache 2 in front of it, the client is getting an HTTP 500 and the Tomcat log says:

 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)

This worked when accessing Tomcat directly through its HTTP connector. If this is not supported with AJP, is there a workaround?

Dottie answered 5/6, 2015 at 13:11 Comment(0)
D
4

Use Apache module mod_proxy_wstunnel:

sudo a2enmod mod_proxy_wstunnel

Then use it to let WebSocket connections through by adding this to apache.conf:

ProxyPass "/ws2/"  "ws://localhost:8180/ws"

And make sure you have enabled an HTTP connector in Tomcat by using...

<Connector protocol="HTTP/1.1" port="8180" ...>

...in server.xml.

Dottie answered 8/10, 2015 at 3:50 Comment(1)
It is sudo a2enmod proxy_wstunnel, without "mod_", in apache 2.4.7Thread

© 2022 - 2024 — McMap. All rights reserved.