I received a Web application, implemented with Spring using STOMP over WebSockets Messaging, similar to what's described here (with RabbitMQ at the backend). It runs on Tomcat, and I can connect to the application using regular URLs (e.g. http://host/server/
). I was also given a demo client - a JSPX page, which uses Modernizr WebSockets and SockJS. The connection code in the demo client looks like this:
if (Modernizr.websockets) {
socket = new WebSocket('ws://host/server/endpointx');
}
else {
socket = new SockJS('/server/endpointy');
}
stompClient = Stomp.over(socket);
stompClient.connect(headers, function(frame) { ... });
....
Demo client works fine (when I load JSPX page in the browser, I can connect to the server). But my goal is to connect to the same server using some Java STOMP library. Problem is, the libraries I tried, require host and port as connection parameters: For example with ActiveMQ Stomp library:
StompConnection connection = new StompConnection();
connection.open("host", port);
connection.connect(new HashMap<String, String>());
If I specify port
as 61613
, connection succeeds, but I hit RabbitMQ directly, not my server (this is not what I want). If I specify 8080
(or 80
), on connection I get an error
java.io.EOFException at java.io.DataInputStream.readByte(Unknown Source) at org.apache.activemq.transport.stomp.StompWireFormat.unmarshal(StompWireFormat.java:137) at org.apache.activemq.transport.stomp.StompConnection.receive(StompConnection.java:77) at org.apache.activemq.transport.stomp.StompConnection.receive(StompConnection.java:68) at org.apache.activemq.transport.stomp.StompConnection.connect(StompConnection.java:139) at ....stomp.impl.activemq.ActiveMQStompDriver.connect(ActiveMQStompDriver.java:39) ... 25 more
and trace shows that this is because CONNECT
frame never receives an expected CONNECTED
frame (in fact, it doesn't receive anything back).
So I'm puzzled: am I using a wrong port? or dealing with some library incompatibility? or do I need to somehow indicate Tomcat that I want to upgrade HTTP connection to WebSockets?
If the above question is difficult to answer, then this one is equally useful: how do I connect to Spring application with STOMP over WebSockets messaging channel running on Tomcat using Java?