1

I have a very simple WebSocket server from Danny Cowards' "Java WebSocket Programming book" that looks like this:

import javax.websocket.server.ServerEndpoint;
import javax.websocket.OnMessage;

@ServerEndpoint (value="/echo")
public class EchoServer
{
    @OnMessage
    public String echo (String incomingMessage)
    {
    return "I got this (" + incomingMessage + "), so I am sending it back!";
    }
}

I compiled it using gradle 2.7 (see build.gradle below)

apply plugin: 'java'
apply plugin: "war"

repositories {
    mavenCentral()
}

dependencies {
        compile 'javax.websocket:javax.websocket-api:1.1'
}

and placed it in the webapps directory of a plain (HTTP only) Jetty server (jetty-distribution-9.3.6.v20151106) and I could make it talk with the client that accessed the WebSocket interface like so:

            var wsUri = "ws://localhost:8080/echoserver/echo";

Then, I took the same *.war file, and placed it on a secure jetty server (running jetty-9.1.3.v20140225) but the deployment didn't work, and my access of the server using (note wss now)

            var wsUri = "wss://localhost:8443/echoserver/echo";

didn't work for an error. The specific error, from the JavaScript console on chrome, is 'WebSocket connection to 'wss://localhost:8443/echoserver/echo' failed: Error during WebSocket handshake: Unexpected Response code: 503'. But I think it is because there was a RunTimeException scanning EchoServer.class that it happened (as evinced in the jetty stderrout.log):

2015-11-20 15:32:14.320:INFO:oejs.Server:main: jetty-9.1.3.v20140225
2015-11-20 15:32:14.329:INFO:oejs.AbstractNCSARequestLog:main: Opened /opt/jetty/logs/2015_11_20.request.log
2015-11-20 15:32:14.329:INFO:oejs.AbstractNCSARequestLog:main: Opened /opt/jetty/logs/2015_11_20.request.log
2015-11-20 15:32:14.331:INFO:oejdp.ScanningAppProvider:main: Deployment monitor [file:/opt/jetty/webapps/] at interval 1
2015-11-20 15:32:14.421:INFO:oeja.AnnotationConfiguration:main: Scanned 1 container path jars, 1 WEB-INF/lib jars, 1 WEB-INF/classes d
irs in 17ms for context o.e.j.w.WebAppContext@4c70fda8{/echoserver,file:/tmp/jetty-0.0.0.0-8443-echoserver.war-_echoserver-any-7817985
952118790015.dir/webapp/,STARTING}{/echoserver.war}
2015-11-20 15:32:14.421:WARN:oejw.WebAppContext:main: Failed startup of context o.e.j.w.WebAppContext@4c70fda8{/echoserver,file:/tmp/j
etty-0.0.0.0-8443-echoserver.war-_echoserver-any-7817985952118790015.dir/webapp/,STARTING}{/echoserver.war}
java.lang.RuntimeException: Error scanning file EchoServer.class
    at org.eclipse.jetty.annotations.AnnotationParser.parseDir(AnnotationParser.java:705)
    at org.eclipse.jetty.annotations.AnnotationParser.parseDir(AnnotationParser.java:686)
    at org.eclipse.jetty.annotations.AnnotationParser.parseDir(AnnotationParser.java:686)
    at org.eclipse.jetty.annotations.AnnotationParser.parseDir(AnnotationParser.java:686)
    at org.eclipse.jetty.annotations.AnnotationParser.parse(AnnotationParser.java:821)
    at org.eclipse.jetty.annotations.AnnotationConfiguration$ParserTask.call(AnnotationConfiguration.java:159)
    at org.eclipse.jetty.annotations.AnnotationConfiguration$1.run(AnnotationConfiguration.java:542)
    at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:607)
    at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:536)
    at java.lang.Thread.run(Thread.java:745)
