gpt4 book ai didi

ssl - 尝试将 websocket 连接到安全的客户端端点会引发错误 : XNIO000100: 'https' URL scheme chosen but no SSL provider given

转载 作者:太空宇宙 更新时间:2023-11-03 14:32:24 24 4
gpt4 key购买 nike

我正在尝试在 java 中创建一个 websocket,它监听端点 f.ex 上的本地应用程序。 “wss://localhost.localapp.com:8080/”。

应用程序确实通过该 websocket 发送有关正在发生的事情的信息。

当我运行 web 应用程序并尝试连接到安全的 websocket 时,它会抛出此错误:

XNIO000100: 'https' URL scheme chosen but no SSL provider given

这是我连接到客户端端点的代码:

@ClientEndpoint
public class ClientEndpoint {

private Logger logger = Logger.getLogger(getClass().getName());

public ClientEndpoint() {
WebSocketContainer container = ContainerProvider.getWebSocketContainer();
try {
container.connectToServer(this, new URI("wss://localhost.localapp.com:8080/"));
} catch (DeploymentException | URISyntaxException | InterruptedException | IOException e) {
System.out.println("Connection error occured!: " + e);
}
}

@OnOpen
public void onOpen(Session session) {
this.logger.info("New websocket session opened: " + session.getId());
}

@OnClose
public void onClose(Session session) {
this.logger.info("Websoket session closed: " + session.getId());
}

@OnMessage
public void onMessage(Session session, String message) throws IOException, EncodeException {
this.logger.info("Message recieved: " + message);
}

@OnError
public void error(Session session, Throwable t) {
t.printStackTrace();
}
}

所以错误发生在这行代码上:

container.connectToServer(this, new URI("wss://localhost.localapp.com:8080/"));

堆栈跟踪输出如下:

ERROR localhost jboss7.1 [RunnerReadFacade] Application was stopped due to exception. Transaction is rollbacked.: java.lang.IllegalArgumentException: XNIO000100: 'https' URL scheme chosen but no SSL provider given
at org.xnio.http.HttpUpgrade$HttpUpgradeState.doUpgrade(HttpUpgrade.java:253)
at org.xnio.http.HttpUpgrade$HttpUpgradeState.access$100(HttpUpgrade.java:165)
at org.xnio.http.HttpUpgrade.performUpgrade(HttpUpgrade.java:129)
at io.undertow.websockets.client.WebSocketClient$ConnectionBuilder.connectImpl(WebSocketClient.java:323)
at io.undertow.websockets.client.WebSocketClient$ConnectionBuilder.connect(WebSocketClient.java:211)
at io.undertow.websockets.jsr.ServerWebSocketContainer.connectToServerInternal(ServerWebSocketContainer.java:463)
at io.undertow.websockets.jsr.ServerWebSocketContainer.connectToServerInternal(ServerWebSocketContainer.java:457)
at io.undertow.websockets.jsr.ServerWebSocketContainer.connectToServer(ServerWebSocketContainer.java:211)

我该如何解决?

使用 JavaScript,我不需要 SSL 提供程序,只需运行即可简单地创建与 websocket 的连接:

websocket = new WebSocket("wss://localhost.localapp.com:8080/");

为什么只有Java会报错?

更新:

这可能无法完成,因为应用程序在您的本地计算机上,而服务器不在本地。

但是,如果您使用本地服务器,可以做到这一点吗?

最佳答案

您可以切换到程序化客户端端点或定义线程本地 SSL 上下文。查看详情 https://issues.jboss.org/browse/THORN-2131 (wsstest-master.zip 包括演示应用程序)。 “实现 io.undertow.websockets.jsr.WebsocketClientSslProvider 并添加 META-INF/services 条目”对我不起作用。

关于ssl - 尝试将 websocket 连接到安全的客户端端点会引发错误 : XNIO000100: 'https' URL scheme chosen but no SSL provider given,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51536218/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com