Deprecated as of 5.0 a TaskScheduler is not provided upfront, not until it is obvious that it is needed; call SockJsServiceRegistration.getTaskScheduler() to check and then SockJsServiceRegistration.setTaskScheduler(TaskScheduler) to set it before a call to SockJsServiceRegistration.createSockJsService()
@Override public SockJsServiceRegistration withSockJS() { this.sockJsServiceRegistration = new SockJsServiceRegistration(); HandshakeInterceptor[] interceptors = getInterceptors(); if (interceptors.length > 0) { this.sockJsServiceRegistration.setInterceptors(interceptors); } if (this.handshakeHandler != null) { WebSocketTransportHandler transportHandler = new WebSocketTransportHandler(this.handshakeHandler); this.sockJsServiceRegistration.setTransportHandlerOverrides(transportHandler); } if (!this.allowedOrigins.isEmpty()) { this.sockJsServiceRegistration.setAllowedOrigins(StringUtils.toStringArray(this.allowedOrigins)); } return this.sockJsServiceRegistration; }
@Override public SockJsServiceRegistration withSockJS() { this.registration = new SockJsServiceRegistration(); this.registration.setTaskScheduler(this.sockJsTaskScheduler); HandshakeInterceptor[] interceptors = getInterceptors(); if (interceptors.length > 0) { this.registration.setInterceptors(interceptors); } if (this.handshakeHandler != null) { WebSocketTransportHandler handler = new WebSocketTransportHandler(this.handshakeHandler); this.registration.setTransportHandlerOverrides(handler); } if (!this.allowedOrigins.isEmpty()) { this.registration.setAllowedOrigins(StringUtils.toStringArray(this.allowedOrigins)); } return this.registration; }
@Test public void allowedOriginsWithSockJsService() { WebMvcStompWebSocketEndpointRegistration registration = new WebMvcStompWebSocketEndpointRegistration(new String[] {"/foo"}, this.handler, this.scheduler); String origin = "http://mydomain.com"; registration.setAllowedOrigins(origin).withSockJS(); MultiValueMap<HttpRequestHandler, String> mappings = registration.getMappings(); assertEquals(1, mappings.size()); SockJsHttpRequestHandler requestHandler = (SockJsHttpRequestHandler)mappings.entrySet().iterator().next().getKey(); assertNotNull(requestHandler.getSockJsService()); DefaultSockJsService sockJsService = (DefaultSockJsService)requestHandler.getSockJsService(); assertTrue(sockJsService.getAllowedOrigins().contains(origin)); assertFalse(sockJsService.shouldSuppressCors()); registration = new WebMvcStompWebSocketEndpointRegistration(new String[] {"/foo"}, this.handler, this.scheduler); registration.withSockJS().setAllowedOrigins(origin); mappings = registration.getMappings(); assertEquals(1, mappings.size()); requestHandler = (SockJsHttpRequestHandler)mappings.entrySet().iterator().next().getKey(); assertNotNull(requestHandler.getSockJsService()); sockJsService = (DefaultSockJsService)requestHandler.getSockJsService(); assertTrue(sockJsService.getAllowedOrigins().contains(origin)); assertFalse(sockJsService.shouldSuppressCors()); }
@Override protected SockJsServiceRegistration setAllowedOrigins(String... origins) { return super.setAllowedOrigins(origins); }
@Override public SockJsServiceRegistration withSockJS() { this.sockJsServiceRegistration = new SockJsServiceRegistration(); HandshakeInterceptor[] interceptors = getInterceptors(); if (interceptors.length > 0) { this.sockJsServiceRegistration.setInterceptors(interceptors); } if (this.handshakeHandler != null) { WebSocketTransportHandler transportHandler = new WebSocketTransportHandler(this.handshakeHandler); this.sockJsServiceRegistration.setTransportHandlerOverrides(transportHandler); } if (!this.allowedOrigins.isEmpty()) { this.sockJsServiceRegistration.setAllowedOrigins(StringUtils.toStringArray(this.allowedOrigins)); } return this.sockJsServiceRegistration; }
@Override public SockJsServiceRegistration withSockJS() { this.registration = new SockJsServiceRegistration(); this.registration.setTaskScheduler(this.sockJsTaskScheduler); HandshakeInterceptor[] interceptors = getInterceptors(); if (interceptors.length > 0) { this.registration.setInterceptors(interceptors); } if (this.handshakeHandler != null) { WebSocketTransportHandler handler = new WebSocketTransportHandler(this.handshakeHandler); this.registration.setTransportHandlerOverrides(handler); } if (!this.allowedOrigins.isEmpty()) { this.registration.setAllowedOrigins(StringUtils.toStringArray(this.allowedOrigins)); } return this.registration; }
@Override public SockJsServiceRegistration withSockJS() { this.registration = new SockJsServiceRegistration(); this.registration.setTaskScheduler(this.sockJsTaskScheduler); HandshakeInterceptor[] interceptors = getInterceptors(); if (interceptors.length > 0) { this.registration.setInterceptors(interceptors); } if (this.handshakeHandler != null) { WebSocketTransportHandler handler = new WebSocketTransportHandler(this.handshakeHandler); this.registration.setTransportHandlerOverrides(handler); } if (!this.allowedOrigins.isEmpty()) { this.registration.setAllowedOrigins(StringUtils.toStringArray(this.allowedOrigins)); } return this.registration; }
@Override public SockJsServiceRegistration withSockJS() { this.sockJsServiceRegistration = new SockJsServiceRegistration(); if (this.scheduler != null) { this.sockJsServiceRegistration.setTaskScheduler(this.scheduler); } HandshakeInterceptor[] interceptors = getInterceptors(); if (interceptors.length > 0) { this.sockJsServiceRegistration.setInterceptors(interceptors); } if (this.handshakeHandler != null) { WebSocketTransportHandler transportHandler = new WebSocketTransportHandler(this.handshakeHandler); this.sockJsServiceRegistration.setTransportHandlerOverrides(transportHandler); } if (!this.allowedOrigins.isEmpty()) { this.sockJsServiceRegistration.setAllowedOrigins(StringUtils.toStringArray(this.allowedOrigins)); } return this.sockJsServiceRegistration; }