I have a problem with WebSockets. Carried out by a Java development environment IntelliJ IDEA Community Edition 12.1.6 using Jetty 9.1.0 and Maven. I created two classes (code below). Class WsHandler:
public class WsHandler extends WebSocketHandler {
private final ConcurrentMap<String, Set<EventWebSocket>> eventsSubscribers = new ConcurrentHashMap<>();
@Override
public WebSocket doWebSocketConnect(HttpServletRequest request, String protocol) {
return new EventWebSocket();
}
private void fireEvent(String eventName) {
Set<EventWebSocket> subscribers = eventsSubscribers.get(eventName);
System.out.println("Event " + eventName + " was occurred. Subscribers " + subscribers);
if (subscribers != null) {
for (EventWebSocket webSocket : subscribers) {
webSocket.onEvent(eventName);
}
}
}
public final class EventWebSocket implements WebSocket.OnTextMessage {
private Connection connection;
private List<String> subscribedEvents = new LinkedList();
@Override
public void onOpen(Connection connection) {
System.out.println("Open connection " + connection);
this.connection = connection;
}
@Override
public void onMessage(String data) {
System.out.println("Process msg: " + data);
if (data.isEmpty()) return;
if (data.startsWith("Sub")) { // subscribe
if (data.length() < 5) return;
String eventName = data.split(":")[1]; // subscribing message format "Sub:EventName"
Set<EventWebSocket> subscribers = eventsSubscribers.get(eventName);
// double-check idiom for lazy initialization
if (subscribers == null) {
synchronized (EventHandler.class) {
if (eventsSubscribers.get(eventName) == null) {
subscribers = new CopyOnWriteArraySet<>();
eventsSubscribers.putIfAbsent(eventName, subscribers);
}
}
}
subscribers.add(this);
subscribedEvents.add(eventName);
} else if (data.startsWith("Fire")) { // fire event
if (data.length() < 6) return;
String eventName = data.split(":")[1]; // Fire event message format "Fire:EventName"
fireEvent(eventName);
} else {
try {
connection.sendMessage("Unknown command: " + data);
} catch (IOException ex) {
System.err.println("Ooops: " + ex + ". Close connection " + connection);
}
}
}
public void onEvent(String eventName) {
try {
connection.sendMessage("Event " + eventName + " was occurred");
} catch (IOException ex) {
System.err.println("Ooops: " + ex + ". Close connection " + connection);
}
}
@Override
public void onClose(int closeCode, String message) {
System.out.println("Close connection " + connection);
// remove from subscribers
for (String eventName : subscribedEvents) {
eventsSubscribers.get(eventName).remove(this);
}
}
}}
Class SimpleEchoClien:
public class SimpleEchoClient {
public static void main(String[] args) throws Exception {
Server server = new Server(8080);
WsHandler handler = new WsHandler();
server.setHandler(handler);
server.start();
server.join();
}}
Run and get the error:
"C:\Program Files\Java\jdk1.7.0_17\bin\java" -Didea.launcher.port=7532 "-Didea.launcher.bin.path=C:\Program Files (x86)\JetBrains\IntelliJ IDEA Community Edition 12.1.6\bin" -Dfile.encoding=UTF-8 -classpath "C:\Program Files\Java\jdk1.7.0_17\jre\lib\charsets.jar;C:\Program Files\Java\jdk1.7.0_17\jre\lib\deploy.jar;C:\Program Files\Java\jdk1.7.0_17\jre\lib\javaws.jar;C:\Program Files\Java\jdk1.7.0_17\jre\lib\jce.jar;C:\Program Files\Java\jdk1.7.0_17\jre\lib\jfr.jar;C:\Program Files\Java\jdk1.7.0_17\jre\lib\jfxrt.jar;C:\Program Files\Java\jdk1.7.0_17\jre\lib\jsse.jar;C:\Program Files\Java\jdk1.7.0_17\jre\lib\management-agent.jar;C:\Program Files\Java\jdk1.7.0_17\jre\lib\plugin.jar;C:\Program Files\Java\jdk1.7.0_17\jre\lib\resources.jar;C:\Program Files\Java\jdk1.7.0_17\jre\lib\rt.jar;C:\Program Files\Java\jdk1.7.0_17\jre\lib\ext\access-bridge-64.jar;C:\Program Files\Java\jdk1.7.0_17\jre\lib\ext\dnsns.jar;C:\Program Files\Java\jdk1.7.0_17\jre\lib\ext\jaccess.jar;C:\Program Files\Java\jdk1.7.0_17\jre\lib\ext\localedata.jar;C:\Program Files\Java\jdk1.7.0_17\jre\lib\ext\sunec.jar;C:\Program Files\Java\jdk1.7.0_17\jre\lib\ext\sunjce_provider.jar;C:\Program Files\Java\jdk1.7.0_17\jre\lib\ext\sunmscapi.jar;C:\Program Files\Java\jdk1.7.0_17\jre\lib\ext\zipfs.jar;C:\Users\Alexandr.Alexandr-PC\Documents\java\Shooter\target\classes;C:\Program Files (x86)\JetBrains\IntelliJ IDEA Community Edition 12.1.6\lib\junit-4.10.jar;C:\Users\Alexandr.Alexandr-PC\.m2\repository\org\freemarker\freemarker\2.3.19\freemarker-2.3.19.jar;C:\Users\Alexandr.Alexandr-PC\.m2\repository\org\eclipse\jetty\jetty-server\9.1.0.M0\jetty-server-9.1.0.M0.jar;C:\Users\Alexandr.Alexandr-PC\.m2\repository\javax\servlet\javax.servlet-api\3.1.0\javax.servlet-api-3.1.0.jar;C:\Users\Alexandr.Alexandr-PC\.m2\repository\org\eclipse\jetty\jetty-http\9.1.0.M0\jetty-http-9.1.0.M0.jar;C:\Users\Alexandr.Alexandr-PC\.m2\repository\org\eclipse\jetty\jetty-util\9.1.0.M0\jetty-util-9.1.0.M0.jar;C:\Users\Alexandr.Alexandr-PC\.m2\repository\org\eclipse\jetty\jetty-io\9.1.0.M0\jetty-io-9.1.0.M0.jar;C:\Users\Alexandr.Alexandr-PC\.m2\repository\org\eclipse\jetty\jetty-webapp\9.1.0.M0\jetty-webapp-9.1.0.M0.jar;C:\Users\Alexandr.Alexandr-PC\.m2\repository\org\eclipse\jetty\jetty-xml\9.1.0.M0\jetty-xml-9.1.0.M0.jar;C:\Users\Alexandr.Alexandr-PC\.m2\repository\org\eclipse\jetty\jetty-servlet\9.1.0.M0\jetty-servlet-9.1.0.M0.jar;C:\Users\Alexandr.Alexandr-PC\.m2\repository\org\eclipse\jetty\jetty-security\9.1.0.M0\jetty-security-9.1.0.M0.jar;C:\Users\Alexandr.Alexandr-PC\.m2\repository\org\eclipse\jetty\jetty-rewrite\9.1.0.M0\jetty-rewrite-9.1.0.M0.jar;C:\Users\Alexandr.Alexandr-PC\.m2\repository\org\eclipse\jetty\jetty-client\9.1.0.M0\jetty-client-9.1.0.M0.jar;C:\Users\Alexandr.Alexandr-PC\.m2\repository\org\mockito\mockito-all\1.8.4\mockito-all-1.8.4.jar;C:\Users\Alexandr.Alexandr-PC\.m2\repository\org\seleniumhq\selenium\selenium-java\2.4.0\selenium-java-2.4.0.jar;C:\Users\Alexandr.Alexandr-PC\.m2\repository\org\seleniumhq\selenium\selenium-android-driver\2.4.0\selenium-android-driver-2.4.0.jar;C:\Users\Alexandr.Alexandr-PC\.m2\repository\org\seleniumhq\selenium\selenium-remote-driver\2.4.0\selenium-remote-driver-2.4.0.jar;C:\Users\Alexandr.Alexandr-PC\.m2\repository\cglib\cglib-nodep\2.1_3\cglib-nodep-2.1_3.jar;C:\Users\Alexandr.Alexandr-PC\.m2\repository\org\json\json\20080701\json-20080701.jar;C:\Users\Alexandr.Alexandr-PC\.m2\repository\org\seleniumhq\selenium\selenium-api\2.4.0\selenium-api-2.4.0.jar;C:\Users\Alexandr.Alexandr-PC\.m2\repository\com\google\guava\guava\r09\guava-r09.jar;C:\Users\Alexandr.Alexandr-PC\.m2\repository\org\apache\httpcomponents\httpclient\4.0.2\httpclient-4.0.2.jar;C:\Users\Alexandr.Alexandr-PC\.m2\repository\org\apache\httpcomponents\httpcore\4.0.1\httpcore-4.0.1.jar;C:\Users\Alexandr.Alexandr-PC\.m2\repository\commons-logging\commons-logging\1.1.1\commons-logging-1.1.1.jar;C:\Users\Alexandr.Alexandr-PC\.m2\repository\commons-codec\commons-codec\1.4\commons-codec-1.4.jar;C:\Users\Alexandr.Alexandr-PC\.m2\repository\org\seleniumhq\selenium\selenium-chrome-driver\2.4.0\selenium-chrome-driver-2.4.0.jar;C:\Users\Alexandr.Alexandr-PC\.m2\repository\org\seleniumhq\selenium\selenium-htmlunit-driver\2.4.0\selenium-htmlunit-driver-2.4.0.jar;C:\Users\Alexandr.Alexandr-PC\.m2\repository\net\sourceforge\htmlunit\htmlunit\2.8\htmlunit-2.8.jar;C:\Users\Alexandr.Alexandr-PC\.m2\repository\xalan\xalan\2.7.1\xalan-2.7.1.jar;C:\Users\Alexandr.Alexandr-PC\.m2\repository\xalan\serializer\2.7.1\serializer-2.7.1.jar;C:\Users\Alexandr.Alexandr-PC\.m2\repository\xml-apis\xml-apis\1.3.04\xml-apis-1.3.04.jar;C:\Users\Alexandr.Alexandr-PC\.m2\repository\commons-collections\commons-collections\3.2.1\commons-collections-3.2.1.jar;C:\Users\Alexandr.Alexandr-PC\.m2\repository\commons-lang\commons-lang\2.4\commons-lang-2.4.jar;C:\Users\Alexandr.Alexandr-PC\.m2\repository\org\apache\httpcomponents\httpmime\4.0.1\httpmime-4.0.1.jar;C:\Users\Alexandr.Alexandr-PC\.m2\repository\org\apache\james\apache-mime4j\0.6\apache-mime4j-0.6.jar;C:\Users\Alexandr.Alexandr-PC\.m2\repository\net\sourceforge\htmlunit\htmlunit-core-js\2.8\htmlunit-core-js-2.8.jar;C:\Users\Alexandr.Alexandr-PC\.m2\repository\xerces\xercesImpl\2.9.1\xercesImpl-2.9.1.jar;C:\Users\Alexandr.Alexandr-PC\.m2\repository\net\sourceforge\nekohtml\nekohtml\1.9.14\nekohtml-1.9.14.jar;C:\Users\Alexandr.Alexandr-PC\.m2\repository\net\sourceforge\cssparser\cssparser\0.9.5\cssparser-0.9.5.jar;C:\Users\Alexandr.Alexandr-PC\.m2\repository\org\w3c\css\sac\1.3\sac-1.3.jar;C:\Users\Alexandr.Alexandr-PC\.m2\repository\commons-io\commons-io\2.0.1\commons-io-2.0.1.jar;C:\Users\Alexandr.Alexandr-PC\.m2\repository\org\seleniumhq\selenium\selenium-firefox-driver\2.4.0\selenium-firefox-driver-2.4.0.jar;C:\Users\Alexandr.Alexandr-PC\.m2\repository\org\seleniumhq\selenium\selenium-ie-driver\2.4.0\selenium-ie-driver-2.4.0.jar;C:\Users\Alexandr.Alexandr-PC\.m2\repository\net\java\dev\jna\jna\3.2.3\jna-3.2.3.jar;C:\Users\Alexandr.Alexandr-PC\.m2\repository\org\seleniumhq\selenium\selenium-iphone-driver\2.4.0\selenium-iphone-driver-2.4.0.jar;C:\Users\Alexandr.Alexandr-PC\.m2\repository\org\seleniumhq\selenium\selenium-support\2.4.0\selenium-support-2.4.0.jar;C:\Users\Alexandr.Alexandr-PC\.m2\repository\junit\junit\4.11\junit-4.11.jar;C:\Users\Alexandr.Alexandr-PC\.m2\repository\org\hamcrest\hamcrest-core\1.3\hamcrest-core-1.3.jar;C:\Users\Alexandr.Alexandr-PC\.m2\repository\org\eclipse\jetty\jetty-websocket\7.4.4.v20110707\jetty-websocket-7.4.4.v20110707.jar;C:\Users\Alexandr.Alexandr-PC\.m2\repository\javax\servlet\servlet-api\2.5\servlet-api-2.5.jar;C:\Program Files (x86)\JetBrains\IntelliJ IDEA Community Edition 12.1.6\lib\idea_rt.jar" com.intellij.rt.execution.application.AppMain servlets.SimpleEchoClient
2013-12-01 00:52:53.727:INFO:oejs.Server:main: jetty-9.1.0.M0
2013-12-01 00:52:53.747:WARN:oejuc.AbstractLifeCycle:main: FAILED servlets.WsHandler@267a1e1c: java.lang.NoClassDefFoundError: org/eclipse/jetty/http/HttpException
java.lang.NoClassDefFoundError: org/eclipse/jetty/http/HttpException
at org.eclipse.jetty.websocket.WebSocketHandler.doStart(WebSocketHandler.java:76)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:69)
at org.eclipse.jetty.util.component.ContainerLifeCycle.start(ContainerLifeCycle.java:118)
at org.eclipse.jetty.server.Server.start(Server.java:342)
at org.eclipse.jetty.util.component.ContainerLifeCycle.doStart(ContainerLifeCycle.java:100)
at org.eclipse.jetty.server.handler.AbstractHandler.doStart(AbstractHandler.java:58)
at org.eclipse.jetty.server.Server.doStart(Server.java:290)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:69)
at servlets.SimpleEchoClient.main(SimpleEchoClient.java:26)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)
Caused by:
java.lang.ClassNotFoundException: org.eclipse.jetty.http.HttpException
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
at org.eclipse.jetty.websocket.WebSocketHandler.doStart(WebSocketHandler.java:76)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:69)
at org.eclipse.jetty.util.component.ContainerLifeCycle.start(ContainerLifeCycle.java:118)
at org.eclipse.jetty.server.Server.start(Server.java:342)
at org.eclipse.jetty.util.component.ContainerLifeCycle.doStart(ContainerLifeCycle.java:100)
at org.eclipse.jetty.server.handler.AbstractHandler.doStart(AbstractHandler.java:58)
at org.eclipse.jetty.server.Server.doStart(Server.java:290)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:69)
at servlets.SimpleEchoClient.main(SimpleEchoClient.java:26)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)
2013-12-01 00:52:53.748:WARN:oejuc.AbstractLifeCycle:main: FAILED org.eclipse.jetty.server.Server@1b4ed400: java.lang.NoClassDefFoundError: org/eclipse/jetty/http/HttpException
java.lang.NoClassDefFoundError: org/eclipse/jetty/http/HttpException
at org.eclipse.jetty.websocket.WebSocketHandler.doStart(WebSocketHandler.java:76)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:69)
at org.eclipse.jetty.util.component.ContainerLifeCycle.start(ContainerLifeCycle.java:118)
at org.eclipse.jetty.server.Server.start(Server.java:342)
at org.eclipse.jetty.util.component.ContainerLifeCycle.doStart(ContainerLifeCycle.java:100)
at org.eclipse.jetty.server.handler.AbstractHandler.doStart(AbstractHandler.java:58)
at org.eclipse.jetty.server.Server.doStart(Server.java:290)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:69)
at servlets.SimpleEchoClient.main(SimpleEchoClient.java:26)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)
With what the problem could be related? Thanks in advance.
First, your command line, decomposed to make it readable:
"C:\Program Files\Java\jdk1.7.0_17\bin\java"
-Didea.launcher.port=7532
"-Didea.launcher.bin.path=C:\Program Files (x86)\JetBrains\IntelliJ IDEA Community Edition 12.1.6\bin"
-Dfile.encoding=UTF-8
-classpath "C:\Program Files\Java\jdk1.7.0_17\jre\lib\charsets.jar
C:\Program Files\Java\jdk1.7.0_17\jre\lib\deploy.jar
C:\Program Files\Java\jdk1.7.0_17\jre\lib\javaws.jar
C:\Program Files\Java\jdk1.7.0_17\jre\lib\jce.jar
C:\Program Files\Java\jdk1.7.0_17\jre\lib\jfr.jar
C:\Program Files\Java\jdk1.7.0_17\jre\lib\jfxrt.jar
C:\Program Files\Java\jdk1.7.0_17\jre\lib\jsse.jar
C:\Program Files\Java\jdk1.7.0_17\jre\lib\management-agent.jar
C:\Program Files\Java\jdk1.7.0_17\jre\lib\plugin.jar
C:\Program Files\Java\jdk1.7.0_17\jre\lib\resources.jar
C:\Program Files\Java\jdk1.7.0_17\jre\lib\rt.jar
C:\Program Files\Java\jdk1.7.0_17\jre\lib\ext\access-bridge-64.jar
C:\Program Files\Java\jdk1.7.0_17\jre\lib\ext\dnsns.jar
C:\Program Files\Java\jdk1.7.0_17\jre\lib\ext\jaccess.jar
C:\Program Files\Java\jdk1.7.0_17\jre\lib\ext\localedata.jar
C:\Program Files\Java\jdk1.7.0_17\jre\lib\ext\sunec.jar
C:\Program Files\Java\jdk1.7.0_17\jre\lib\ext\sunjce_provider.jar
C:\Program Files\Java\jdk1.7.0_17\jre\lib\ext\sunmscapi.jar
C:\Program Files\Java\jdk1.7.0_17\jre\lib\ext\zipfs.jar
C:\Users\Alexandr.Alexandr-PC\Documents\java\Shooter\target\classes
C:\Program Files (x86)\JetBrains\IntelliJ IDEA Community Edition 12.1.6\lib\junit-4.10.jar
C:\Users\Alexandr.Alexandr-PC\.m2\repository\org\freemarker\freemarker\2.3.19\freemarker-2.3.19.jar
C:\Users\Alexandr.Alexandr-PC\.m2\repository\org\eclipse\jetty\jetty-server\9.1.0.M0\jetty-server-9.1.0.M0.jar
C:\Users\Alexandr.Alexandr-PC\.m2\repository\javax\servlet\javax.servlet-api\3.1.0\javax.servlet-api-3.1.0.jar
C:\Users\Alexandr.Alexandr-PC\.m2\repository\org\eclipse\jetty\jetty-http\9.1.0.M0\jetty-http-9.1.0.M0.jar
C:\Users\Alexandr.Alexandr-PC\.m2\repository\org\eclipse\jetty\jetty-util\9.1.0.M0\jetty-util-9.1.0.M0.jar
C:\Users\Alexandr.Alexandr-PC\.m2\repository\org\eclipse\jetty\jetty-io\9.1.0.M0\jetty-io-9.1.0.M0.jar
C:\Users\Alexandr.Alexandr-PC\.m2\repository\org\eclipse\jetty\jetty-webapp\9.1.0.M0\jetty-webapp-9.1.0.M0.jar
C:\Users\Alexandr.Alexandr-PC\.m2\repository\org\eclipse\jetty\jetty-xml\9.1.0.M0\jetty-xml-9.1.0.M0.jar
C:\Users\Alexandr.Alexandr-PC\.m2\repository\org\eclipse\jetty\jetty-servlet\9.1.0.M0\jetty-servlet-9.1.0.M0.jar
C:\Users\Alexandr.Alexandr-PC\.m2\repository\org\eclipse\jetty\jetty-security\9.1.0.M0\jetty-security-9.1.0.M0.jar
C:\Users\Alexandr.Alexandr-PC\.m2\repository\org\eclipse\jetty\jetty-rewrite\9.1.0.M0\jetty-rewrite-9.1.0.M0.jar
C:\Users\Alexandr.Alexandr-PC\.m2\repository\org\eclipse\jetty\jetty-client\9.1.0.M0\jetty-client-9.1.0.M0.jar
C:\Users\Alexandr.Alexandr-PC\.m2\repository\org\mockito\mockito-all\1.8.4\mockito-all-1.8.4.jar
C:\Users\Alexandr.Alexandr-PC\.m2\repository\org\seleniumhq\selenium\selenium-java\2.4.0\selenium-java-2.4.0.jar
C:\Users\Alexandr.Alexandr-PC\.m2\repository\org\seleniumhq\selenium\selenium-android-driver\2.4.0\selenium-android-driver-2.4.0.jar
C:\Users\Alexandr.Alexandr-PC\.m2\repository\org\seleniumhq\selenium\selenium-remote-driver\2.4.0\selenium-remote-driver-2.4.0.jar
C:\Users\Alexandr.Alexandr-PC\.m2\repository\cglib\cglib-nodep\2.1_3\cglib-nodep-2.1_3.jar
C:\Users\Alexandr.Alexandr-PC\.m2\repository\org\json\json\20080701\json-20080701.jar
C:\Users\Alexandr.Alexandr-PC\.m2\repository\org\seleniumhq\selenium\selenium-api\2.4.0\selenium-api-2.4.0.jar
C:\Users\Alexandr.Alexandr-PC\.m2\repository\com\google\guava\guava\r09\guava-r09.jar
C:\Users\Alexandr.Alexandr-PC\.m2\repository\org\apache\httpcomponents\httpclient\4.0.2\httpclient-4.0.2.jar
C:\Users\Alexandr.Alexandr-PC\.m2\repository\org\apache\httpcomponents\httpcore\4.0.1\httpcore-4.0.1.jar
C:\Users\Alexandr.Alexandr-PC\.m2\repository\commons-logging\commons-logging\1.1.1\commons-logging-1.1.1.jar
C:\Users\Alexandr.Alexandr-PC\.m2\repository\commons-codec\commons-codec\1.4\commons-codec-1.4.jar
C:\Users\Alexandr.Alexandr-PC\.m2\repository\org\seleniumhq\selenium\selenium-chrome-driver\2.4.0\selenium-chrome-driver-2.4.0.jar
C:\Users\Alexandr.Alexandr-PC\.m2\repository\org\seleniumhq\selenium\selenium-htmlunit-driver\2.4.0\selenium-htmlunit-driver-2.4.0.jar
C:\Users\Alexandr.Alexandr-PC\.m2\repository\net\sourceforge\htmlunit\htmlunit\2.8\htmlunit-2.8.jar
C:\Users\Alexandr.Alexandr-PC\.m2\repository\xalan\xalan\2.7.1\xalan-2.7.1.jar
C:\Users\Alexandr.Alexandr-PC\.m2\repository\xalan\serializer\2.7.1\serializer-2.7.1.jar
C:\Users\Alexandr.Alexandr-PC\.m2\repository\xml-apis\xml-apis\1.3.04\xml-apis-1.3.04.jar
C:\Users\Alexandr.Alexandr-PC\.m2\repository\commons-collections\commons-collections\3.2.1\commons-collections-3.2.1.jar
C:\Users\Alexandr.Alexandr-PC\.m2\repository\commons-lang\commons-lang\2.4\commons-lang-2.4.jar
C:\Users\Alexandr.Alexandr-PC\.m2\repository\org\apache\httpcomponents\httpmime\4.0.1\httpmime-4.0.1.jar
C:\Users\Alexandr.Alexandr-PC\.m2\repository\org\apache\james\apache-mime4j\0.6\apache-mime4j-0.6.jar
C:\Users\Alexandr.Alexandr-PC\.m2\repository\net\sourceforge\htmlunit\htmlunit-core-js\2.8\htmlunit-core-js-2.8.jar
C:\Users\Alexandr.Alexandr-PC\.m2\repository\xerces\xercesImpl\2.9.1\xercesImpl-2.9.1.jar
C:\Users\Alexandr.Alexandr-PC\.m2\repository\net\sourceforge\nekohtml\nekohtml\1.9.14\nekohtml-1.9.14.jar
C:\Users\Alexandr.Alexandr-PC\.m2\repository\net\sourceforge\cssparser\cssparser\0.9.5\cssparser-0.9.5.jar
C:\Users\Alexandr.Alexandr-PC\.m2\repository\org\w3c\css\sac\1.3\sac-1.3.jar
C:\Users\Alexandr.Alexandr-PC\.m2\repository\commons-io\commons-io\2.0.1\commons-io-2.0.1.jar
C:\Users\Alexandr.Alexandr-PC\.m2\repository\org\seleniumhq\selenium\selenium-firefox-driver\2.4.0\selenium-firefox-driver-2.4.0.jar
C:\Users\Alexandr.Alexandr-PC\.m2\repository\org\seleniumhq\selenium\selenium-ie-driver\2.4.0\selenium-ie-driver-2.4.0.jar
C:\Users\Alexandr.Alexandr-PC\.m2\repository\net\java\dev\jna\jna\3.2.3\jna-3.2.3.jar
C:\Users\Alexandr.Alexandr-PC\.m2\repository\org\seleniumhq\selenium\selenium-iphone-driver\2.4.0\selenium-iphone-driver-2.4.0.jar
C:\Users\Alexandr.Alexandr-PC\.m2\repository\org\seleniumhq\selenium\selenium-support\2.4.0\selenium-support-2.4.0.jar
C:\Users\Alexandr.Alexandr-PC\.m2\repository\junit\junit\4.11\junit-4.11.jar
C:\Users\Alexandr.Alexandr-PC\.m2\repository\org\hamcrest\hamcrest-core\1.3\hamcrest-core-1.3.jar
C:\Users\Alexandr.Alexandr-PC\.m2\repository\org\eclipse\jetty\jetty-websocket\7.4.4.v20110707\jetty-websocket-7.4.4.v20110707.jar
C:\Users\Alexandr.Alexandr-PC\.m2\repository\javax\servlet\servlet-api\2.5\servlet-api-2.5.jar
C:\Program Files (x86)\JetBrains\IntelliJ IDEA Community Edition 12.1.6\lib\idea_rt.jar"
com.intellij.rt.execution.application.AppMain servlets.SimpleEchoClient
And your first line of output from your program
2013-12-01 00:52:53.727:INFO:oejs.Server:main: jetty-9.1.0.M0
You have multiple things to take care of.
7.4.4.v20110707
while the rest of Jetty is at 9.1.0.M0
.9.1.0.v20131115
Modern Jetty WebSocket API
An example project has been setup at:
https://github.com/jetty-project/embedded-jetty-websocket-examples/tree/master/native-jetty-websocket-example
The maven dependencies you'll need:
<!-- To write basic websockets against -->
<dependency>
<groupId>org.eclipse.jetty.websocket</groupId>
<artifactId>websocket-api</artifactId>
<version>9.1.0.v20131115</version>
</dependency>
<!-- To run websockets in embedded server -->
<dependency>
<groupId>org.eclipse.jetty.websocket</groupId>
<artifactId>websocket-server</artifactId>
<version>9.1.0.v20131115</version>
</dependency>
<!-- To run websockets client -->
<dependency>
<groupId>org.eclipse.jetty.websocket</groupId>
<artifactId>websocket-client</artifactId>
<version>9.1.0.v20131115</version>
</dependency>
Look at the example code.
EventServer.java
- this the jetty embedded server code, to initialize the handler tree + ServletContext. It maps the EventServlet
to the path spec of "/events/*"
EventServlet.java
- this simply registers the EventSocket
with the Servlet (For background, the WebSocketServletFactory has a simple default implementation of WebSocketCreator
that only supports 1 websocket. The .register(Class<?>)
call simply tells this default WebSocketCreator what WebSocket to create. If you want a more complex WebSocketCreator, then you would call WebSocketServletFactory.setCreator(WebSocketCreator)
with your own implementation)EventSocket.java
- the actual websocket that receives the incoming eventsEventClient.java
- since your demo code was called client, but had server code in it, I didn't really know what you were planning, so i tossed in a Native Jetty WebSocket Client example as well.javax.websocket standard API on Jetty
An example project has been setup at:
https://github.com/jetty-project/embedded-jetty-websocket-examples/tree/master/javax.websocket-example
The maven dependencies you'll need:
<!-- To write basic javax.websocket against -->
<dependency>
<groupId>javax.websocket</groupId>
<artifactId>javax.websocket-api</artifactId>
<version>1.0</version>
</dependency>
<!-- To run javax.websocket in embedded server -->
<dependency>
<groupId>org.eclipse.jetty.websocket</groupId>
<artifactId>javax-websocket-server-impl</artifactId>
<version>9.1.0.v20131115</version>
</dependency>
<!-- To run javax.websocket client -->
<dependency>
<groupId>org.eclipse.jetty.websocket</groupId>
<artifactId>javax-websocket-client-impl</artifactId>
<version>9.1.0.v20131115</version>
</dependency>
Look at the example code.
EventServer.java
- this is slightly different than the Native API, as everything in the javax.websocket world is based on Annotations with discovery. So this embedded server establishes a ServletContextHandler, then initializes the javax.websocket layer with a call to WebSocketServerContainerInitializer.configureContext(context)
, finally with a manual addEndpoint(Class)
against the ServerContainer
.EventSocket.java
- using the annotations for javax.websocket, this class is both annotated to be a Server endpoint and a Client endpoint, with the methods that should receive the various events also annotated to indicate their desired purpose.EventClient.java
- this uses the javax.websocket WebSocketContainer (client container) to connect to the server and send a message. (of particular note, is the extra work to cleanup the lifecycle of the WebSocketContainer. a missing feature from the JSR-356 spec)Good luck
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With