Afternoon everyone. I'm having an issue with sockjs and Spring4. I don't know which side of the setup is causing the issue. The problem is I can't seem to get IE8 to open a connection to my Spring backend over HTTPS.
I'm trying to implament this example:
https://demo.rasc.ch/spring4ws/ The link I'm trying is the chat.
The link to his source is here:
https://github.com/ralscha/spring4ws-demosThe only change I made to his source is I'm using jquery-1.9.1 , Spring 4.0.0, and the full stomp.js and not the stomp.min.js
The sock and stomp code in the index page for the chat client is:
$(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();
});
Sorry about the formatting.
In Spring all I did was separate the the webconfig java file into 2 files
WebConfig is standard. Extends WebMvcConfigurerAdapter :
@Override
public void addViewControllers(ViewControllerRegistry registry) {
registry.addViewController("/").setViewName("index.html");
}
@Override
public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) {
configurer.enable();
}
WebSocket implaments 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);
}
The initilizer is basic too.
@Override
protected Class<?>[] getServletConfigClasses() {
return new Class<?>[] { WebConfig.class, WebSocketConfig.class };
}
@Override
protected String[] getServletMappings() {
return new String[] { "/chatdemo/*" };
}
I'm also running this through Tomcat 7 using eclipse. So not the embedded tomcat.
The problem I'm having is the readystate inside sock is being set to permanent in IE. I don't fully understand xhr/xdr polling, but I'm assuming that's the problem.
Is there anything else I need to do to get IE to work over https on the sockjs side or the spring side?