views:

214

answers:

2

I'm writing jquery client for cometd server (i'm using jquery.cometd.js plugin) and I'm running out of ideas why the simplest possible case doesn't work.

The cometd server is behind apache (so it's running on this same domain) and all the requests are forwarded from uri http://wwwhost/cometd.

The problem is that when I try to connect (by executing handshake()) to the cometd it's not sending requests directly to /cometd but to /cometd/handshake that gives 404 error. I checked on the other apps that I was testing and dojo is always connecting to /cometd and then sending message 'handshake'.

Anyone has an idea why jquery.cometd is doing that?

This is what i can see in the apache logs:

- - [23/Mar/2010:17:59:30 +0100] "POST /cometd/handshake HTTP/1.1" 404 158 "http://wwwhost/" "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.8) Gecko/20100308 Iceweasel/3.5.8 (like Firefox/3.5.8)"

Below you can find the code i'm using (it's more or less what i got from examples).

(function($)
{
        var COMETD_URL = "http://wwwhost/cometd";
        var cometd = $.cometd;

        $(document).ready(function() {

                cometd.configure({
                        url: COMETD_URL,
                        logLevel: 'debug'
                });

                cometd.handshake();

        });
})(jQuery);

and the firebug debug:

Initial transport is Object {}
cometd.js (line 278)
Status disconnected -> handshaking
cometd.js (line 278)
Handshake sent Object { version="1.0", more...}
cometd.js (line 278)
Send Object { url="http://wwwhost/cometd/handshake", more...}
cometd.js (line 278)
POST http://wwwhost/cometd/handshake
POST http://wwwhost/cometd/handshake
404 Not Found 104ms

EDIT

It looks like my server implementation doesn't support the URI that is other than cometd. Jquery adds at the end the type of the message so when sending handshake it sends it to: /cometd/handshake which in general looks like that /cometd/message_type.

I found function that is sending messages in the cometd.js code and the function have three paramters:

function _send(messages, longpoll, extraPath)

and this function is called for example:

 _send([message], true, 'connect');

which means i will always end up with /cometd/handshake. I have to either fix the server or comment out the append url in cometd.js.

A: 

Try setting appendMessageTypeToURL to false

cometd.configure({
    url: COMETD_URL,
    logLevel: 'debug',
    `appendMessageTypeToURL`: false
});

But as the documentation says there might be another reason why the handshake fails

The handshake may fail for several reasons:

  • you mistyped the server URL
  • the long poll transport could not be negotiated successfully
  • the server denied the handshake (for example, the authentication credentials were wrong)
  • the server crashed
  • there was a network failure
jitter
A cannot see the appendMessageTypeToURL parameter anywhere. I've checked the sources and it doesn't exist. The server URL is correct. I have all the rights to connect to the server. The only problem is the additional path.
j t
A: 

I ran into the same thing. It worked when running under maven, but not directly in jetty.

I added a file named contexts/cometd.xml to my jetty. It seems redundant, but it worked for me.

  <?xml version="1.0"  encoding="ISO-8859-1"?>
  <!DOCTYPE Configure PUBLIC "-//Mort Bay Consulting//DTD Configure//EN"   "http://jetty.mortbay.org/configure.dtd"&gt;
  <configure class="org.eclipse.jetty.webapp.WebAppContext">
    <Set name="contextPath">/</Set>
    <Set name="resourceBase"><SystemProperty name="jetty.home" default="."/>/webapps/server</Set>
  </configure>
jcohen