WebSockets for GWT
Пытаюсь реализовать простой пример соединения. Может кто глазами ошибку увидит?
Client
| Код | package ru.test.client;
import com.google.gwt.core.client.EntryPoint; import com.google.gwt.core.client.GWT; import com.google.gwt.user.client.ui.RootPanel; import com.google.gwt.user.client.ui.TextArea; import com.google.gwt.user.client.ui.VerticalPanel; import de.csenk.gwt.ws.client.WebSocketConnection; import de.csenk.gwt.ws.client.js.JavaScriptWebSocket; import de.csenk.gwt.ws.client.js.JavaScriptWebSocketFactory; import de.csenk.gwt.ws.shared.Connection; import de.csenk.gwt.ws.shared.Handler;
public class webSocketEntryPoint implements EntryPoint {
public webSocketEntryPoint() { }
@Override public void onModuleLoad() { final TextArea ta = new TextArea(); ta.setCharacterWidth(100); ta.setVisibleLines(50); ta.setText("Test WebSocket connection"); if (!JavaScriptWebSocket.IsSupported()) return; //webSocketURL looks like "ws://127.0.0.1:8888/de_csenk_gwtws_demo/webSocket" String webSocketURL = GWT.getModuleBaseURL().replace("http", "ws") + "webSocket"; ta.setText(ta.getText() + "\ngetModuleBaseURL - " + webSocketURL); webSocketURL = "ws://127.0.0.1:8080/WebSocketTest2/ru_test_server/webSocket"; ta.setText(ta.getText() + "\nMyURL - " + webSocketURL); Handler handler = new Handler() {
@Override public void onConnectionClosed(Connection connection) throws Exception { ta.setText(ta.getText() + "\n" + "Client connection close"); }
@Override public void onConnectionOpened(Connection connection) throws Exception { String msg = "Hello world"; ta.setText(ta.getText() + "\n" + msg); connection.send(msg); }
@Override public void onExceptionCaught(Connection connection, Throwable caught) { ta.setText(ta.getText() + "\nClient Caught: " + caught.getMessage()); }
@Override public void onMessageReceived(Connection connection, Object message) throws Exception { ta.setText(ta.getText() + "\n" + message); } }; // JavaScriptWebSocketConnection webSocketConnection = // new JavaScriptWebSocketConnection(webSocketURL, handler); Connection webSocketClient = new WebSocketConnection(webSocketURL, handler, new JavaScriptWebSocketFactory()); VerticalPanel panel = new VerticalPanel(); panel.add(ta); RootPanel.get().add(panel); } }
|
Server
| Код | package ru.test.server;
import de.csenk.gwt.ws.server.jetty.JettyWebSocketConnection; import de.csenk.gwt.ws.shared.Connection; import de.csenk.gwt.ws.shared.Handler; import javax.servlet.http.HttpServletRequest; import org.eclipse.jetty.websocket.WebSocket; import org.eclipse.jetty.websocket.WebSocketServlet;
public class WebSocketServletImpl extends WebSocketServlet {
private static final long serialVersionUID = 5565068884455990101L;
@Override protected WebSocket doWebSocketConnect(HttpServletRequest arg0, String arg1) { return new JettyWebSocketConnection(new Handler() {
@Override public void onConnectionClosed(Connection connection) throws Exception { System.out.println("Server connection close"); }
@Override public void onConnectionOpened(Connection connection) throws Exception { System.out.println("Server connection open"); }
@Override public void onExceptionCaught(Connection connection, Throwable caught) { System.out.println("Server Caught: " + caught.getMessage()); }
@Override public void onMessageReceived(Connection connection, Object message) throws Exception { System.out.println("Server received:" + message); }
}); }
}
|
webSocket.gwt.xml
| Код | <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE module PUBLIC "-//Google Inc.//DTD Google Web Toolkit 1.7.0//EN" "http://google-web-toolkit.googlecode.com/svn/tags/1.7.0/distro-source/core/src/gwt-module.dtd">
<module> <inherits name="com.google.gwt.user.User"/> <inherits name='de.csenk.gwt.ws.WebSocket' /> <entry-point class="ru.test.client.webSocketEntryPoint"/> </module>
|
web.xml
| Код | <?xml version="1.0" encoding="UTF-8"?> <web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" 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_3_0.xsd"> <servlet> <servlet-name>webSocket</servlet-name> <servlet-class>ru.test.server.WebSocketServletImpl</servlet-class> </servlet>
<servlet-mapping> <servlet-name>webSocket</servlet-name> <url-pattern>/ru_test_server/webSocket</url-pattern> </servlet-mapping> <session-config> <session-timeout> 30 </session-timeout> </session-config> <welcome-file-list> <welcome-file>welcomeGWT.html</welcome-file> </welcome-file-list> </web-app>
|
Использую: GWT2.6.0 TomCat 7.0.53.0 de.csenk.gwt.jetty-7.1.6.v20100715.jar - просят добавить в проект на https://code.google.com/p/gwt-ws/ de.csenk.gwt.ws_v0.0.1.67.jar - просят добавить в проект на https://code.google.com/p/gwt-ws/
В итоге получаю сообщение об ошибке не стороне клиента:
| Код | Test WebSocket connection MyURL - ws://127.0.0.1:8080/WebSocketTest2/ru_test_server/webSocket Client Caught: JavaScript implementation of WebSocket thrown an unknown exception. Client connection close
|
Добавлено через 1 минуту и 57 секунд Прикрепил сам проект в архиве. NetBeans. |