2 Replies Latest reply on Apr 9, 2013 3:35 AM by jfclere

    error when using WebSockets with Netty 3.2.7 & Jetty 8.1

    ben1234

      Hi,

      I have encountered some issues while trying to create the server side webSockets(I know that the client side works becase when i redirect it to a tomcat server everything is good)

      I am recieving the following error message:

       

      17:36:01,728 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/benAsync].[AsynchServlet]] (http-localhost/127.0.0.1:8080-7) JBWEB000236: Servlet.service() for servlet AsynchServlet threw exception: java.lang.NullPointerException

                at org.eclipse.jetty.websocket.WebSocketFactory.upgrade(WebSocketFactory.java:225) [jetty-all-7.6.2.v20120308.jar:7.6.2.v20120308]

                at org.eclipse.jetty.websocket.WebSocketFactory.acceptWebSocket(WebSocketFactory.java:361) [jetty-all-7.6.2.v20120308.jar:7.6.2.v20120308]

                at org.eclipse.jetty.websocket.WebSocketServlet.service(WebSocketServlet.java:107) [jetty-all-7.6.2.v20120308.jar:7.6.2.v20120308]

                at com.benPackage.entrypoint.servlets.OWMFAsyncJboss.service(OWMFAsyncJboss.java:58) [classes:]

                at javax.servlet.http.HttpServlet.service(HttpServlet.java:847) [jboss-servlet-api_3.0_spec-1.0.2.Final.jar:1.0.2.Final]

                at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:295) [jbossweb-7.2.0.Final.jar:7.2.0.Final]

                at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:214) [jbossweb-7.2.0.Final.jar:7.2.0.Final]

                at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230) [jbossweb-7.2.0.Final.jar:7.2.0.Final]

                at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:149) [jbossweb-7.2.0.Final.jar:7.2.0.Final]

                at org.jboss.as.web.security.SecurityContextAssociationValve.invoke(SecurityContextAssociationValve.java:169) [jboss-as-web-7.2.0.Alpha1-redhat-4.jar:7.2.0.Alpha1-redhat-4]

                at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:145) [jbossweb-7.2.0.Final.jar:7.2.0.Final]

                at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:97) [jbossweb-7.2.0.Final.jar:7.2.0.Final]

                at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:102) [jbossweb-7.2.0.Final.jar:7.2.0.Final]

                at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:336) [jbossweb-7.2.0.Final.jar:7.2.0.Final]

                at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:856) [jbossweb-7.2.0.Final.jar:7.2.0.Final]

                at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:653) [jbossweb-7.2.0.Final.jar:7.2.0.Final]

                at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:920) [jbossweb-7.2.0.Final.jar:7.2.0.Final]

                at java.lang.Thread.run(Unknown Source) [rt.jar:1.6.0_33]

       

       

      17:37:39,237 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/benAsync].[AsynchServlet]] (http-localhost/127.0.0.1:8080-2) JBWEB000236: Servlet.service() for servlet AsynchServlet threw exception: java.lang.NullPointerException

                at org.eclipse.jetty.websocket.WebSocketFactory.upgrade(WebSocketFactory.java:225) [jetty-all-7.6.2.v20120308.jar:7.6.2.v20120308]

                at org.eclipse.jetty.websocket.WebSocketFactory.acceptWebSocket(WebSocketFactory.java:361) [jetty-all-7.6.2.v20120308.jar:7.6.2.v20120308]

                at org.eclipse.jetty.websocket.WebSocketServlet.service(WebSocketServlet.java:107) [jetty-all-7.6.2.v20120308.jar:7.6.2.v20120308]

                at com.benPackage.entrypoint.servlets.OWMFAsyncJboss.service(OWMFAsyncJboss.java:58) [classes:]

                at javax.servlet.http.HttpServlet.service(HttpServlet.java:847) [jboss-servlet-api_3.0_spec-1.0.2.Final.jar:1.0.2.Final]

                at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:295) [jbossweb-7.2.0.Final.jar:7.2.0.Final]

                at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:214) [jbossweb-7.2.0.Final.jar:7.2.0.Final]

                at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230) [jbossweb-7.2.0.Final.jar:7.2.0.Final]

                at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:149) [jbossweb-7.2.0.Final.jar:7.2.0.Final]

                at org.jboss.as.web.security.SecurityContextAssociationValve.invoke(SecurityContextAssociationValve.java:169) [jboss-as-web-7.2.0.Alpha1-redhat-4.jar:7.2.0.Alpha1-redhat-4]

                at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:145) [jbossweb-7.2.0.Final.jar:7.2.0.Final]

                at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:97) [jbossweb-7.2.0.Final.jar:7.2.0.Final]

                at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:102) [jbossweb-7.2.0.Final.jar:7.2.0.Final]

                at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:336) [jbossweb-7.2.0.Final.jar:7.2.0.Final]

                at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:856) [jbossweb-7.2.0.Final.jar:7.2.0.Final]

                at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:653) [jbossweb-7.2.0.Final.jar:7.2.0.Final]

                at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:920) [jbossweb-7.2.0.Final.jar:7.2.0.Final]

                at java.lang.Thread.run(Unknown Source) [rt.jar:1.6.0_33]

       

       

      Here is my Code:

       

      package com.microfocus.entrypoint.servlets;

       

       

      import java.io.IOException;

      import java.util.Set;

      import java.util.concurrent.CopyOnWriteArraySet;

      import javax.servlet.ServletException;

      import javax.servlet.http.HttpServletRequest;

      import javax.servlet.http.HttpServletResponse;

       

       

      import org.eclipse.jetty.websocket.WebSocket;

      import org.eclipse.jetty.websocket.WebSocketConnection;

      import org.eclipse.jetty.websocket.WebSocketServlet;

       

       

      @SuppressWarnings("serial")

      public class OWMFAsyncJboss extends WebSocketServlet {

       

       

                @SuppressWarnings({ "unchecked", "rawtypes" })

                private final Set<ChatWebSocket> users = new CopyOnWriteArraySet();

       

                @Override

                public WebSocket doWebSocketConnect(HttpServletRequest arg0, String arg1) {

                          try

                          {

                          return new ChatWebSocket();

                          }

                          catch(Exception e)

                          {

                                    System.console().writer().write("error");

                          }

                          return null;

                }

       

                @Override

                protected void service(HttpServletRequest request,

                                    HttpServletResponse response) throws ServletException, IOException {

                          super.service(request, response);

                }

       

                class ChatWebSocket implements WebSocket

                {

                          WebSocketConnection connection;

       

                          @Override

                          public void onClose(int arg0, String arg1) {

                                    users.remove(this);

                          }

       

                          @Override

                          public void onOpen(Connection arg0) {

                                    ChatWebSocket.this.connection= (WebSocketConnection) connection;

                                    users.add(this);

                          }

       

                          public void onMessage(byte frame, byte[] data,int offset, int length)

                          {

                          // binary communication not needed

                          }

                          public void onMessage(byte frame, String data)

                          {

       

                          }

                }

       

       

      }

       

      It is a code i took from a well proven sample

      the error occurrs after the "doWebSocketConnect" function returns the ChatWebSocket , for some reason it thinkgs that the chatWebSocket is empty :\

       

      If any of you can help me i will be very gratfull

      thanks