尝试在JBOSS上使用带有Jetty 8.1.8&的JBOSS的WebSockets时出错Netty 3.2.7

时间:2013-04-08 08:35:18

标签: websocket jetty jboss7.x netty

我试图在JBOSS上使用Jetty 8.1.8& amp;创建一个websocket servlet。 Netty 3.2.7 我正在使用一个与Tomcat一起工作的客户端,所以我不认为这是问题所在 每当我尝试连接到服务器端websocket servlet时,我都会收到Null指针异常 Jetty的“WebSocketFactory.java”文件中发生异常 在以下行之后:     AbstractHttpConnection http AbstractHttpConnection.getCurrentConnection() getCurrentConnection函数返回null,并在此行之后尝试使用其中一个函数(显然会抛出异常)。

这是我的代码:     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.OnTextMessage
          {
                    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)
                    {

                   }
         }

}

以下是例外:

  

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的Servlet.service()AsynchServlet抛出异常:java.lang.NullPointerException             在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]             在org.eclipse.jetty.websocket.WebSocketServlet.service(WebSocketServlet.java:107)[jetty-all-7.6.2.v20120308.jar:7.6.2.v20120308]             在com.benPackage.entrypoint.servlets.OWMFAsyncJboss.service(OWMFAsyncJboss.java:58)[classes:]             在javax.servlet.http.HttpServlet.service(HttpServlet.java:847)[jboss-servlet-api_3.0_spec-1.0.2.Final.jar:1.0.2.Final]             在org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:295)[jbossweb-7.2.0.Final.jar:7.2.0.Final]             在org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:214)[jbossweb-7.2.0.Final.jar:7.2.0.Final]             在org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230)[jbossweb-7.2.0.Final.jar:7.2.0.Final]             在org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:149)[jbossweb-7.2.0.Final.jar:7.2.0.Final]             在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]             在org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:145)[jbossweb-7.2.0.Final.jar:7.2.0.Final]             在org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:97)[jbossweb-7.2.0.Final.jar:7.2.0.Final]             在org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:102)[jbossweb-7.2.0.Final.jar:7.2.0.Final]             在org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:336)[jbossweb-7.2.0.Final.jar:7.2.0.Final]             在org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:856)[jbossweb-7.2.0.Final.jar:7.2.0.Final]             在org.apache.coyote.http11.Http11Protocol $ Http11ConnectionHandler.process(Http11Protocol.java:653)[jbossweb-7.2.0.Final.jar:7.2.0.Final]             在org.apache.tomcat.util.net.JIoEndpoint $ Worker.run(JIoEndpoint.java:920)[jbossweb-7.2.0.Final.jar:7.2.0.Final]             在java.lang.Thread.run(未知来源)[rt.jar:1.6.0_33]

任何可以帮助我的帮助或方向都将受到赞赏 谢谢 ! :)

1 个答案:

答案 0 :(得分:0)

两个问题。

首先,您在问题中说您正在使用Jetty 8.1.8,但您的堆栈跟踪显示您正在使用Jetty 7.6.2.v20120308。

接下来,jetty-websocket需要访问Jetty内部连接升级机制才能打破Servlet API规范。在您所描述的混合JBoss + Jetty环境中无法实现的功能。

解决方案可能是在同一台机器上的不同端口上运行Jetty,只需将UPGRADE请求代理到另一个Jetty实例。但是JBoss对UPGRADE请求和101 Switching Protocols响应的支持非常有限。