Caused by: 
java.lang.IllegalArgumentException
    at org.objectweb.asm.ClassReader.<init>(Unknown Source)
    at org.objectweb.asm.ClassReader.<init>(Unknown Source)
    at org.objectweb.asm.ClassReader.<init>(Unknown Source)
    at org.eclipse.jetty.annotations.AnnotationParser.scanClass(AnnotationParser.java:970)
    at org.eclipse.jetty.annotations.AnnotationParser.parseDir(AnnotationParser.java:700)
    at org.eclipse.jetty.annotations.AnnotationParser.parseDir(AnnotationParser.java:686)
    at org.eclipse.jetty.annotations.AnnotationParser.parseDir(AnnotationParser.java:686)
    at org.eclipse.jetty.annotations.AnnotationParser.parseDir(AnnotationParser.java:686)
    at org.eclipse.jetty.annotations.AnnotationParser.parse(AnnotationParser.java:821)
    at org.eclipse.jetty.annotations.AnnotationConfiguration$ParserTask.call(AnnotationConfiguration.java:159)
    at org.eclipse.jetty.annotations.AnnotationConfiguration$1.run(AnnotationConfiguration.java:542)
    at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:607)
    at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:536)
    at java.lang.Thread.run(Thread.java:745)

My environment is a Ubuntu 14.04/x64/Oracle java 8. BTW, I downloaded Danny Cowards' source code from the website, and it is exactly the same code I have. However, it comes with its own mystery *.war (in the dist directory, but the ant build.xml is clearly referring to all manner of NetBeans dependencies which have no business being there, ergo I could not compile it using ant) and placed it in the HTTPS jetty and it runs exactly as expected, and I do not get an error when I access it using wss:, so it is not a SSL/self-signed-certificate issue, or so I think.

Can anyone tell me what might be the issue here? Any help with this is deeply appreciated.

Thanks, Sonny.

PS: I have checked out a number of WebSocket/SSL/Jetty posts on SO, but they do not seem to address the problem I am having with Jetty.

Sonny
  • 2,103
  • 1
  • 26
  • 34
  • I looked more in detail into the error `java.lang.IllegalArgumentException at org.objectweb.asm.ClassReader.(Unknown Source)` and a number of folks are suggesting I go back to Java 7 (e.g.http://stackoverflow.com/questions/27092857/cglib-throws-an-illegalargumentexception-when-enhancing-the-java-util-date-class) !! This is an unsupported version of Java! Any workarounds for this issue? – Sonny Nov 20 '15 at 21:39

1 Answers1

1

Jetty 9.1.x is too old for JSR356 (javax.websocket) use.

Use Jetty 9.2.x or Jetty 9.3.x for JSR356 support.

Since you seem to be using Java 8, use version Jetty version 9.3.6.v20151106.

Joakim Erdfelt
  • 46,896
  • 7
  • 86
  • 136
  • Thanks. I would like to try this asap before I can accept your answer, but I am running into a LOT of trouble with keystore and SSL configuration for switching to SSL/HTTPS on 9.3.6. I looked at the Jetty website (http://www.eclipse.org/jetty/documentation/current/configuring-ssl.html#configuring-sslcontextfactory) and followed it to the dot, but it does not help, starting Jetty results in `Caused by: java.io.IOException: Keystore was tampered with, or password was incorrect` which I checked here again on SO, again unhelpful. I think Jetty documentation requires a lot of work; I hope to help. – Sonny Nov 21 '15 at 00:38
  • Had to do `{jetty.home} $ java -cp lib/jetty-util-9.3.6.v20151106.jar org.eclipse.jetty.util.security.Password "MyInterestingAndAwesomPassword"` and replace the `OBF..` lines in `{jetty.home}/etc/jetty-ssl-context.xml` and `wss` and HTTPS work now. Thanks! – Sonny Nov 21 '15 at 01:00
  • 1
    Don't modify/delete/change/edit **any** files under `${jetty.home}`. Setup your `${jetty.base}/start.ini` properly and just set the properties for your keystore there. – Joakim Erdfelt Nov 23 '15 at 15:48
  • For those who are trying to figure out the new `jetty.base` related concepts, please see http://www.eclipse.org/jetty/documentation/current/quickstart-running-jetty.html#quickstart-starting-https – Sonny Dec 25 '15 at 19:38