How can I programmatically enable WSS for a Tyrus WebSocket @ServerEndpoint

巧了我就是萌 提交于 2019-12-11 02:54:28

问题


I have a microservice that has a REST endpoint and a WebSocket endpoint.

It Spring-wires Grizzly and Tyrus, and adds in authentication via SSO using a JAX-RS filter and a ServerEndpointConfig.Configurator. I've added in SSL to the REST endpoint using SSLContextConfigurator and SSLEngineConfigurator and a (currently) self-signed certificate.

I don't see a way to do the same for org.glassfish.tyrus.server.Server in Tyrus 1.14.

In fact, the code hardwires the protocol name, which makes me wonder if this is even possible:

LOGGER.info("WebSocket Registered apps: URLs all start with ws://" + this.hostName + ":" + this.getPort());

There's a similar question here but it requires deploying a WAR file to a full-on Glassfish instance. I want to do this programmatically.


回答1:


Solved using the suggestion at https://stackoverflow.com/a/27239122/17641

listener = new NetworkListener("grizzly", "0.0.0.0", port); listener.setSecure(true); listener.setSSLEngineConfig(new SSLEngineConfigurator(getSslContextConfigurator()).setClientMode(false).setNeedClientAuth(false));

Where getSslContextConfigurator constructs a org.glassfish.grizzly.ssl.SSLContextConfigurator with a keystore byte[] and password.



来源:https://stackoverflow.com/questions/53849572/how-can-i-programmatically-enable-wss-for-a-tyrus-websocket-serverendpoint

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