Note that there are some explanatory texts on larger screens.

plurals
  1. POJetty 8.1.9.v20130131 Web Socket issues
    primarykey
    data
    text
    <p>I do have a strange problem with jetty 8 websockets. I found several tutorials that pretty much show the same code, yet I get this error when I try to open the websocket from a local html page:</p> <pre><code>2013-02-05 13:14:03.467:INFO:oejs.Server:jetty-8.1.9.v20130131 2013-02-05 13:14:03.770:INFO:oejs.AbstractConnector:Started SelectChannelConnector@0.0.0.0:8080 2013-02-05 13:14:18.002:WARN:oejs.ServletHandler:/echo java.lang.NullPointerException at org.eclipse.jetty.websocket.WebSocketFactory.upgrade(WebSocketFactory.java:236) at org.eclipse.jetty.websocket.WebSocketFactory.acceptWebSocket(WebSocketFactory.java:382) at org.eclipse.jetty.websocket.WebSocketServlet.service(WebSocketServlet.java:104) at javax.servlet.http.HttpServlet.service(HttpServlet.java:848) at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:669) at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:457) at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:137) </code></pre> <p>Here is the Socket servlet:</p> <pre class="lang-java prettyprint-override"><code>public class ExampleWebSocketServlet extends WebSocketServlet { private static final long serialVersionUID = 1L; /** * @see WebSocketServlet#WebSocketServlet() */ public ExampleWebSocketServlet() { super(); } protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { PrintWriter out = response.getWriter(); out.println("OK"); out.close(); System.out.println("OK"); } protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { getServletContext().getNamedDispatcher("default").forward(request, response); } public WebSocket doWebSocketConnect(HttpServletRequest request, String protocol) { return new EchoWebSocket(); } } </code></pre> <p>and the WebSocket (for a simple Echo)</p> <pre class="lang-java prettyprint-override"><code>public class EchoWebSocket implements WebSocket.OnTextMessage { private Connection con; @Override public void onClose(int closeCode, String message) { } @Override public void onOpen(Connection con) { this.con = con; try { con.sendMessage("Server received Web Socket upgrade ..."); } catch (IOException e) { e.printStackTrace(); } } @Override public void onMessage(String msg) { System.out.println("Received: "+msg); try { con.sendMessage(msg); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } //send it back } } </code></pre> <p>My html page works fine with other websocket test servers, e.g. websocket.org</p> <p>What could be wrong? I am on Eclipse, created a dynamic web project and use the jetty webapp run configuration. Also, when jetty starts up i can see that </p> <p>/Users/sven.haiges/dev/jetty/jetty-distribution-8.1.9.v20130131/lib/jetty-websocket-8.1.9.v20130131.jar</p> <p>is on the classpath. </p> <p>Any help appreciated,thx!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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