slimsim Posted October 21, 2020 Posted October 21, 2020 (edited) Hi I'm trying to send data from my Java Spring Boot backend to my frontend using webSockets StompJS.But I'm gettign the followign error in the browser console: WebSocket connection to 'ws://slimsim.heliohost.org/slimsim_ava/gs-guide-websocket/015/sxvos2r2/websocket' failed: Error during WebSocket handshake: Unexpected response code: 400Is it possible to get the server-logs? This request was made at about 2020-10-21 14:16:45. My info:Username: slimsimWAR-file: slimsim_ava.warPath: /home/slimsim/Server: johnny I have read a lot on this forum, but I can't seem to find any one who have used Stomp. It works on my locahost as well as on my last web hosting server. Does anybody have any tips? My JavaScript code is the following: connect = function() { const funk = "connect"; console.log("\n\n\n\n" + funk + ":\n"); const socketPath = thymeLeaf.contextPath + 'gs-guide-websocket'; console.log( "*** " + funk + ": socketPath", socketPath ); var socket = new SockJS( socketPath ); console.log( "*** " + funk + ": socket", socket ); stompClient = Stomp.over(socket); console.log( "*** " + funk + ": stompClient", stompClient ); stompClient.connect({}, function (frame) { // It never gets to here.... console.log( "*** " + funk + ": connected!" ); }); } And my WebSocketConfig.java file is the following: import com.slimsimapps.ava.badlog.BadLogService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Configuration; import org.springframework.messaging.simp.config.MessageBrokerRegistry; import org.springframework.web.socket.config.annotation.EnableWebSocketMessageBroker; import org.springframework.web.socket.config.annotation.StompEndpointRegistry; import org.springframework.web.socket.config.annotation.WebSocketMessageBrokerConfigurer; import org.springframework.web.socket.server.standard.TomcatRequestUpgradeStrategy; import org.springframework.web.socket.server.support.DefaultHandshakeHandler; @Configuration @EnableWebSocketMessageBroker public class WebSocketConfig implements WebSocketMessageBrokerConfigurer { @Autowired BadLogService log; @Override public void configureMessageBroker(MessageBrokerRegistry config) { log.a(config); config.enableSimpleBroker("/topic"); config.setApplicationDestinationPrefixes("/app"); log.o(config); } @Override public void registerStompEndpoints(StompEndpointRegistry registry) { log.a(registry); //registry.addEndpoint("/gs-guide-websocket").withSockJS(); registry.addEndpoint("/gs-guide-websocket") .setHandshakeHandler(new DefaultHandshakeHandler(new TomcatRequestUpgradeStrategy())) //.setAllowedOrigins( "slimsim.heliohost.org" ) .setAllowedOrigins( "*" ) .withSockJS(); log.o(registry); } } Thanks so much for any help! Edited October 21, 2020 by slimsim
Krydos Posted October 22, 2020 Posted October 22, 2020 21-Oct-2020 14:13:59.360 INFO [localhost-startStop-9] org.apache.catalina.startup.HostConfig.deployWAR Deployment of web application archive [/opt/tomcat/apache-tomcat-8.5.24/webapps/slimsim_ava.war] has finished in [33,771] ms 2020-10-21 14:14:54.920 INFO 16719 --- [MessageBroker-1] o.s.w.s.c.WebSocketMessageBrokerStats : WebSocketSession[0 current WS(0)-HttpStream(0)-HttpPoll(0), 0 total, 0 closed abnormally (0 connect failure, 0 send limit, 0 transport error)], stompSubProtocol[processed CONNECT(0)-CONNECTED(0)-DISCONNECT(0)], stompBrokerRelay[null], inboundChannel[pool size = 0, active threads = 0, queued tasks = 0, completed tasks = 0], outboundChannel[pool size = 0, active threads = 0, queued tasks = 0, completed tasks = 0], sockJsScheduler[pool size = 1, active threads = 1, queued tasks = 0, completed tasks = 0] 2020-10-21 14:16:29.615 INFO 16719 --- [io-8080-exec-90] o.s.web.servlet.DispatcherServlet : Initializing Servlet 'dispatcherServlet' 2020-10-21 14:16:29.655 INFO 16719 --- [io-8080-exec-90] o.s.web.servlet.DispatcherServlet : Completed initialization in 40 ms 2020-10-21 14:16:47.324 ERROR 16719 --- [io-8080-exec-83] o.s.w.s.s.s.DefaultHandshakeHandler : Handshake failed due to invalid Upgrade header: null
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now