Package io.undertow.servlet.websockets

Examples of io.undertow.servlet.websockets.ServletWebSocketHttpExchange


    @Override
    public void doFilter(final ServletRequest request, final ServletResponse response, final FilterChain chain) throws IOException, ServletException {
        HttpServletRequest req = (HttpServletRequest) request;
        HttpServletResponse resp = (HttpServletResponse) response;
        if (req.getHeader(Headers.UPGRADE_STRING) != null) {
            final ServletWebSocketHttpExchange facade = new ServletWebSocketHttpExchange(req, resp, peerConnections);

            String path;
            if (req.getPathInfo() == null) {
                path = req.getServletPath();
            } else {
                path = req.getServletPath() + req.getPathInfo();
            }
            if (!path.startsWith("/")) {
                path = "/" + path;
            }
            PathTemplateMatcher.PathMatchResult<WebSocketHandshakeHolder> matchResult = pathTemplateMatcher.match(path);
            if (matchResult != null) {
                Handshake handshaker = null;
                for (Handshake method : matchResult.getValue().handshakes) {
                    if (method.matches(facade)) {
                        handshaker = method;
                        break;
                    }
                }

                if (handshaker != null) {
                    facade.putAttachment(HandshakeUtil.PATH_PARAMS, matchResult.getParameters());
                    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);
View Full Code Here


    @Override
    public void doFilter(final ServletRequest request, final ServletResponse response, final FilterChain chain) throws IOException, ServletException {
        HttpServletRequest req = (HttpServletRequest) request;
        HttpServletResponse resp = (HttpServletResponse) response;
        if (req.getHeader("Upgrade") != null) {
            final ServletWebSocketHttpExchange facade = new ServletWebSocketHttpExchange(req, resp);

            String path;
            if (req.getPathInfo() == null) {
                path = req.getServletPath();
            } else {
                path = req.getServletPath() + req.getPathInfo();
            }
            if (!path.startsWith("/")) {
                path = "/" + path;
            }

            final Map<String, String> params = new HashMap<String, String>();
            //we need a better way of handling this mapping.
            for (ConfiguredServerEndpoint endpoint : configuredServerEndpoints) {
                if (endpoint.getPathTemplate().matches(path, params)) {
                    Handshake handshaker = null;
                    for (Handshake method : handshakes.get(endpoint)) {
                        if (method.matches(facade)) {
                            handshaker = method;
                            break;
                        }
                    }

                    if (handshaker == null) {
                        chain.doFilter(request, response);
                    } else {
                        facade.putAttachment(HandshakeUtil.PATH_PARAMS, params);
                        handshaker.handshake(facade, callback);
                        return;
                    }
                }
            }
View Full Code Here

    @Override
    public void doFilter(final ServletRequest request, final ServletResponse response, final FilterChain chain) throws IOException, ServletException {
        HttpServletRequest req = (HttpServletRequest) request;
        HttpServletResponse resp = (HttpServletResponse) response;
        if (req.getHeader(Headers.UPGRADE_STRING) != null) {
            final ServletWebSocketHttpExchange facade = new ServletWebSocketHttpExchange(req, resp);

            String path;
            if (req.getPathInfo() == null) {
                path = req.getServletPath();
            } else {
                path = req.getServletPath() + req.getPathInfo();
            }
            if (!path.startsWith("/")) {
                path = "/" + path;
            }
            PathTemplateMatcher.PathMatchResult<WebSocketHandshakeHolder> matchResult = pathTemplateMatcher.match(path);
            if (matchResult != null) {
                Handshake handshaker = null;
                for (Handshake method : matchResult.getValue().handshakes) {
                    if (method.matches(facade)) {
                        handshaker = method;
                        break;
                    }
                }

                if (handshaker != null) {
                    facade.putAttachment(HandshakeUtil.PATH_PARAMS, matchResult.getParameters());
                    final Handshake selected = handshaker;
                    facade.upgradeChannel(new HttpUpgradeListener() {
                        @Override
                        public void handleUpgrade(StreamConnection streamConnection, HttpServerExchange exchange) {
                            WebSocketChannel channel = selected.createChannel(facade, streamConnection, facade.getBufferPool());
                            callback.onConnect(facade, channel);
                        }
                    });
                    handshaker.handshake(facade);
                    return;
View Full Code Here

    @Override
    public void doFilter(final ServletRequest request, final ServletResponse response, final FilterChain chain) throws IOException, ServletException {
        HttpServletRequest req = (HttpServletRequest) request;
        HttpServletResponse resp = (HttpServletResponse) response;
        if (req.getHeader(Headers.UPGRADE_STRING) != null) {
            final ServletWebSocketHttpExchange facade = new ServletWebSocketHttpExchange(req, resp, peerConnections);

            String path;
            if (req.getPathInfo() == null) {
                path = req.getServletPath();
            } else {
                path = req.getServletPath() + req.getPathInfo();
            }
            if (!path.startsWith("/")) {
                path = "/" + path;
            }
            PathTemplateMatcher.PathMatchResult<WebSocketHandshakeHolder> matchResult = pathTemplateMatcher.match(path);
            if (matchResult != null) {
                Handshake handshaker = null;
                for (Handshake method : matchResult.getValue().handshakes) {
                    if (method.matches(facade)) {
                        handshaker = method;
                        break;
                    }
                }

                if (handshaker != null) {
                    facade.putAttachment(HandshakeUtil.PATH_PARAMS, matchResult.getParameters());
                    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);
View Full Code Here

    @Override
    public void doFilter(final ServletRequest request, final ServletResponse response, final FilterChain chain) throws IOException, ServletException {
        HttpServletRequest req = (HttpServletRequest) request;
        HttpServletResponse resp = (HttpServletResponse) response;
        if (req.getHeader("Upgrade") != null) {
            final ServletWebSocketHttpExchange facade = new ServletWebSocketHttpExchange(req, resp);

            String path;
            if (req.getPathInfo() == null) {
                path = req.getServletPath();
            } else {
                path = req.getServletPath() + req.getPathInfo();
            }
            if (!path.startsWith("/")) {
                path = "/" + path;
            }

            final Map<String, String> params = new HashMap<String, String>();
            //we need a better way of handling this mapping.
            for (ConfiguredServerEndpoint endpoint : configuredServerEndpoints) {
                if (endpoint.getPathTemplate().matches(path, params)) {
                    Handshake handshaker = null;
                    for (Handshake method : handshakes.get(endpoint)) {
                        if (method.matches(facade)) {
                            handshaker = method;
                            break;
                        }
                    }

                    if (handshaker == null) {
                        chain.doFilter(request, response);
                    } else {
                        facade.putAttachment(HandshakeUtil.PATH_PARAMS, params);
                        handshaker.handshake(facade, callback);
                        return;
                    }
                }
            }
View Full Code Here

      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) {
        WebSocketChannel channel = handshake.createChannel(exchange, connection, exchange.getBufferPool());
        if (peerConnections != null) {
          peerConnections.add(channel);
        }
        endpointSessionHandler.onConnect(exchange, channel);
      }
View Full Code Here

    @Override
    public void doFilter(final ServletRequest request, final ServletResponse response, final FilterChain chain) throws IOException, ServletException {
        HttpServletRequest req = (HttpServletRequest) request;
        HttpServletResponse resp = (HttpServletResponse) response;
        if (req.getHeader(Headers.UPGRADE_STRING) != null) {
            final ServletWebSocketHttpExchange facade = new ServletWebSocketHttpExchange(req, resp, peerConnections);

            String path;
            if (req.getPathInfo() == null) {
                path = req.getServletPath();
            } else {
                path = req.getServletPath() + req.getPathInfo();
            }
            if (!path.startsWith("/")) {
                path = "/" + path;
            }
            PathTemplateMatcher.PathMatchResult<WebSocketHandshakeHolder> matchResult = pathTemplateMatcher.match(path);
            if (matchResult != null) {
                Handshake handshaker = null;
                for (Handshake method : matchResult.getValue().handshakes) {
                    if (method.matches(facade)) {
                        handshaker = method;
                        break;
                    }
                }

                if (handshaker != null) {
                    facade.putAttachment(HandshakeUtil.PATH_PARAMS, matchResult.getParameters());
                    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);
View Full Code Here

    @Override
    public void doFilter(final ServletRequest request, final ServletResponse response, final FilterChain chain) throws IOException, ServletException {
        HttpServletRequest req = (HttpServletRequest) request;
        HttpServletResponse resp = (HttpServletResponse) response;
        if (req.getHeader(Headers.UPGRADE_STRING) != null) {
            final ServletWebSocketHttpExchange facade = new ServletWebSocketHttpExchange(req, resp);

            String path;
            if (req.getPathInfo() == null) {
                path = req.getServletPath();
            } else {
                path = req.getServletPath() + req.getPathInfo();
            }
            if (!path.startsWith("/")) {
                path = "/" + path;
            }
            PathTemplateMatcher.PathMatchResult<WebSocketHandshakeHolder> matchResult = pathTemplateMatcher.match(path);
            if (matchResult != null) {
                Handshake handshaker = null;
                for (Handshake method : matchResult.getValue().handshakes) {
                    if (method.matches(facade)) {
                        handshaker = method;
                        break;
                    }
                }

                if (handshaker == null) {
                    chain.doFilter(request, response);
                } else {
                    facade.putAttachment(HandshakeUtil.PATH_PARAMS, matchResult.getParameters());
                    handshaker.handshake(facade, callback);
                    return;
                }
            }
            chain.doFilter(request, response);
View Full Code Here

    @Override
    public void doFilter(final ServletRequest request, final ServletResponse response, final FilterChain chain) throws IOException, ServletException {
        HttpServletRequest req = (HttpServletRequest) request;
        HttpServletResponse resp = (HttpServletResponse) response;
        if (req.getHeader("Upgrade") != null) {
            final ServletWebSocketHttpExchange facade = new ServletWebSocketHttpExchange(req, resp);

            String path;
            if (req.getPathInfo() == null) {
                path = req.getServletPath();
            } else {
                path = req.getServletPath() + req.getPathInfo();
            }
            if (!path.startsWith("/")) {
                path = "/" + path;
            }

            final Map<String, String> params = new HashMap<>();
            //we need a better way of handling this mapping.
            for (ConfiguredServerEndpoint endpoint : configuredServerEndpoints) {
                if (endpoint.getPathTemplate().matches(path, params)) {
                    Handshake handshaker = null;
                    for (Handshake method : handshakes.get(endpoint)) {
                        if (method.matches(facade)) {
                            handshaker = method;
                            break;
                        }
                    }

                    if (handshaker == null) {
                        chain.doFilter(request, response);
                    } else {
                        facade.putAttachment(HandshakeUtil.PATH_PARAMS, params);
                        handshaker.handshake(facade, callback);
                        return;
                    }
                }
            }
View Full Code Here

TOP

Related Classes of io.undertow.servlet.websockets.ServletWebSocketHttpExchange

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.