stomp - Spring Websocket url hits RequestMapping but not MessageMapping -
i'm having trouble setting websocket configuration in existing web application.
@configuration @enablewebsocketmessagebroker public class websocketconfig extends abstractwebsocketmessagebrokerconfigurer{ @override public void configuremessagebroker(messagebrokerregistry config) { config.enablesimplebroker("/mobile"); config.setapplicationdestinationprefixes("/mobile-server"); config.setuserdestinationprefix("/mobile-user"); } @override public void registerstompendpoints(stompendpointregistry registry) { registry.addendpoint("/mobile-socket") .withsockjs() .setinterceptors(new httpsessionhandshakeinterceptor()); } }
controller
@controller public class websocketinboxcontroller{ @messagemapping("/inbox") @sendtouser("/mobile") public map<string,object> inbox( ){ map<string,object> res = new hashmap<>(); res.put("hello", "hello"); return res; }
client
const webstomp = require('webstomp-client'); const socket = webstomp.client('ws://www.dev.server.com/mobile-socket',{ debug:true }); socket.connect('marc@gmail.com', '123456', (client) => { console.log('connected'); socket.send("/mobile-server/inbox",) socket.subscribe("/mobile/inbox"); }, (client, err) => { console.log(err); });
what see when client tries connect spring trying match /mobile-socket against requestmappings of existing web application, hitting 1 matches way of @requestmapping("/{somevar}").
i'm new websockets, expect endpoint registration catchall these kinds of connects?
even after removing erronous requestmapping being hit, can't seem messagemapping hit. see in log
antpathrequestmatcher.matches(150) | request '/mobile-socket' matched universal pattern '/**' [msa] debug [2016-06-03t11:16:21,025] filtersecurityinterceptor.beforeinvocation(219) | secure object: filterinvocation: url: /mobile-socket; attributes: [permitall] [msa] debug [2016-06-03t11:16:21,025] filtersecurityinterceptor.authenticateifrequired(348) | authenticated: org.springframework.security.authentication.anonymousauthenticationtoken@9055e4a6: principal: anonymoususer; credentials: [protected]; authenticated: true; details: org.springframework.security.web.authentication.webauthenticationdetails@957e: remoteipaddress: 127.0.0.1; sessionid: null; granted authorities: role_anonymous [msa] debug [2016-06-03t11:16:21,025] affirmativebased.decide(66) | voter: org.springframework.security.web.access.expression.webexpressionvoter@444af45, returned: 1 [msa] debug [2016-06-03t11:16:21,025] filtersecurityinterceptor.beforeinvocation(243) | authorization successful [msa] debug [2016-06-03t11:16:21,026] filtersecurityinterceptor.beforeinvocation(256) | runasmanager did not change authentication object [msa] debug [2016-06-03t11:16:21,026] filterchainproxy.dofilter(325) | /mobile-socket @ position 16 of 16 in additional filter chain; firing filter: 'filtersecurityinterceptor' [msa] debug [2016-06-03t11:16:21,026] filterchainproxy.dofilter(310) | /mobile-socket reached end of additional filter chain; proceeding original chain [msa] debug [2016-06-03t11:16:21,027] exceptiontranslationfilter.dofilter(117) | chain processed [msa] debug [2016-06-03t11:16:21,027] hstsheaderwriter.writeheaders(130) | not injecting hsts header since did not match requestmatcher org.springframework.security.web.header.writers.hstsheaderwriter$securerequestmatcher@53cc2afb [msa] debug [2016-06-03t11:16:21,027] httpsessionsecuritycontextrepository.savecontext(352) | securitycontext empty or contents anonymous - context not stored in httpsession. [msa] debug [2016-06-03t11:16:21,028] securitycontextpersistencefilter.dofilter(120) | securitycontextholder cleared, request processing completed
the spring tries match "/mobile-socket" against requestmappings because requests go handlermapping beans in web application context map incoming web requests appropriate handlers. introduction of annotated controllers, requestmappinghandlermapping automatically looks @requestmapping annotations on @controller beans including controller has @messagemapping.
since @messagemapping can defined under @controller annotation, spring try match other requestmappings well.
one possible solution introduce interceptor handle websocket request url map particular controller. can give try!