Im trying to connect to a commetd server via websocket client. I used exactly the code from an official cometd demo on github without modifications and try to connect to http://localhost:8080/cometd/test
.. but as soon as my client tries to do the websocket upgrade http request I get a response with "HTTP/1.1 400 Unknown Bayeux Transport" Any ideas?
I tried it with SSL and without it, the latter obviosly to reduce potential error sources. In both cases I get the same error.
Here is my pom, in case I forgot some important websocket related dependencies
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>de.verlinkied</groupId>
<artifactId>bayeux-server</artifactId>
<version>1.0</version>
<properties>
<jetty.version>9.2.22.v20170606</jetty.version>
<cometd.version>3.1.3</cometd.version>
<slf4j.version>1.7.25</slf4j.version>
</properties>
<dependencies>
<dependency>
<groupId>org.eclipse.jetty.websocket</groupId>
<artifactId>websocket-api</artifactId>
<version>${jetty.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-server</artifactId>
<version>${jetty.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-servlet</artifactId>
<version>${jetty.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-jmx</artifactId>
<version>${jetty.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty.websocket</groupId>
<artifactId>javax-websocket-server-impl</artifactId>
<version>${jetty.version}</version>
</dependency>
<dependency>
<groupId>org.cometd.java</groupId>
<artifactId>cometd-java-server</artifactId>
<version>${cometd.version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${slf4j.version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>${slf4j.version}</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<configuration>
<mainClass>de.verlinked.BayeuxServerTest</mainClass>
</configuration>
</plugin>
</plugins>
</build>
</project>
mvn dependency:tree yields the following
[INFO] ------------------------------------------------------------------------
[INFO] Building bayeux-server 1.0
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-dependency-plugin:2.8:tree (default-cli) @ bayeux-server ---
[INFO] de.verlinkied:bayeux-server:jar:1.0
[INFO] +- org.eclipse.jetty.websocket:websocket-api:jar:9.2.22.v20170606:compile
[INFO] +- org.eclipse.jetty:jetty-server:jar:9.2.22.v20170606:compile
[INFO] | +- javax.servlet:javax.servlet-api:jar:3.1.0:compile
[INFO] | +- org.eclipse.jetty:jetty-http:jar:9.2.22.v20170606:compile
[INFO] | \- org.eclipse.jetty:jetty-io:jar:9.2.22.v20170606:compile
[INFO] +- org.eclipse.jetty:jetty-servlet:jar:9.2.22.v20170606:compile
[INFO] | \- org.eclipse.jetty:jetty-security:jar:9.2.22.v20170606:compile
[INFO] +- org.eclipse.jetty:jetty-jmx:jar:9.2.22.v20170606:compile
[INFO] | \- org.eclipse.jetty:jetty-util:jar:9.2.22.v20170606:compile
[INFO] +- org.eclipse.jetty.websocket:javax-websocket-server-impl:jar:9.2.22.v20170606:compile
[INFO] | +- org.eclipse.jetty:jetty-annotations:jar:9.2.22.v20170606:compile
[INFO] | | +- org.eclipse.jetty:jetty-plus:jar:9.2.22.v20170606:compile
[INFO] | | | \- org.eclipse.jetty:jetty-jndi:jar:9.2.22.v20170606:compile
[INFO] | | +- org.eclipse.jetty:jetty-webapp:jar:9.2.22.v20170606:compile
[INFO] | | | \- org.eclipse.jetty:jetty-xml:jar:9.2.22.v20170606:compile
[INFO] | | +- javax.annotation:javax.annotation-api:jar:1.2:compile
[INFO] | | +- org.ow2.asm:asm:jar:5.0.1:compile
[INFO] | | \- org.ow2.asm:asm-commons:jar:5.0.1:compile
[INFO] | | \- org.ow2.asm:asm-tree:jar:5.0.1:compile
[INFO] | +- org.eclipse.jetty.websocket:javax-websocket-client-impl:jar:9.2.22.v20170606:compile
[INFO] | | \- org.eclipse.jetty.websocket:websocket-client:jar:9.2.22.v20170606:compile
[INFO] | +- org.eclipse.jetty.websocket:websocket-server:jar:9.2.22.v20170606:compile
[INFO] | | +- org.eclipse.jetty.websocket:websocket-common:jar:9.2.22.v20170606:compile
[INFO] | | \- org.eclipse.jetty.websocket:websocket-servlet:jar:9.2.22.v20170606:compile
[INFO] | \- javax.websocket:javax.websocket-api:jar:1.0:compile
[INFO] +- org.cometd.java:cometd-java-server:jar:3.1.3:compile
[INFO] | +- org.cometd.java:bayeux-api:jar:3.1.3:compile
[INFO] | \- org.cometd.java:cometd-java-common:jar:3.1.3:compile
[INFO] | \- org.eclipse.jetty:jetty-util-ajax:jar:9.2.22.v20170606:compile
[INFO] +- org.slf4j:slf4j-api:jar:1.7.25:compile
[INFO] \- org.slf4j:slf4j-log4j12:jar:1.7.25:compile
[INFO] \- log4j:log4j:jar:1.2.17:compile
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
The jetty log shows the following
3411 [qtp1080615555-20] DEBUG org.eclipse.jetty.server.HttpChannel - HttpChannelOverHttp@31f5a8ff{r=1,c=false,a=IDLE,uri=/cometd/test} messageComplete
3411 [qtp1080615555-20] DEBUG org.eclipse.jetty.server.HttpInput - HttpInputOverHTTP@6f0992d0 EOF
3411 [qtp1080615555-20] DEBUG org.eclipse.jetty.server.HttpChannel - HttpChannelOverHttp@31f5a8ff{r=1,c=false,a=IDLE,uri=/cometd/test} handle enter
3412 [qtp1080615555-20 - /cometd/test] DEBUG org.eclipse.jetty.server.HttpChannelState - HttpChannelState@738a2171{s=IDLE i=true a=null} handling IDLE
3412 [qtp1080615555-20 - /cometd/test] DEBUG org.eclipse.jetty.server.HttpChannel - HttpChannelOverHttp@31f5a8ff{r=1,c=false,a=DISPATCHED,uri=/cometd/test} action REQUEST_DISPATCH
3412 [qtp1080615555-20 - /cometd/test] DEBUG org.eclipse.jetty.server.Server - REQUEST GET /cometd/test on HttpChannelOverHttp@31f5a8ff{r=1,c=false,a=DISPATCHED,uri=/cometd/test}
3412 [qtp1080615555-20 - /cometd/test] DEBUG org.eclipse.jetty.server.handler.ContextHandler - scope null||/cometd/test @ o.e.j.s.ServletContextHandler@35fdf572{/,null,AVAILABLE}
3413 [qtp1080615555-20 - /cometd/test] DEBUG org.eclipse.jetty.server.handler.ContextHandler - context=||/cometd/test @ o.e.j.s.ServletContextHandler@35fdf572{/,null,AVAILABLE}
3413 [qtp1080615555-20 - /cometd/test] DEBUG org.eclipse.jetty.servlet.ServletHandler - servlet |/cometd|/test -> org.cometd.server.CometDServlet-629a2d4a@4553b89a==org.cometd.server.CometDServlet,1,true
3413 [qtp1080615555-20 - /cometd/test] DEBUG org.eclipse.jetty.servlet.ServletHandler - chain=Jetty_WebSocketUpgradeFilter->org.cometd.server.CometDServlet-629a2d4a@4553b89a==org.cometd.server.CometDServlet,1,true
3414 [qtp1080615555-20 - /cometd/test] DEBUG org.eclipse.jetty.servlet.ServletHandler - call filter Jetty_WebSocketUpgradeFilter
3416 [qtp1080615555-20 - /cometd/test] DEBUG org.eclipse.jetty.servlet.ServletHandler - call servlet org.cometd.server.CometDServlet-629a2d4a@4553b89a==org.cometd.server.CometDServlet,1,true
3418 [qtp1080615555-20 - /cometd/test] DEBUG org.eclipse.jetty.server.HttpConnection - org.eclipse.jetty.server.HttpConnection$SendCallback@62e6f50[PROCESSING][i=ResponseInfo{HTTP/1.1 400 Unknown Bayeux Transport,304,false},cb=org.eclipse.jetty.server.HttpChannel$CommitCallback@6892f8b1] generate: NEED_HEADER (null,[p=0,l=304,c=2048,r=304],true)@START
Where you can see that some Jetty_WebSocketUpgradeFilter is called, which makes me think that the websocket dependency is present but still something goes wrong.
Jetty offers 2 different WebSocket flavors, the standard JSR 356 one and a Jetty specific one.
The first is indicated in Maven artifacts with javax in the artifact name, while the second is indicated with jetty in the artifact name.
From your POM above you are using
cometd-java-websocket-jetty-server, which is the CometD binding to the jetty WebSocket flavor.However, you are explicitly specifying as a dependency the
javax-websocket-server-implartifact, which is the JSR 356 javax flavor.I am guessing that if you make the dependencies consistent, that is depend on the javax flavor only or the jetty flavor only will solve your issue.
Unless you need to use the Jetty specific features, I would recommend that you use the JSR 356 javax flavor for both the CometD binding (
org.cometd.java:cometd-java-websocket-javax-server) and the Jetty dependency (org.eclipse.jetty.websocket:javax-websocket-server-impl).