001/* 002 * $Id: AjaxRestWebsocketListener.java 997 2015-08-21 00:06:40Z tgutwin $ 003 * $HeadURL: $ 004 * $Revision: 997 $ 005 * $LastChangedDate: 2015-08-20 17:06:40 -0700 (Thu, 20 Aug 2015) $ 006 * $LastChangedBy: tgutwin $ 007 * Copyright (c) 2017 Tom B. Gutwin P.Eng. North Vancouver BC Canada 008 * 009 * This program is free software; you can redistribute it and/or 010 * modify it under the terms of the GNU General Public License 011 * as published by the Free Software Foundation; either version 3 012 * of the License, or any later version. 013 * 014 * This program is distributed in the hope that it will be useful, 015 * but WITHOUT ANY WARRANTY; without even the implied warranty of 016 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 017 * GNU General Public License for more details. 018 * 019 * You should have received a copy of the GNU General Public License 020 * along with this program; If not, see <http://www.gnu.org/licenses/>. 021 */ 022 023package ca.bc.webarts.servlet; 024 025import javax.servlet.annotation.WebServlet; 026 027import org.eclipse.jetty.websocket.servlet.WebSocketServlet; 028import org.eclipse.jetty.websocket.servlet.WebSocketServletFactory; 029 030/** 031 * TomsWebSocketEchoServlet is a basic WebSocket server implemented in a servlet. 032 * 033 * When you want a custom WebSocketCreator, use WebSocketServletFactory.setCreator(WebSocketCreator creator) and the 034 * WebSocketServletFactory will use your creator for all incoming Upgrade requests on this servlet. 035<br> 036<ul>Other uses for a WebSocketCreator: 037 038 <li>Controlling the selection of WebSocket subprotocol</li> 039 <li>Performing any WebSocket origin you deem important</li> 040 <li>Obtaining the HTTP headers from incoming request</li> 041 <li>Obtaining the Servlet HttpSession object (if it exists)</li> 042 <li>Specifying a response status code and reason</li> 043</ul) 044**/ 045//@SuppressWarnings("serial") 046// @WebServlet(name = "Toms Echo WebSocket Servlet", urlPatterns = { "/advecho" }) // define these in the web.xml 047public class TomsWebSocketEchoServlet extends WebSocketServlet 048{ 049 public static boolean debugOut = true; 050 051 052 @Override 053 public void configure(WebSocketServletFactory factory) 054 { 055 if (debugOut) System.out.println("TomsWebSocketEchoServlet.configure()"); 056 057 // set a 10 second timeout 058 //factory.getPolicy().setIdleTimeout(10000); 059 060 // register a very basic socketListener 061 factory.register(TomsEventSocket.class); 062 063 // set a custom WebSocket creator 064 //factory.setCreator(new TomsEchoCreator()); 065 } 066}