Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * JBoss, Home of Professional Open Source.
   * Copyright 2012 Red Hat, Inc., and individual contributors
   * as indicated by the @author tags.
   *
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   *
  *     http://www.apache.org/licenses/LICENSE-2.0
  *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
 
 package io.undertow.websockets;
 
 
 
 import java.util.Set;

io.undertow.server.HttpHandler which will process the io.undertow.server.HttpServerExchange and do the actual handshake/upgrade to WebSocket.

Author(s):
Norman Maurer
 
 public class WebSocketProtocolHandshakeHandler implements HttpHandler {
     private final Set<Handshakehandshakes;

    
The upgrade listener. This will only be used if another web socket implementation is being layered on top.
 
     private final HttpUpgradeListener upgradeListener;
 
     private final WebSocketConnectionCallback callback;

    
The handler that is invoked if there are no web socket headers
 
     private final HttpHandler next;

    
Create a new WebSocketProtocolHandshakeHandler

Parameters:
callback The WebSocketConnectionCallback which will be executed once the handshake was established
 
         this(callback.);
     }

    
Create a new WebSocketProtocolHandshakeHandler

Parameters:
callback The WebSocketConnectionCallback which will be executed once the handshake was established
 
     public WebSocketProtocolHandshakeHandler(final WebSocketConnectionCallback callbackfinal HttpHandler next) {
         this. = callback;
         Set<Handshakehandshakes = new HashSet<Handshake>();
         handshakes.add(new Hybi13Handshake());
         handshakes.add(new Hybi08Handshake());
         handshakes.add(new Hybi07Handshake());
         this. = handshakes;
         this. = next;
         this. = null;
     }

    
Create a new WebSocketProtocolHandshakeHandler

Parameters:
handshakes The supported handshake methods
callback The WebSocketConnectionCallback which will be executed once the handshake was established
 
     public WebSocketProtocolHandshakeHandler(Collection<Handshakehandshakesfinal WebSocketConnectionCallback callback) {
         this(handshakescallback.);
     }

    
Create a new WebSocketProtocolHandshakeHandler

Parameters:
handshakes The supported handshake methods
callback The WebSocketConnectionCallback which will be executed once the handshake was established
    public WebSocketProtocolHandshakeHandler(Collection<Handshakehandshakesfinal WebSocketConnectionCallback callbackfinal HttpHandler next) {
        this. = callback;
        this. = new HashSet<Handshake>(handshakes);
        this. = next;
        this. = null;
    }

    
Create a new WebSocketProtocolHandshakeHandler

Parameters:
callback The WebSocketConnectionCallback which will be executed once the handshake was established
    public WebSocketProtocolHandshakeHandler(final HttpUpgradeListener callback) {
        this(callback.);
    }

    
Create a new WebSocketProtocolHandshakeHandler

Parameters:
callback The WebSocketConnectionCallback which will be executed once the handshake was established
    public WebSocketProtocolHandshakeHandler(final HttpUpgradeListener callbackfinal HttpHandler next) {
        this. = null;
        Set<Handshakehandshakes = new HashSet<Handshake>();
        handshakes.add(new Hybi13Handshake());
        handshakes.add(new Hybi08Handshake());
        handshakes.add(new Hybi07Handshake());
        this. = handshakes;
        this. = next;
        this. = callback;
    }


    
Create a new WebSocketProtocolHandshakeHandler

Parameters:
handshakes The supported handshake methods
callback The WebSocketConnectionCallback which will be executed once the handshake was established
    public WebSocketProtocolHandshakeHandler(Collection<Handshakehandshakesfinal HttpUpgradeListener callback) {
        this(handshakescallback.);
    }

    
Create a new WebSocketProtocolHandshakeHandler

Parameters:
handshakes The supported handshake methods
callback The WebSocketConnectionCallback which will be executed once the handshake was established
    public WebSocketProtocolHandshakeHandler(Collection<Handshakehandshakesfinal HttpUpgradeListener callbackfinal HttpHandler next) {
        this. = null;
        this. = new HashSet<Handshake>(handshakes);
        this. = next;
        this. = callback;
    }
    @Override
    public void handleRequest(final HttpServerExchange exchangethrows Exception {
        if (!exchange.getRequestMethod().equals(.)) {
            // Only GET is supported to start the handshake
            .handleRequest(exchange);
            return;
        }
        final AsyncWebSocketHttpServerExchange facade = new AsyncWebSocketHttpServerExchange(exchange);
        Handshake handshaker = null;
        for (Handshake method : ) {
            if (method.matches(facade)) {
                handshaker = method;
                break;
            }
        }
        if (handshaker == null) {
            .handleRequest(exchange);
        } else {
            final Handshake selected = handshaker;
            if ( == null) {
                exchange.upgradeChannel(new HttpUpgradeListener() {
                    @Override
                    public void handleUpgrade(StreamConnection streamConnectionHttpServerExchange exchange) {
                        WebSocketChannel channel = selected.createChannel(facadestreamConnectionfacade.getBufferPool());
                        .onConnect(facadechannel);
                    }
                });
            } else {
                exchange.upgradeChannel();
            }
            handshaker.handshake(facade);
        }
    }
New to GrepCode? Check out our FAQ X