我尝试使用 Jetty 8.1.8 和 Netty 3.2.7 在 JBOSS 上创建一个 websocket servlet 我正在使用一个与 Tomcat 配合使用的客户端,所以我不认为这是我在尝试连接到服务器端 websocket servlet 异常发生在 Jetty 的“WebSocketFactory.java”文件中以下行之后: AbstractHttpConnection http AbstractHttpConnection.getCurrentConnection() getCurrentConnection 函数返回 null 并遵循这一行尝试使用其函数之一(这显然会引发异常) .
这是我的代码:包 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 错误 [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/benAsync].[AsynchServlet]] (http-localhost/127.0.0.1:8080-7 ) JBWEB000236:Servlet AsynchServlet 的 Servlet.service() 抛出异常:java.lang.NullPointerException at org.eclipse.jetty.websocket.WebSocketFactory.upgrade(WebSocketFactory.java:225) [jetty-all-7.6.2.v20120308.jar :7.6.2.v20120308] 在 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) [类:] 在 javax.servlet.http.HttpServlet。服务(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。调用(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] 在 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] at 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] at java.lang.Thread.run(Unknown Source) [rt.jar: 1.6.0_33]
任何可能对我有帮助的帮助或方向将不胜感激,谢谢!:)