WAR文件中的WebSocketServlet:SelectChannelEndPoint的错误字符13

时间:2016-07-02 14:50:41

标签: servlets websocket jetty jetty-9 java-websocket

在Mac上使用Oracle java“1.8.0_45”我创建了一个Jetty基础目录:

for p in *
    cd $p
    do something
    cd -
end

然后我将非常简单的Maven项目产生的# java -jar /Users/afarber/jetty-distribution-9.3.10.v20160621/start.jar jetty.home=/Users/afarber/jetty-distribution-9.3.10.v20160621 jetty.base=/Users/afarber/jetty-base --add-to-startd=http,servlet,webapp,resources,ext,fcgi,websocket,proxy-protocol,deploy INFO: ext initialised in ${jetty.base}/start.d/ext.ini INFO: resources initialised in ${jetty.base}/start.d/resources.ini INFO: server initialised (transitively) in ${jetty.base}/start.d/server.ini INFO: http initialised in ${jetty.base}/start.d/http.ini INFO: servlet initialised in ${jetty.base}/start.d/servlet.ini INFO: fcgi initialised in ${jetty.base}/start.d/fcgi.ini INFO: proxy-protocol initialised in ${jetty.base}/start.d/proxy-protocol.ini INFO: webapp initialised in ${jetty.base}/start.d/webapp.ini INFO: websocket initialised in ${jetty.base}/start.d/websocket.ini MKDIR: ${jetty.base}/lib MKDIR: ${jetty.base}/lib/ext MKDIR: ${jetty.base}/resources MKDIR: ${jetty.base}/webapps INFO: Base directory was modified 放在 -

之外

WsServlet.java

$JETTY_BASE/webapps/ws-servlet-0.1-SNAPSHOT.war

EchoListener.java

public class WsServlet extends WebSocketServlet
{
    @Override
    public void configure(WebSocketServletFactory factory) {
        factory.register(EchoListener.class);
    }
}

最后,我创建了指向WAR文件的public class EchoListener implements WebSocketListener { private static final Logger LOG = Log.getLogger(EchoListener.class); private Session mSession; @Override public void onWebSocketConnect(Session session) { LOG.info("onWebSocketConnect {}", session); mSession = session; } @Override public void onWebSocketText(String message) { LOG.info("onWebSocketText {}", message); if (mSession != null && mSession.isOpen()) { mSession.getRemote().sendString("ECHO: " + message, null); } } } 文件:

$JETTY_BASE/webapps/ws.xml

当我启动Jetty,然后使用浏览器<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure_9_0.dtd"> <Configure class="org.eclipse.jetty.webapp.WebAppContext"> <Set name="contextPath">/ws</Set> <Set name="war"><SystemProperty name="jetty.base"/>/webapps/ws-servlet-0.1-SNAPSHOT.war</Set> </Configure> 中的简单JavaScript代码或Simple Web Socket Client extension for Chrome连接到它时出现错误:

var ws = new WebSocket("//127.0.0.1:8080/ws");

以下是the full Jetty log,我在这里错过了什么?

更新

我还尝试连接到# java -Dorg.eclipse.jetty.LEVEL=DEBUG -jar /Users/afarber/jetty-distribution-9.3.10.v20160621/start.jar jetty.base=/Users/afarber/jetty-base .... WARN:oejs.ProxyConnectionFactory:qtp1993134103-12: Bad character 13 for SelectChannelEndPoint@26ba5622{/127.0.0.1:49883<->8080,Open,in,out,-,-,0/30000,ProxyConnection@49376d8e}{io=1/0,kio=1,kro=1} 并尝试添加ws://127.0.0.1:8080/ws-servlet-0.1-SNAPSHOT之类的注释 - 但这没有用。我也尝试过旧版本9.3.9.v20160517。

更新2:

我的生产服务器必须使用PROXY Protocol的根本原因,因为我卸载了SSL和HAProxy的正常连接吗?从文档中我读到@WebServlet(name = "WsServlet", urlPatterns = { "/ws" })作为第一个字节发送。

更新3:

通过添加尾部斜杠来解决问题:13

0 个答案:

没有答案