GWT Jetty WebSockets 405错误
我试图修改标准的GWT演示应用程序,通过websocket接收股票报价。我正在使用websockets实现,根据gwt ws主页,我升级了gwt的嵌入式Jetty版本 然而,当我尝试打开websocket连接时,我得到以下405错误。有人有什么建议吗GWT Jetty WebSockets 405错误,gwt,jetty,websocket,Gwt,Jetty,Websocket,我试图修改标准的GWT演示应用程序,通过websocket接收股票报价。我正在使用websockets实现,根据gwt ws主页,我升级了gwt的嵌入式Jetty版本 然而,当我尝试打开websocket连接时,我得到以下405错误。有人有什么建议吗 [WARN] 405 - GET /stockwatcher/webSocket (127.0.0.1) 1457 bytes Request headers Upgrade: websocket Connection
[WARN] 405 - GET /stockwatcher/webSocket (127.0.0.1) 1457 bytes
Request headers
Upgrade: websocket
Connection: Upgrade
Host: 127.0.0.1:8888
Origin: http://127.0.0.1:8888
Sec-WebSocket-Key: zlH08kgvDw3qHs+/OaQ9/w==
Sec-WebSocket-Version: 13
Sec-WebSocket-Extensions: x-webkit-deflate-frame
Response headers
Content-Type: text/html;charset=ISO-8859-1
Cache-Control: must-revalidate,no-cache,no-store
Content-Length: 1457
下面是我的客户端websocket代码,从onModuleLoad()调用:
我在网页上看到“Web套接字连接已关闭”
这是我的Servlet:
package com.google.gwt.sample.stockwatcher.StockWatcher.server;
import javax.servlet.http.HttpServletRequest;
import org.eclipse.jetty.websocket.WebSocket;
import de.csenk.gwt.ws.server.jetty.JettyWebSocketConnection;
import de.csenk.gwt.ws.shared.Connection;
import de.csenk.gwt.ws.shared.Handler;
public class MyWebSocketServlet extends org.eclipse.jetty.websocket.WebSocketServlet {
public static final long serialVersionUID = 1;
protected WebSocket doWebSocketConnect(HttpServletRequest arg0, String arg1) {
return new JettyWebSocketConnection(new Handler() {
public void onConnectionOpened(Connection connection) throws Throwable {
System.out.println("Connection opened server side");
}
public void onConnectionClosed(Connection connection) throws Throwable {
System.out.println("Connection closed server side");
}
public void onExceptionCaught(Connection connection, Throwable caught) {
System.out.println("exception caught server side");
caught.printStackTrace(System.out);
}
public void onMessageReceived(Connection connection, Object message) throws Throwable {
System.out.println("Message Received! " + message);
}
});
}
}
下面是StockWatcher.gwt.xml
<?xml version="1.0" encoding="UTF-8"?>
<module rename-to='stockwatcher'>
<!-- Inherit the core Web Toolkit stuff. -->
<inherits name='com.google.gwt.user.User'/>
<!-- Inherit the default GWT style sheet. You can change -->
<!-- the theme of your GWT application by uncommenting -->
<!-- any one of the following lines. -->
<!-- <inherits name='com.google.gwt.user.theme.clean.Clean'/> -->
<inherits name='com.google.gwt.user.theme.standard.Standard'/>
<!-- <inherits name='com.google.gwt.user.theme.chrome.Chrome'/> -->
<!-- <inherits name='com.google.gwt.user.theme.dark.Dark'/> -->
<!-- Other module inherits -->
<inherits name='de.csenk.gwt.ws.WebSocket'/>
<!-- Specify the app entry point class. -->
<entry-point class='com.google.gwt.sample.stockwatcher.StockWatcher.client.StockWatcher'/>
<!-- Specify the paths for translatable code -->
<source path='client'/>
<source path='shared'/>
</module>
下面是web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
version="2.5"
xmlns="http://java.sun.com/xml/ns/javaee">
<!-- Servlets -->
<servlet>
<servlet-name>webSocket</servlet-name>
<servlet-class>com.google.gwt.sample.stockwatcher.StockWatcher.server.MyWebSocketServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>webSocket</servlet-name>
<url-pattern>/stockwatcher/webSocket</url-pattern>
</servlet-mapping>
<!-- Default page to serve -->
<welcome-file-list>
<welcome-file>StockWatcher.html</welcome-file>
</welcome-file-list>
</web-app>
网袋
com.google.gwt.sample.stockwatcher.stockwatcher.server.MyWebSocketServlet
网袋
/股票观察家/网袋
StockWatcher.html
WebSocket协议自其早期版本以来发生了很大变化,gwt ws和gwt Jetty使用的Jetty版本(7.1.6)都很旧(2010年秋季),可能太旧了。gwt-ws是谷歌第二次推出“gwt WebSocket”的热门产品。有些令人害怕的是,一些过时的、破损的东西仍然会排名很高。这是否意味着做GWT的人都没有在玩websockets?ApacheWave使用websockets。他们用JSNI做了自己的包装。或者看看勘误表。或使用CometD@Github通过JSNI。如果你成功了,请告诉我。有人解决了这个问题吗?
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
version="2.5"
xmlns="http://java.sun.com/xml/ns/javaee">
<!-- Servlets -->
<servlet>
<servlet-name>webSocket</servlet-name>
<servlet-class>com.google.gwt.sample.stockwatcher.StockWatcher.server.MyWebSocketServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>webSocket</servlet-name>
<url-pattern>/stockwatcher/webSocket</url-pattern>
</servlet-mapping>
<!-- Default page to serve -->
<welcome-file-list>
<welcome-file>StockWatcher.html</welcome-file>
</welcome-file-list>
</web-app>