Java Websocket:Jakrata.Websocket Interceptor

发布于 2025-01-24 04:07:38 字数 714 浏览 2 评论 0原文

我想丰富(或使用其他方式)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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文