FileNotFoundException:cert \ jssecacerts和sessionId = 0

时间:2018-10-17 02:15:43

标签: spring spring-boot spring-websocket

我正在尝试通过websocket连接到我们的服务器。我在IDE中运行时能够获得会话。但是,会话ID为0。
另外,当我使用java -jar进行编译和运行时,出现以下错误。在IDE中运行时,由于将工作目录设置为cert文件夹所在的src / main / resources,所以没有收到此错误:

java.io.FileNotFoundException: cert\jssecacerts (The system cannot find the path specified)
    ...
    at org.apache.tomcat.websocket.WsWebSocketContainer.createSSLEnginer(WsWebSocketContainer.java:893)

请告知。

    WebSocketClient client = new StandardWebSocketClient();
    WebSocketHandler handler = new TextWebSocketHandler();
    WebSocketHttpHeaders headers = new WebSocketHttpHeaders();
    headers.add("Authorization", "Bearer " + getSignedToken());
    URI uri = new URI("wss://<some server>");
    ((StandardWebSocketClient) client).getUserProperties().put(Constants.SSL_TRUSTSTORE_PROPERTY, "cert/jssecacerts");
    ((StandardWebSocketClient) client).getUserProperties().put(Constants.SSL_TRUSTSTORE_PWD_PROPERTY, Constants.SSL_TRUSTSTORE_PWD_DEFAULT);
    WebSocketSession session = client.doHandshake(handler, headers, uri).get();

1 个答案:

答案 0 :(得分:0)

关于文件未找到,我知道了。

Resource resource = new ClassPathResource("cert/jssecacerts");
...
((StandardWebSocketClient) client).getUserProperties().put(Constants.SSL_TRUSTSTORE_PROPERTY, resource.getFile().getAbsolutePath());