How Tomcat 8 Handles websocket upgrade request

无人久伴 提交于 2019-12-04 06:44:29

问题


I want to understand handling of websocket upgrade request in tomcat ? Is it done via filters or servlets ? How the ws upgrade request is handled by TOmcat-8.

Thanks,
Anuj


回答1:


Tomcat uses a filter to look for the HTTP upgrade request that starts a WebSocket connection and passes it the the appropriate handler if it sees one.

The Filter is configured using a ServletContainerInitializer. The location of the Filter will depend on what other Filters are configured by the web application and where the web application places them in the FilterChain. It is possible, for example, that a web application would wish to place a security filter before the Web Socket filter and Tomcat allows this.




回答2:


WebSockets are a completely different protocol. They are not handled by filters or servlets but instead by EndPoints. To create them you use to extend the endpoint class but, like everything else in Java EE, you can now use annotations. For more info check out the latest doc Java API for WebSockets

To create them on the client side the request starts in HTTP, perhaps in JavaScript, but on Tomcat the endpoint is listening, not your normal servlets.



来源:https://stackoverflow.com/questions/26103939/how-tomcat-8-handles-websocket-upgrade-request

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!