大家下午。我遇到了 sockjs 和 Spring4 的问题。我不知道设置的哪一侧导致了问题。问题是我似乎无法让 IE8 通过 HTTPS 打开与我的 Spring 后端的连接。
我正在尝试实施此示例:https ://demo.rasc.ch/spring4ws/ 我正在尝试的链接是聊天。他的来源链接在这里:https ://github.com/ralscha/spring4ws-demos
我对他的源代码所做的唯一更改是我使用的是 jquery-1.9.1、Spring 4.0.0 和完整的 stomp.js 而不是 stomp.min.js
聊天客户端的索引页中的 sock 和 stomp 代码为: $(function() { var username, lastUsername, stompClient, content = $("#content")[0], input = $("#editor input" )[0];
function notify(text) {
$('<p class="message notice"/>').text(text).appendTo(content);
content.scrollTop = content.scrollHeight;
}
$(input).keyup(function(event) {
if (event.which === 13 && $.trim(input.value)) {
if (!username) {
username = input.value;
$("#editor p").addClass("user").removeClass("guide").text(username);
var path = window.location.pathname.substring(0,
window.location.pathname.lastIndexOf('/')+1);
var sock = new SockJS(path + 'chat');
stompClient = Stomp.over(sock);
stompClient.connect({}, function(frame) {
notify("The connection has been opened");
$(input).removeAttr("disabled").focus();
stompClient.subscribe("/queue/chatmessage", function(msg) {
var data = JSON.parse(msg.body);
if (lastUsername !== data.username) {
lastUsername = data.username;
$('<p class="user"/>').text(data.username).appendTo(content);
}
$('<p class="message"/>').text(data.message).appendTo(content);
content.scrollTop = content.scrollHeight;
});
},
function(error) {
notify("An error occured: " + error);
$(input).attr("disabled", "disabled");
});
} else {
stompClient.send("/queue/chatmessage", {}, JSON.stringify({username: username, message: input.value}));
}
input.value = "";
}
});
$(input).focus();
$(window).resize(function() {
$(content).height($(window).height() - $("#editor").outerHeight(true) - 15).scrollTop(content.scrollHeight);
}).resize();
});
对不起格式。
在 Spring 中,我所做的只是将 webconfig java 文件分成 2 个文件
WebConfig 是标准的。扩展 WebMvcConfigurerAdapter :
@Override
public void addViewControllers(ViewControllerRegistry registry) {
registry.addViewController("/").setViewName("index.html");
}
@Override
public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) {
configurer.enable();
}
WebSocket 实现 WebSocketMessageBrokerConfigurer:
@Override
public void registerStompEndpoints(StompEndpointRegistry registry) {
registry.addEndpoint("/chat").withSockJS().setSessionCookieNeeded(false);
}
@Override
public void configureMessageBroker(MessageBrokerRegistry registry) {
registry.enableSimpleBroker("/queue/");
}
@Override
public void configureClientInboundChannel(ChannelRegistration registration) {
// use default thread pool with 1 thread
}
@Override
public void configureClientOutboundChannel(ChannelRegistration registration) {
registration.taskExecutor().corePoolSize(2).maxPoolSize(3);
}
初始化器也是基本的。
@Override
protected Class<?>[] getServletConfigClasses() {
return new Class<?>[] { WebConfig.class, WebSocketConfig.class };
}
@Override
protected String[] getServletMappings() {
return new String[] { "/chatdemo/*" };
}
我也在使用 Eclipse 通过 Tomcat 7 运行它。所以不是嵌入式tomcat。
我遇到的问题是 sock 中的 readystate 在 IE 中被设置为永久状态。我不完全理解 xhr/xdr 轮询,但我假设这就是问题所在。
我还需要做什么才能让 IE 在 sockjs 端或 spring 端通过 https 工作?