Jquery 和 cometd 的 URL 和 404 错误问题

发布于 2024-08-26 06:08:22 字数 1888 浏览 5 评论 0原文

我正在为 cometd 服务器编写 jquery 客户端(我正在使用 jquery.cometd.js 插件),但我不知道为什么最简单的可能情况不起作用。

cometd 服务器位于 apache 后面(因此它在同一个域上运行)并且所有 请求从 uri http://wwwhost/cometd 转发。

问题是,当我尝试连接(通过执行握手())到 cometd 时,它没有发送请求 直接到 /cometd 但到 /cometd/handshake 会出现 404 错误。 我检查了我正在测试的其他应用程序,dojo 始终连接到 /cometd,然后发送消息“握手”。

任何人都知道为什么 jquery.cometd 这样做?

这是我在 apache 日志中看到的内容:

- - [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)"

下面您可以找到我正在使用的代码(或多或少是我从示例中得到的)。

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

        $(document).ready(function() {

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

                cometd.handshake();

        });
})(jQuery);

和 firebug 调试:

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

编辑

看起来我的服务器实现不支持 cometd 以外的 URI。 Jquery 在末尾添加消息类型,因此在发送握手时会将其发送到: /cometd/handshake 通常看起来像 /cometd/message_type。

我发现在 cometd.js 代码中发送消息的函数,该函数具有三个参数:

function _send(messages, longpoll, extraPath)

例如,调用该函数:

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

这意味着我将始终以 /cometd/handshake 结束。 我必须修复服务器或注释掉 cometd.js 中的附加 url。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

你怎么敢 2024-09-02 06:08:22

我遇到了同样的事情。它在maven下运行时有效,但不能直接在jetty中运行。

我向我的码头添加了一个名为 contexts/cometd.xml 的文件。这似乎多余,但它对我有用。

  <?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>

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>
与酒说心事 2024-09-02 06:08:22

尝试将 appendMessageTypeToURL 设置为 false

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

但正如文档所说,握手失败可能还有另一个原因

多次握手可能会失败
原因:

  • 您输入了错误的服务器网址
  • 长轮询传输无法成功协商
  • 服务器拒绝了握手(例如,身份验证
    凭据错误)
  • 服务器崩溃
  • 出现网络故障

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文