Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
725 views
in Technique[技术] by (71.8m points)

jakarta ee - Will javax.servlet.Filter intercept Websocket messages? (Java Servlet API)

When I have a websocket connection, say at "/ws"

Will a regular javax.servlet.Filter on the "/ws" path intercept each message as a regular http request? Will it intercept only the first request (as part of the handshake?)

If no, then, how can I make such a filter for websocket messages?

I don't find any specifics about that in the spec.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

No, Servlet Filter won't catch WebSocket messages.

Servlet does not support WebSocket protocol at all. Only thing you can do is to register HttpUpgradeHandler (see HttpServletRequest#upgrade)and then implement WebSocket protocol on top of that.

Or.. if you want to save some time, take a look at JSR 356 and the implementations, they are working on top of this API. I personally work on Tyrus, which is the reference implementation of JSR 356. (It is part of Java EE 7, but you only need Servlet 3.1 API).


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...