ssl - JSF websocket url 在 ssl 端口上不起作用
问题描述
我正在使用它创建一个 jsf 聊天应用程序,当我在我的 jsf 应用程序中使用 http时它工作正常,但当我在我的 jsf 应用程序中使用 https 时失败。我已经按照这个创建了一个 websocket,它在运行在端口 8080 上的 tomcat 上运行良好,但是当我在 tomcat ssl 端口 8443 上运行我的 jsf 应用程序时,我收到了这个错误。
这是我正在使用的java代码
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import javax.websocket.OnClose;
import javax.websocket.OnOpen;
import javax.websocket.Session;
import javax.websocket.server.ServerEndpoint;
@ServerEndpoint("/push")
public class PushNofity {
private static final Set<Session> SESSIONS = ConcurrentHashMap.newKeySet();
@OnOpen
public void onOpen(Session session) {
SESSIONS.add(session);
}
@OnClose
public void onClose(Session session) {
SESSIONS.remove(session);
}
public static void sendAll(String text) {
System.out.println("on session:" + text);
synchronized (SESSIONS) {
for (Session session : SESSIONS) {
if (session.isOpen()) {
session.getAsyncRemote().sendText(text);
}
}
}
}
}
@ManagedBean(name = "ch")
@SessionScoped
@Getter
@Setter
public class ChatManagedBean {
StompClient stompSocket;
@PostConstruct
public void inIt()
{
stompSocket = new StompClient(URI.create("ws://127.0.0.1:8080/SpringBootWebsocktAPI/ws"));
try {
//stompSocket.setSocketFactory(getSslFactory());
connected = stompSocket.connectBlocking();
} catch (InterruptedException e) {
e.printStackTrace();
return;
}
if (!connected) {
System.out.println("Failed to connect to the socket");
return;
}
stompSocket.subscribe("/user/" + USER_ID + "/queue/messages", new StompMessageListener() {
@Override
public void onMessage(StompFrame stompFrame) {
ChatMessage chatMessage = gson.fromJson(stompFrame.getBody().trim(), ChatMessage.class);
PushNofity.sendAll(chatMessage.getMessage());//this works fine when my jsf url is running on port 8080
}
});
}
}
和我的 xhtml 代码
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:p="http://primefaces.org/ui"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
xmlns:c="http://xmlns.jcp.org/jsp/jstl/core">
<h:head>
<title>JSF Chat</title>
<h:outputStylesheet library="css" name="style.css"/>
<script type="text/javascript">
if (window.WebSocket) {
var ws = new WebSocket("wss://localhost:8443/JsChatApp/push");//does not work when my jsf url is running on port 8443
//var ws = new WebSocket("ws://localhost:8080/JsChatApp/push"); this work fine
}
ws.onmessage = function () {
console.log("helo");
updateChat();
};
// }
$("#chat_panel").animate({scrollTop: 500}, 1000);
function autoScroll() {
chatWindow = document.getElementById('chat_panel');
var xH = chatWindow.scrollHeight;
chatWindow.scrollTo(0, xH);
}
</script>
<style>
*{
margin: 0px;
padding: 0px;
}
</style>
</h:head>
<h:body>
<h:form>
<p:remoteCommand oncomplete="autoScroll();" name="updateChat" process="@this" update="chat_panel" />
</h:form>
<p:outputPanel id="chat_panel" styleClass="chat-container" style="height: 440px;overflow-y: scroll;overflow-x: hidden;margin-bottom: 10px;" >
<ui:repeat value="#{ch.messages}" var="t" id="tbl" class="chat_div" varStatus="myVarStatus">
<div class="row no-guttersp" style="margin-left: 0px;">
<div class="#{ch.alternateChat(t.senderId)}">
#{t.message}
<br></br>
<span>
#{t.chatDate}
</span>
</div>
</div>
</ui:repeat>
</p:outputPanel>
</h:body>
</html>
我在用;
- 素面 8.0
- JSF 2.2
- 雄猫 8.0.24
解决方案
推荐阅读
- css - Bootstrap 4如何在不超出空间的情况下在列之间设置边距
- javascript - Kendo:上下文主菜单的方向属性
- python - Python COM 互操作 - 工厂模式
- shell - 在无头 RPi 零 W 上启用 WiFi 热点
- functional-programming - 带 Ramdajs 的无点管道范围
- python - 检索 Azure Active Directory 和本地帐户的数据
- c# - 您如何输入 TextBox 并将其返回到 TextBlock
- vue.js - [Vue 警告]:属性或方法“任务”未在实例上定义,但在渲染期间被引用
- r - 从 R 中的远程时间服务器获取时间
- javascript - 如何使用是或否选项添加对话框并基于该选项调用函数