Note that there are some explanatory texts on larger screens.

plurals
  1. POTomcat throws AbstractMethodError for WebSocketServlet.createWebSocketInbound() when custom servlet runs
    text
    copied!<p>I work on a project in which I need to create a real time web application. I've developed a small program to test WebSockets with Apache Tomcat, but it doesn't work and instead throws an <code>AbstractMethodError</code> exception. The servlet compiles and the web application deploys fine.</p> <p>Here's the servlet's code.</p> <pre><code>public class TestWebSocket extends WebSocketServlet { private static final long serialVersionUID = 1L; @Override protected boolean verifyOrigin(String origin) { System.out.println("Origin: {}" + origin); return true; } @Override protected StreamInbound createWebSocketInbound(String subProtocol, HttpServletRequest request) { return new WebSocketConnection(); } private static class WebSocketConnection extends MessageInbound { @Override protected void onOpen(WsOutbound outbound) { System.out.println("Conexión abierta"); } @Override protected void onClose(int status) { System.out.println("Conexión cerrada"); } @Override protected void onBinaryMessage(ByteBuffer byteBuffer) throws IOException { System.out.println("No se soportan mensajes binarios"); throw new UnsupportedOperationException("No se soportan mensajes binarios"); } @Override protected void onTextMessage(CharBuffer charBuffer) throws IOException { final String user = charBuffer.toString(); System.out.println("Mensaje recibido: {}" + user); getWsOutbound().writeTextMessage(CharBuffer.wrap("Hola " + user + " desde WebSocket")); } } } </code></pre> <p>Here goes the deployment descriptor - <code>web.xml</code></p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0"&gt; &lt;display-name&gt;TestWebSocket&lt;/display-name&gt; &lt;servlet&gt; &lt;servlet-name&gt;TestWebSocket&lt;/servlet-name&gt; &lt;servlet-class&gt;com.test.TestWebSocket&lt;/servlet-class&gt; &lt;/servlet&gt; &lt;servlet-mapping&gt; &lt;servlet-name&gt;TestWebSocket&lt;/servlet-name&gt; &lt;url-pattern&gt;/testWebSocket&lt;/url-pattern&gt; &lt;/servlet-mapping&gt; &lt;/web-app&gt; </code></pre> <p>And the client code - <code>testSocket.js</code>:</p> <pre><code>/* * For Testing websockets */ $(function(){ console.log("URL :" + 'ws://' + location.host + '/TestTomcatWebSocket/testWebSocket'); var ws = new WebSocket('ws://' + location.host + '/TestTomcatWebSocket/testWebSocket'); ws.onopen = function() { console.log("Websocket Ready!!"); sendMessage(); }; ws.onmessage= function(data) { console.log("message received : " + data); }; function sendMessage() { ws.send("Test"); }; }); </code></pre> <p>Upon execution the application finishes with the following <code>java.lang.AbstractMethodError</code> exception:</p> <pre><code>INFO: Server startup in 495 ms Origin: {}http://localhost:8080 Dec 17, 2012 1:58:51 AM org.apache.catalina.core.StandardWrapperValve invoke SEVERE: Servlet.service() for servlet [TestWebSocket] in context with path [/TestTomcatWebSocket] threw exception [Servlet execution threw an exception] with root cause java.lang.AbstractMethodError: org.apache.catalina.websocket.WebSocketServlet.createWebSocketInbound(Ljava/lang/String;)Lorg/apache/catalina/websocket/StreamInbound; at org.apache.catalina.websocket.WebSocketServlet.doGet(WebSocketServlet.java:125) at javax.servlet.http.HttpServlet.service(HttpServlet.java:621) at javax.servlet.http.HttpServlet.service(HttpServlet.java:722) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:225) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:169) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98) at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:927) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407) at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:999) at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:565) at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:307) at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) at java.lang.Thread.run(Unknown Source) </code></pre> <p>I use Apache Tomcat 7.0.33.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload