messages = readMessages(request); if (ex.getClass().getName().contains("Mapping")) { handleReadError(response, "Payload expected.", sockJsSession.getId()); handleReadError(response, "Broken JSON encoding.", sockJsSession.getId()); handleReadError(response, "Failed to read message(s)", sockJsSession.getId()); return; handleReadError(response, "Payload expected.", sockJsSession.getId()); return; logger.trace("Received message(s): " + Arrays.asList(messages)); response.setStatusCode(getResponseStatus()); response.getHeaders().setContentType(new MediaType("text", "plain", StandardCharsets.UTF_8));
@Override public final void handleRequest(ServerHttpRequest request, ServerHttpResponse response, WebSocketHandler wsHandler, SockJsSession wsSession) throws SockJsException { Assert.notNull(wsSession, "No session"); AbstractHttpSockJsSession sockJsSession = (AbstractHttpSockJsSession) wsSession; handleRequestInternal(request, response, wsHandler, sockJsSession); }
private void handleRequest(AbstractHttpReceivingTransportHandler transportHandler) throws Exception { WebSocketHandler wsHandler = mock(WebSocketHandler.class); AbstractSockJsSession session = new TestHttpSockJsSession("1", new StubSockJsServiceConfig(), wsHandler, null); transportHandler.initialize(new StubSockJsServiceConfig()); transportHandler.handleRequest(this.request, this.response, wsHandler, session); assertEquals("text/plain;charset=UTF-8", this.response.getHeaders().getContentType().toString()); verify(wsHandler).handleMessage(session, new TextMessage("x")); }
messages = readMessages(request); if (ex.getClass().getName().contains("Mapping")) { handleReadError(response, "Payload expected.", sockJsSession.getId()); handleReadError(response, "Broken JSON encoding.", sockJsSession.getId()); handleReadError(response, "Failed to read message(s)", sockJsSession.getId()); return; handleReadError(response, "Payload expected.", sockJsSession.getId()); return; logger.trace("Received message(s): " + Arrays.asList(messages)); response.setStatusCode(getResponseStatus()); response.getHeaders().setContentType(new MediaType("text", "plain", StandardCharsets.UTF_8));
@Override public final void handleRequest(ServerHttpRequest request, ServerHttpResponse response, WebSocketHandler wsHandler, SockJsSession wsSession) throws SockJsException { Assert.notNull(wsSession, "No session"); AbstractHttpSockJsSession sockJsSession = (AbstractHttpSockJsSession) wsSession; handleRequestInternal(request, response, wsHandler, sockJsSession); }
messages = readMessages(request); if (ex.getClass().getName().contains("Mapping")) { handleReadError(response, "Payload expected.", sockJsSession.getId()); handleReadError(response, "Broken JSON encoding.", sockJsSession.getId()); handleReadError(response, "Failed to read message(s)", sockJsSession.getId()); return; handleReadError(response, "Payload expected.", sockJsSession.getId()); return; logger.trace("Received message(s): " + Arrays.asList(messages)); response.setStatusCode(getResponseStatus()); response.getHeaders().setContentType(new MediaType("text", "plain", StandardCharsets.UTF_8));
@Override public final void handleRequest(ServerHttpRequest request, ServerHttpResponse response, WebSocketHandler wsHandler, SockJsSession wsSession) throws SockJsException { Assert.notNull(wsSession, "No session"); AbstractHttpSockJsSession sockJsSession = (AbstractHttpSockJsSession) wsSession; handleRequestInternal(request, response, wsHandler, sockJsSession); }
@Override public void handleRequestInternal(ServerHttpRequest request, ServerHttpResponse response, WebSocketHandler wsHandler, AbstractHttpSockJsSession sockJsSession) throws SockJsException { super.handleRequestInternal(request, response, wsHandler, sockJsSession); try { response.getBody().write("ok".getBytes(StandardCharsets.UTF_8)); } catch (IOException ex) { throw new SockJsException("Failed to write to the response body", sockJsSession.getId(), ex); } }