Java Websocket:Jakrata.Websocket Interceptor
我想丰富(或使用其他方式)clientendpointConfig.configurator jakarta.websocket。
Tyrus 作为实现
public class WebsocketClientEndpointConfigurator extends ClientEndpointConfig.Configurator {
private MyCreds credential;
public WebsocketClientEndpointConfigurator(MyCreds credential) {
this.credential = credential;
}
@Override
public void beforeRequest(Map<String, List<String>> headers) {
try {
credential.intercept(null);
} catch (IOException e) {
e.printStackTrace();
}
headers.put(AUTHORIZATION, Arrays.asList(credential.getAccessToken()));
}
}
我正在使用服务器。
怎么可能?
I want to enrich (or use other way) the ClientEndpointConfig.Configurator of jakarta.websocket.
I'm using tyrus
as the implementation and I have something like:
public class WebsocketClientEndpointConfigurator extends ClientEndpointConfig.Configurator {
private MyCreds credential;
public WebsocketClientEndpointConfigurator(MyCreds credential) {
this.credential = credential;
}
@Override
public void beforeRequest(Map<String, List<String>> headers) {
try {
credential.intercept(null);
} catch (IOException e) {
e.printStackTrace();
}
headers.put(AUTHORIZATION, Arrays.asList(credential.getAccessToken()));
}
}
It's seems that the beforeRequest
called only once, I would like that it will be execute before each message sends to the server.
How is it possible?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论