0%
Java 连接 WebSocket 服务忽略证书校验
依赖
<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 自定义 CSS 覆盖原生
在使用 Element UI 时,发现有时候可以在控制台利用内置的类来改变节点元素样式,但是当数据一多就无法利用了(即,无效利用),并且,在无效后在其上添加会发现,添加的样式处于所需要绑定的上层,故又无效。
页面跳转报错 This request has been blocked; the content must be served over HTTPS
JS 报错:
This request has been blocked; the content must be served over HTTPS
ElasticSearch 聚合查询 TermsAggregationBuilder 使用汇总
整理一些 ElasticSearch 聚合查询的常用操作。