angularjs - Transport error in WebSocketServerSockJsSession - Cannot load platform configurator on a Spring Stomp websocket -
i'm trying add web sockets angularjs application.
i set web socket using spring 4 on server , stomp sockjs on client.
i access page @ http://localhost:9000/#/project/1/bts
after grunt serve
command.
but 500 response when doing web socket handshake:
websocket connection 'ws://localhost:8080/nitro-project-rest/api/socket/bts/405/bmtcztq4/websocket' failed: error during websocket handshake: unexpected response code: 500
the server has upon each failed websocket request:
severe: servlet.service() servlet [nitro] in context path [/nitro-project-rest] threw exception [request processing failed; nested exception org.springframework.web.socket.sockjs.sockjsexception: uncaught failure in sockjs request, uri=http://localhost:8080/nitro-project-rest/api/socket/bts/970/2xoe6kls/websocket; nested exception org.springframework.web.socket.sockjs.sockjstransportfailureexception: websocket handshake failure; nested exception java.lang.runtimeexception: cannot load platform configurator] root cause java.lang.runtimeexception: cannot load platform configurator
more on error:
2017-02-06 10:36:04,241 debug [http-bio-8080-exec-10] o.s.w.s.h.loggingwebsockethandlerdecorator transport error in websocketserversockjssession[id=nqj286ob] java.lang.runtimeexception: cannot load platform configurator @ javax.websocket.server.serverendpointconfig$configurator.fetchcontainerdefaultconfigurator(serverendpointconfig.java:123) @ javax.websocket.server.serverendpointconfig$configurator.getcontainerdefaultconfigurator(serverendpointconfig.java:128) @ javax.websocket.server.serverendpointconfig$configurator.checkorigin(serverendpointconfig.java:192)
the funny thing push notification works fine. can see webpage being updated live when expected event occurs. websocket works fine, in spite of exception. exception occurs @ page load time.
when manually type url:
http://localhost:8080/nitro-project-rest/api/socket/bts
in chromium web browser displays: welcome sockjs!
here web socket connection service:
function stompservice(endpoint) { this.stompclient = stomp.client(env.nitro_project_ws_url + '/socket/' + endpoint); } stompservice.prototype.connect = function(onconnect, onerror) { this.stompclient.connect({}, function(frame) { $rootscope.$apply(function() { onconnect.apply(stompclient, frame); }); }, function(frame) { $rootscope.$apply(function() { onerror.apply(stompclient, frame); }); }, '/'); };
and controller:
var stomp = new socketservice(bts_ws_endpoint); stomp.connect(function() { $scope.client.subscribe('status', function(message) { $scope.messages.push(message.body); }); }, function() { });
with server side configuration , controller:
@configuration @enablewebsocketmessagebroker @componentscan(basepackages = "com.nsn.nitro.project.rest.socket") public class websocketconfiguration extends abstractwebsocketmessagebrokerconfigurer { @override public void configuremessagebroker(messagebrokerregistry config) { // prefix destinations towards server config.setapplicationdestinationprefixes("/app"); // prefix destinations towards client config.enablesimplebroker("/topic"); } @override public void registerstompendpoints(stompendpointregistry registry) { // controllers need added endpoint registry registry.addendpoint("/socket/bts").withsockjs(); } @override public void configureclientinboundchannel(channelregistration registration) { } @override public void configureclientoutboundchannel(channelregistration registration) { registration.taskexecutor().corepoolsize(4).maxpoolsize(10); } } @controller public class btssocketcontroller { private static logger logger = loggerfactory.getlogger(btssocketcontroller.class); @messagemapping("/socket/bts") @sendto("/topic/status") public btsmessage status(btsmessage message) throws exception { logger.debug("==========>> received message " + message.getbtsid()); message.setstatus(btsstatus.onair); return message; } }
i'm running spring security basic authentication , following configuration:
@override protected void configure(httpsecurity http) throws exception { http.addfilterbefore(simplecorsfilter, channelprocessingfilter.class); http .csrf().disable().sessionmanagement().sessioncreationpolicy(sessioncreationpolicy.stateless) .and().httpbasic().authenticationentrypoint(restauthenticationentrypoint) .and().authorizerequests().antmatchers("/socket/**").permitall() .and().authorizerequests().antmatchers("/resources/**").permitall() .and().authorizerequests().antmatchers(restconstants.slash + restconstants.admins + restconstants.slash + restconstants.login).permitall() .and().authorizerequests().antmatchers("/**").hasrole("admin").anyrequest().authenticated(); } @component public class simplecorsfilter implements filter { private static final string origin = "origin"; private static final string options = "options"; private static final string ok = "ok"; public void dofilter(servletrequest servletrequest, servletresponse servletresponse, filterchain filterchain) throws ioexception, servletexception { httpservletrequest httpservletrequest = (httpservletrequest) servletrequest; httpservletresponse httpservletresponse = (httpservletresponse) servletresponse; if (httpservletrequest.getheader(origin) != null) { string origin = httpservletrequest.getheader(origin); httpservletresponse.setheader("access-control-allow-origin", origin); httpservletresponse.setheader("access-control-allow-methods", "post, put, get, options, delete"); httpservletresponse.setheader("access-control-max-age", "3600"); httpservletresponse.setheader("access-control-allow-headers", "accept-language,content-type,x-requested-with,accept,origin,access-control-request-method,access-control-request-headers,authorization,x-filename,content-disposition,content-length"); // allow more 6 default headers returned, content length required download file request file size httpservletresponse.setheader("access-control-expose-headers", "accept-language,content-type,x-requested-with,accept,origin,access-control-request-method,access-control-request-headers,authorization,x-filename,content-disposition,content-length"); } if (httpservletrequest.getmethod().equals(options)) { try { httpservletresponse.getwriter().print(ok); httpservletresponse.getwriter().flush(); } catch (ioexception e) { e.printstacktrace(); } } else { filterchain.dofilter(servletrequest, servletresponse); } } public void init(filterconfig filterconfig) { } public void destroy() { } }
my java dependencies are:
[info] +- javax.websocket:javax.websocket-api:jar:1.1:provided [info] +- org.springframework:spring-web:jar:4.3.6.release:compile [info] +- org.springframework:spring-webmvc:jar:4.3.6.release:compile [info] +- org.springframework:spring-test:jar:4.3.6.release:compile [info] +- org.springframework:spring-messaging:jar:4.3.6.release:compile [info] +- org.springframework:spring-websocket:jar:4.3.6.release:compile
my js dependencies are:
"sockjs": "~0.3.4", "stomp-websocket": "~2.3.4",
to else stumbles across while searching "welcome sockjs" error: if trying connect sockjs address using regular websocket connection, add /websocket end of url.
Comments
Post a Comment