Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package io.undertow.servlet.websockets;
  
 
 import java.util.List;

Author(s):
Stuart Douglas
 
 public class WebSocketServlet extends HttpServlet {
 
     public static final String SESSION_HANDLER = "io.undertow.handler";
 
     private final List<Handshakehandshakes;
 
 
     public WebSocketServlet() {
         this. = handshakes();
     }
 
     public WebSocketServlet(WebSocketConnectionCallback callback) {
         this. = callback;
         this. = handshakes();
     }
 
 
     @Override
     public void init(final ServletConfig configthrows ServletException {
         super.init(config);
         try {
             final String sessionHandler = config.getInitParameter();
             if (sessionHandler != null) {
                 final Class<?> clazz = Class.forName(sessionHandlertrue, Thread.currentThread().getContextClassLoader());
                 final Object handler = clazz.newInstance();
                 this. = (WebSocketConnectionCallbackhandler;
             }
             //TODO: set properties based on init params
 
         } catch (ClassNotFoundException e) {
             throw new ServletException(e);
         } catch (InstantiationException e) {
             throw new ServletException(e);
         } catch (IllegalAccessException e) {
             throw new ServletException(e);
         }
         if ( == null) {
             throw ..noWebSocketHandler();
         }
     }
 
     @Override
     protected void doGet(final HttpServletRequest reqfinal HttpServletResponse respthrows ServletExceptionIOException {
 
         final ServletWebSocketHttpExchange facade = new ServletWebSocketHttpExchange(reqresp);
         Handshake handshaker = null;
         for (Handshake method : ) {
             if (method.matches(facade)) {
                 handshaker = method;
                 break;
             }
         }
 
         if (handshaker == null) {
             ..debug("Could not find hand shaker for web socket request");
             resp.sendError(400);
             return;
         }
         final Handshake selected = handshaker;
         facade.upgradeChannel(new HttpUpgradeListener() {
             @Override
             public void handleUpgrade(StreamConnection streamConnectionHttpServerExchange exchange) {
                 WebSocketChannel channel = selected.createChannel(facadestreamConnectionfacade.getBufferPool());
                 .onConnect(facadechannel);
             }
         });
         handshaker.handshake(facade);
     }
 
     protected List<Handshakehandshakes() {
         List<Handshakehandshakes = new ArrayList<Handshake>();
         handshakes.add(new Hybi13Handshake());
        handshakes.add(new Hybi08Handshake());
        handshakes.add(new Hybi07Handshake());
        return handshakes;
    }
New to GrepCode? Check out our FAQ X