Java Code Examples for io.undertow.websockets.core.protocol.Handshake#handshake()
The following examples show how to use
io.undertow.websockets.core.protocol.Handshake#handshake() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: UndertowWebSocketFilter.java From pippo with Apache License 2.0 | 6 votes |
private void processWebSocketRequest(Request request, Response response) { HttpServletRequest servletRequest = request.getHttpServletRequest(); HttpServletResponse servletResponse = response.getHttpServletResponse(); WebSocketHttpExchange exchange = new ServletWebSocketHttpExchange(servletRequest, servletResponse, peerConnections); // exchange.putAttachment(HandshakeUtil.PATH_PARAMS, Collections.<String, String>emptyMap()); Handshake handshake = getHandshake(exchange); exchange.upgradeChannel((connection, serverExchange) -> { WebSocketChannel channel = handshake.createChannel(exchange, connection, exchange.getBufferPool()); peerConnections.add(channel); createWebSocketAdapter(request).onConnect(exchange, channel); }); handshake.handshake(exchange); }
Example 2
Source File: WebSocketServlet.java From lams with GNU General Public License v2.0 | 5 votes |
@Override protected void doGet(final HttpServletRequest req, final HttpServletResponse resp) throws ServletException, IOException { final ServletWebSocketHttpExchange facade = new ServletWebSocketHttpExchange(req, resp, peerConnections); Handshake handshaker = null; for (Handshake method : handshakes) { if (method.matches(facade)) { handshaker = method; break; } } if (handshaker == null) { UndertowLogger.REQUEST_LOGGER.debug("Could not find hand shaker for web socket request"); resp.sendError(StatusCodes.BAD_REQUEST); return; } final Handshake selected = handshaker; facade.upgradeChannel(new HttpUpgradeListener() { @Override public void handleUpgrade(StreamConnection streamConnection, HttpServerExchange exchange) { WebSocketChannel channel = selected.createChannel(facade, streamConnection, facade.getBufferPool()); peerConnections.add(channel); callback.onConnect(facade, channel); } }); handshaker.handshake(facade); }
Example 3
Source File: UndertowRequestUpgradeStrategy.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Override protected void upgradeInternal(ServerHttpRequest request, ServerHttpResponse response, String selectedProtocol, List<Extension> selectedExtensions, final Endpoint endpoint) throws HandshakeFailureException { HttpServletRequest servletRequest = getHttpServletRequest(request); HttpServletResponse servletResponse = getHttpServletResponse(response); final ServletWebSocketHttpExchange exchange = createHttpExchange(servletRequest, servletResponse); exchange.putAttachment(HandshakeUtil.PATH_PARAMS, Collections.<String, String>emptyMap()); ServerWebSocketContainer wsContainer = (ServerWebSocketContainer) getContainer(servletRequest); final EndpointSessionHandler endpointSessionHandler = new EndpointSessionHandler(wsContainer); final ConfiguredServerEndpoint configuredServerEndpoint = createConfiguredServerEndpoint( selectedProtocol, selectedExtensions, endpoint, servletRequest); final Handshake handshake = getHandshakeToUse(exchange, configuredServerEndpoint); exchange.upgradeChannel(new HttpUpgradeListener() { @Override public void handleUpgrade(StreamConnection connection, HttpServerExchange serverExchange) { Object bufferPool = ReflectionUtils.invokeMethod(getBufferPoolMethod, exchange); WebSocketChannel channel = (WebSocketChannel) ReflectionUtils.invokeMethod( createChannelMethod, handshake, exchange, connection, bufferPool); if (peerConnections != null) { peerConnections.add(channel); } endpointSessionHandler.onConnect(exchange, channel); } }); handshake.handshake(exchange); }