开发者

Jquery and cometd problems with URL and 404 errors

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开发者_StackOverflow社区. I have to either fix the server or comment out the append url in cometd.js.


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">
  <configure class="org.eclipse.jetty.webapp.WebAppContext">
    <Set name="contextPath">/</Set>
    <Set name="resourceBase"><SystemProperty name="jetty.home" default="."/>/webapps/server</Set>
  </configure>


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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