@Override public void upgradeInternal(ServerHttpRequest request, ServerHttpResponse response, @Nullable String selectedProtocol, List<Extension> selectedExtensions, Endpoint endpoint) throws HandshakeFailureException { HttpServletRequest servletRequest = getHttpServletRequest(request); HttpServletResponse servletResponse = getHttpServletResponse(response); StringBuffer requestUrl = servletRequest.getRequestURL(); String path = servletRequest.getRequestURI(); // shouldn't matter Map<String, String> pathParams = Collections.<String, String> emptyMap(); ServerEndpointRegistration endpointConfig = new ServerEndpointRegistration(path, endpoint); endpointConfig.setSubprotocols(Collections.singletonList(selectedProtocol)); endpointConfig.setExtensions(selectedExtensions); try { getContainer(servletRequest).doUpgrade(servletRequest, servletResponse, endpointConfig, pathParams); } catch (ServletException ex) { throw new HandshakeFailureException( "Servlet request failed to upgrade to WebSocket: " + requestUrl, ex); } catch (IOException ex) { throw new HandshakeFailureException( "Response update failed during upgrade to WebSocket: " + requestUrl, ex); } }
public WsRemoteEndpointImplServer(ServletOutputStream sos, WsServerContainer serverContainer) { this.sos = sos; this.wsWriteTimeout = serverContainer.getTimeout(); this.executorService = serverContainer.getExecutorService(); }
public WsRemoteEndpointImplServer(SocketWrapperBase<?> socketWrapper, WsServerContainer serverContainer) { this.socketWrapper = socketWrapper; this.wsWriteTimeout = serverContainer.getTimeout(); }
static WsServerContainer init(ServletContext servletContext, boolean initBySciMechanism) { WsServerContainer sc = new WsServerContainer(servletContext); servletContext.setAttribute( Constants.SERVER_CONTAINER_SERVLET_CONTEXT_ATTRIBUTE, sc); servletContext.addListener(new WsSessionListener(sc)); // Can't register the ContextListener again if the ContextListener is // calling this method if (initBySciMechanism) { servletContext.addListener(new WsContextListener()); } return sc; }
@Override protected void doWrite(SendHandler handler, ByteBuffer... buffers) { this.handler = handler; this.buffers = buffers; // This is definitely the same thread that triggered the write so a // dispatch will be required. onWritePossible(true); }
@Override public void onError(Throwable throwable) { wsProtocolHandler.onError(throwable); wsRemoteEndpointServer.close(); } }
public void doUpgrade(HttpServletRequest request, HttpServletResponse response, ServerEndpointConfig sec, Map<String,String> pathParams) throws ServletException, IOException { UpgradeUtil.doUpgrade(this, request, response, sec, pathParams); }
@Override public void onError(Throwable throwable) { wsProtocolHandler.onError(throwable); } }
static WsServerContainer init(ServletContext servletContext, boolean initBySciMechanism) { WsServerContainer sc = new WsServerContainer(servletContext); servletContext.setAttribute( Constants.SERVER_CONTAINER_SERVLET_CONTEXT_ATTRIBUTE, sc); servletContext.addListener(new WsSessionListener(sc)); // Can't register the ContextListener again if the ContextListener is // calling this method if (initBySciMechanism) { servletContext.addListener(new WsContextListener()); } return sc; }
public WsRemoteEndpointImplServer(AbstractServletOutputStream sos, WsServerContainer serverContainer) { this.sos = sos; this.wsWriteTimeout = serverContainer.getTimeout(); this.executorService = serverContainer.getExecutorService(); }
@Override public void onWritePossible() { // Triggered by the poller so this isn't the same thread that // triggered the write so no need for a dispatch wsRemoteEndpointServer.onWritePossible(false); }
@Override public Mono<Void> upgrade(ServerWebExchange exchange, WebSocketHandler handler, @Nullable String subProtocol, Supplier<HandshakeInfo> handshakeInfoFactory){ ServerHttpRequest request = exchange.getRequest(); ServerHttpResponse response = exchange.getResponse(); HttpServletRequest servletRequest = getHttpServletRequest(request); HttpServletResponse servletResponse = getHttpServletResponse(response); HandshakeInfo handshakeInfo = handshakeInfoFactory.get(); DataBufferFactory bufferFactory = response.bufferFactory(); Endpoint endpoint = new StandardWebSocketHandlerAdapter( handler, session -> new TomcatWebSocketSession(session, handshakeInfo, bufferFactory)); String requestURI = servletRequest.getRequestURI(); DefaultServerEndpointConfig config = new DefaultServerEndpointConfig(requestURI, endpoint); config.setSubprotocols(subProtocol != null ? Collections.singletonList(subProtocol) : Collections.emptyList()); try { WsServerContainer container = getContainer(servletRequest); container.doUpgrade(servletRequest, servletResponse, config, Collections.emptyMap()); } catch (ServletException | IOException ex) { return Mono.error(ex); } return Mono.empty(); }
public WsRemoteEndpointImplServer(SocketWrapperBase<?> socketWrapper, WsServerContainer serverContainer) { this.socketWrapper = socketWrapper; this.wsWriteTimeout = serverContainer.getTimeout(); }
@Override public void onError(Throwable throwable) { wsProtocolHandler.onError(throwable); wsRemoteEndpointServer.close(); } }
@Override public void onError(Throwable throwable) { wsProtocolHandler.onError(throwable); } }
public WsRemoteEndpointImplServer(AbstractServletOutputStream sos, WsServerContainer serverContainer) { this.sos = sos; this.wsWriteTimeout = serverContainer.getTimeout(); this.executorService = serverContainer.getExecutorService(); }
@Override public void onWritePossible() { // Triggered by the poller so this isn't the same thread that // triggered the write so no need for a dispatch wsRemoteEndpointServer.onWritePossible(false); }
@Override protected void doWrite(SendHandler handler, ByteBuffer... buffers) { this.handler = handler; this.buffers = buffers; // This is definitely the same thread that triggered the write so a // dispatch will be required. onWritePossible(true); }
@Override protected void doWrite(SendHandler handler, ByteBuffer... buffers) { this.handler = handler; this.buffers = buffers; // This is definitely the same thread that triggered the write so a // dispatch will be required. onWritePossible(true); }
@Override public void onWritePossible() { // Triggered by the poller so this isn't the same thread that // triggered the write so no need for a dispatch wsRemoteEndpointServer.onWritePossible(false); }