return; if (!transportHandler.checkSessionType(session)) { logger.debug("Session type does not match the transport type for the request."); response.setStatusCode(HttpStatus.NOT_FOUND); transportHandler.handleRequest(request, response, handler, session); chain.applyAfterHandshake(request, response, null);
/** * Create a TransportHandlingSockJsService with given {@link TransportHandler handler} types. * @param scheduler a task scheduler for heart-beat messages and removing timed-out sessions; * the provided TaskScheduler should be declared as a Spring bean to ensure it gets * initialized at start-up and shuts down when the application stops * @param handlers one or more {@link TransportHandler} implementations to use */ public TransportHandlingSockJsService(TaskScheduler scheduler, Collection<TransportHandler> handlers) { super(scheduler); if (CollectionUtils.isEmpty(handlers)) { logger.warn("No transport handlers specified for TransportHandlingSockJsService"); } else { for (TransportHandler handler : handlers) { handler.initialize(this); this.handlers.put(handler.getTransportType(), handler); } } if (jackson2Present) { this.messageCodec = new Jackson2SockJsMessageCodec(); } }
@Before public void setup() { super.setup(); MockitoAnnotations.initMocks(this); Map<String, Object> attributes = Collections.emptyMap(); this.session = new TestSockJsSession(sessionId, new StubSockJsServiceConfig(), this.wsHandler, attributes); given(this.xhrHandler.getTransportType()).willReturn(TransportType.XHR); given(this.xhrHandler.createSession(sessionId, this.wsHandler, attributes)).willReturn(this.session); given(this.xhrSendHandler.getTransportType()).willReturn(TransportType.XHR_SEND); given(this.wsTransportHandler.getTransportType()).willReturn(TransportType.WEBSOCKET); this.service = new TransportHandlingSockJsService(this.taskScheduler, this.xhrHandler, this.xhrSendHandler); }
@Test public void handleTransportRequestXhrSend() throws Exception { String sockJsPath = sessionUrlPrefix + "xhr_send"; setRequest("POST", sockJsPrefix + sockJsPath); this.service.handleRequest(this.request, this.response, sockJsPath, this.wsHandler); assertEquals(404, this.servletResponse.getStatus()); // no session yet resetResponse(); sockJsPath = sessionUrlPrefix + "xhr"; setRequest("POST", sockJsPrefix + sockJsPath); this.service.handleRequest(this.request, this.response, sockJsPath, this.wsHandler); assertEquals(200, this.servletResponse.getStatus()); // session created verify(this.xhrHandler).handleRequest(this.request, this.response, this.wsHandler, this.session); resetResponse(); sockJsPath = sessionUrlPrefix + "xhr_send"; setRequest("POST", sockJsPrefix + sockJsPath); given(this.xhrSendHandler.checkSessionType(this.session)).willReturn(true); this.service.handleRequest(this.request, this.response, sockJsPath, this.wsHandler); assertEquals(200, this.servletResponse.getStatus()); // session exists verify(this.xhrSendHandler).handleRequest(this.request, this.response, this.wsHandler, this.session); }
/** * Create a TransportHandlingSockJsService with given {@link TransportHandler handler} types. * @param scheduler a task scheduler for heart-beat messages and removing timed-out sessions; * the provided TaskScheduler should be declared as a Spring bean to ensure it gets * initialized at start-up and shuts down when the application stops * @param handlers one or more {@link TransportHandler} implementations to use */ public TransportHandlingSockJsService(TaskScheduler scheduler, Collection<TransportHandler> handlers) { super(scheduler); if (CollectionUtils.isEmpty(handlers)) { logger.warn("No transport handlers specified for TransportHandlingSockJsService"); } else { for (TransportHandler handler : handlers) { handler.initialize(this); this.handlers.put(handler.getTransportType(), handler); } } if (jackson2Present) { this.messageCodec = new Jackson2SockJsMessageCodec(); } }
return; if (!transportHandler.checkSessionType(session)) { logger.debug("Session type does not match the transport type for the request."); response.setStatusCode(HttpStatus.NOT_FOUND); transportHandler.handleRequest(request, response, handler, session); chain.applyAfterHandshake(request, response, null);
/** * Create a TransportHandlingSockJsService with given {@link TransportHandler handler} types. * @param scheduler a task scheduler for heart-beat messages and removing timed-out sessions; * the provided TaskScheduler should be declared as a Spring bean to ensure it gets * initialized at start-up and shuts down when the application stops * @param handlers one or more {@link TransportHandler} implementations to use */ public TransportHandlingSockJsService(TaskScheduler scheduler, Collection<TransportHandler> handlers) { super(scheduler); if (CollectionUtils.isEmpty(handlers)) { logger.warn("No transport handlers specified for TransportHandlingSockJsService"); } else { for (TransportHandler handler : handlers) { handler.initialize(this); this.handlers.put(handler.getTransportType(), handler); } } if (jackson2Present) { this.messageCodec = new Jackson2SockJsMessageCodec(); } }
return; if (!transportHandler.checkSessionType(session)) { logger.debug("Session type does not match the transport type for the request."); response.setStatusCode(HttpStatus.NOT_FOUND); transportHandler.handleRequest(request, response, handler, session); chain.applyAfterHandshake(request, response, null);