0%

依赖

<dependency>
    <groupId>org.java-websocket</groupId>
    <artifactId>Java-WebSocket</artifactId>
    <version>1.5.2</version>
</dependency>

代码

@Test
public void testWssWithWebSocketServer() throws Exception {
    TrustManager trustManager = new X509ExtendedTrustManager() {
        @Override
        public void checkClientTrusted(X509Certificate[] chain, String authType, Socket socket) throws CertificateException {

        }

        @Override
        public void checkServerTrusted(X509Certificate[] chain, String authType, Socket socket) throws CertificateException {

        }

        @Override
        public void checkClientTrusted(X509Certificate[] chain, String authType, SSLEngine engine) throws CertificateException {

        }

        @Override
        public void checkServerTrusted(X509Certificate[] chain, String authType, SSLEngine engine) throws CertificateException {

        }

        @Override
        public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException {

        }

        @Override
        public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException {

        }

        @Override
        public X509Certificate[] getAcceptedIssuers() {
            return new X509Certificate[]{};
        }
    };
    SSLContext sslContext = SSLContext.getInstance("TLS");
    sslContext.init(null, new TrustManager[]{trustManager}, null);

    URI uri = URI.create("wss://127.0.0.1:8443/websocket");
    SSLSocketFactory socketFactory = sslContext.getSocketFactory();
    WebSocketClient webSocketClient = new WebSocketClient(uri) {
        @Override
        public void onOpen(ServerHandshake serverHandshake) {
            logger.info("onOpen");
        }

        @Override
        public void onMessage(String s) {
            logger.info("onMessage: " + s);
        }

        @Override
        public void onClose(int i, String s, boolean b) {
            logger.info("onClose");
        }

        @Override
        public void onError(Exception e) {
            logger.info("onError: " + e.getMessage(), e);
        }
    };
    webSocketClient.setSocketFactory(socketFactory);
    webSocketClient.connectBlocking();
    SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
    webSocketClient.send(simpleDateFormat.format(new Date()));
    webSocketClient.closeBlocking();
}

main.bundle.js:20686 Mixed Content: The page at 'https://***' was loaded over HTTPS, but attempted to connect to the insecure WebSocket endpoint 'ws://***/websocket/***'. This request has been blocked; this endpoint must be available over WSS.
Uncaught (in promise) DOMException: Failed to construct 'WebSocket': An insecure WebSocket connection may not be initiated from a page loaded over HTTPS.

https://blog.csdn.net/u012977315/article/details/84944708

在使用 Element UI 时,发现有时候可以在控制台利用内置的类来改变节点元素样式,但是当数据一多就无法利用了(即,无效利用),并且,在无效后在其上添加会发现,添加的样式处于所需要绑定的上层,故又无效。

阅读全文 »