Issues with Jetty Server 8.1.9.v20130131

I have a weird problem with websockets 8 berth. I have found several tutorials that pretty much show the same code, but I get this error when I try to open a website from a local html page:

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)

      

Here is the Socket Servlet:

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();
    }
}

      

and WebSocket (for a simple Echo)

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

    }
}

      

My html page works fine with other websocket test servers eg. websocket.org

What could be wrong? I am in Eclipse, creating a dynamic web project and using a jetty run configuration. Also, when the pier starts, I see that

/Users/sven.haiges/dev/jetty/jetty-distribution-8.1.9.v20130131/lib/jetty-websocket-8.1.9.v20130131.jar

is in the classpath.

Any help is appreciated, thanks!

+3


source to share


2 answers


I had the same problem with the Run Jetty Run plugin. finally found a solution. go to launch configuration

  • select the project name under the webapp in the left pane.
  • select Jetty 8.1 on the right side of the Jetty tab.


Apply / execute that's all

+2


source


Try using Jetty 8.1.8. Today I ran into the problem of creating a simple servlet using the @WebServlet annotation. The pier did not answer and I could not understand why. But when I suddenly went back to version 8.1.8 everything worked fine. Perhaps this is a similar problem.



+1


source







All Articles