 <p>Trying to do something similar to allow WS calls to an embedded Jetty REST API...here's my echo test code (Jetty 7), HTH</p> <pre><code> public class myApiSocketServlet extends WebSocketServlet { protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException ,IOException { OutputStream responseBody = response.getOutputStream(); responseBody.write("Socket API".getBytes()); responseBody.close(); } public WebSocket doWebSocketConnect(HttpServletRequest request, String protocol) { return new APIWebSocket(); } class APIWebSocket implements WebSocket, WebSocket.OnTextMessage { Connection connection; @Override public void onClose(int arg0, String arg1) { } @Override public void onOpen(Connection c) { connection = c; } @Override public void onMessage(String msg) { try { this.connection.sendMessage("I received: " + msg); } catch (Exception e) { e.printStackTrace(); } } } } </code></pre>