openfire smack发送包404错误意味着什么?

时间:2009-10-13 03:19:29

标签: java openfire

当使用Smack将数据包发送到openfire时,我得到错误remote-server-not-found(404)。任何人都可以解释这个错误意味着什么?它意味着无法连接到服务器或数据包有问题?

        PacketFilter responseFilter = new PacketIDFilter(packet.getPacketID());
        PacketCollector response = connection.createPacketCollector(responseFilter);

        connection.sendPacket(packet);



        // Wait up to a certain number of seconds for a reply.
        Packet result = response.nextResult(timeout);



        // Stop queuing results
        response.cancel();



        if (result == null) {
            throw new XMPPException("No response from server.");
        }
        else if (result.getError() != null) {  

            System.out.println("error:"+result.getError());   //i get error here.... 404
            throw new XMPPException(result.getError());
        }

// ---下面是我如何连接到openfire。

        ConnectionConfiguration config = new ConnectionConfiguration("localhost", 5222);
        config.setCompressionEnabled(true);
        config.setSASLAuthenticationEnabled(true);



        XMPPConnection connection = new XMPPConnection(config);
        // Connect to the server
        connection.connect();
        // Log into the server
        connection.login("test", "test","testresource");

我附上了从日志

收到的xmpp xml

...发送

<stream:stream to="localhost" xmlns="jabber:client" xmlns:stream="http://etherx.jabber.org/streams" version="1.0">
<starttls xmlns="urn:ietf:params:xml:ns:xmpp-tls"/>
<stream:stream to="xuser" xmlns="jabber:client" xmlns:stream="http://etherx.jabber.org/streams" version="1.0">
<auth mechanism="DIGEST-MD5" xmlns="urn:ietf:params:xml:ns:xmpp-sasl"></auth>
<response xmlns="urn:ietf:params:xml:ns:xmpp-sasl">Y2hhcnNldD11dGYtOCx1c2VybmFtZT0idGVzdCIscmVhbG09InpoYW5nIixub25jZT0ieHZacDFOdHlkcld6MVBzOFA0UGlnbWgrbHRieWtyclNYU0NLWVJaRyIsbmM9MDAwMDAwMDEsY25vbmNlPSIxdThheGtJSWgrSzhBLzFBSDRtTHJ5OUxDTE1OSFpBa0xvdlVGcVFGIixkaWdlc3QtdXJpPSJ4bXBwL3poYW5nIixtYXhidWY9NjU1MzYscmVzcG9uc2U9MGE3YzEzOWRkODliZjk5NDcxN2ZiNjQzY2E5NWM3ZDUscW9wPWF1dGgsYXV0aHppZD0idGVzdCI=</response>
<stream:stream to="xuser" xmlns="jabber:client" xmlns:stream="http://etherx.jabber.org/streams" version="1.0">
<iq id="CHWuJ-0" type="set"><bind xmlns="urn:ietf:params:xml:ns:xmpp-bind"><resource>god</resource></bind></iq>
<iq id="CHWuJ-1" type="set"><session xmlns="urn:ietf:params:xml:ns:xmpp-session"/></iq>
<compress xmlns='http://jabber.org/protocol/compress'>
<method>zlib</method></compress>
<stream:stream to="xuser" xmlns="jabber:client" xmlns:stream="http://etherx.jabber.org/streams" version="1.0">
<iq id="CHWuJ-2" type="get"><query xmlns="jabber:iq:roster"></query></iq>
<presence id="CHWuJ-3"></presence>
<iq id="CHWuJ-4" to="pubsub.my.openfire.server" type="set"><pubsub xmlns="http://jabber.org/protocol/pubsub"><create node='TestNode2323'/><configure><x xmlns="jabber:x:data" type="submit"><field var="pubsub#persist_items" type="boolean"><value>0</value></field><field var="pubsub#deliver_payloads" type="boolean"><value>1</value></field><field var="pubsub#access_model" type="list-single"><value>open</value></field></x></configure></pubsub></iq>

...接收

<?xml version='1.0' encoding='UTF-8'?><stream:stream xmlns:stream="http://etherx.jabber.org/streams" xmlns="jabber:client" from="xuser" id="d0689fdf" xml:lang="en" version="1.0"><stream:features><starttls xmlns="urn:ietf:params:xml:ns:xmpp-tls"></starttls>
<mechanisms xmlns="urn:ietf:params:xml:ns:xmpp-sasl"><mechanism>PLAIN</mechanism><mechanism>CRAM-MD5</mechanism><mechanism>ANONYMOUS</mechanism><mechanism>DIGEST-MD5</mechanism></mechanisms><compression xmlns="http://jabber.org/features/compress"><method>
zlib</method></compression><auth xmlns="http://jabber.org/features/iq-auth"/><register xmlns="http://jabber.org/features/iq-register"/></stream:features><proceed xmlns="urn:ietf:params:xml:ns:xmpp-tls"/>
<?xml version='1.0' encoding='UTF-8'?><stream:stream xmlns:stream="http://etherx.jabber.org/streams" xmlns="jabber:client" from="xuser" id="d0689fdf" xml:lang="en" version="1.0"><stream:features><mechanisms xmlns="urn:ietf:params:xml:ns:xmpp-sasl">
<mechanism>PLAIN</mechanism><mechanism>CRAM-MD5</mechanism><mechanism>ANONYMOUS</mechanism><mechanism>DIGEST-MD5</mechanism></mechanisms><compression xmlns="http://jabber.org/features/compress"><method>zlib</method></compression>
<auth xmlns="http://jabber.org/features/iq-auth"/><register xmlns="http://jabber.org/features/iq-register"/></stream:features>
<challenge xmlns="urn:ietf:params:xml:ns:xmpp-sasl">
cmVhbG09InpoYW5nIixub25jZT0ieHZacDFOdHlkcld6MVBzOFA0UGlnbWgrbHRieWtyclNYU0NLWVJaRyIscW9wPSJhdXRoIixjaGFyc2V0PSJ1dGYtOCIsYWxnb3JpdGhtPSJtZDUtc2VzcyI=</challenge>
<success xmlns="urn:ietf:params:xml:ns:xmpp-sasl">
cnNwYXV0aD1jOWIyOWIxYTMwN2Q5ZjdkYmZiOGM4MDBkMTU4OWFmZQ==</success>
<?xml version='1.0' encoding='UTF-8'?><stream:stream xmlns:stream="http://etherx.jabber.org/streams" xmlns="jabber:client" from="xuser" id="d0689fdf" xml:lang="en" version="1.0"><stream:features><compression xmlns="http://jabber.org/features/compress"><method>zlib</method></compression><bind xmlns="urn:ietf:params:xml:ns:xmpp-bind"/><session xmlns="urn:ietf:params:xml:ns:xmpp-session"/></stream:features>
<iq type="result" id="CHWuJ-0" to="xuser/d0689fdf"><bind xmlns="urn:ietf:params:xml:ns:xmpp-bind"><jid>test@xuser/god</jid></bind></iq>
<iq type="result" id="CHWuJ-1" to="test@xuser/god"><session xmlns="urn:ietf:params:xml:ns:xmpp-session"/></iq>
<compressed xmlns='http://jabber.org/protocol/compress'/>
<?xml version='1.0' encoding='UTF-8'?><stream:stream xmlns:stream="http://etherx.jabber.org/streams" xmlns="jabber:client" from="xuser" id="d0689fdf" xml:lang="en" version="1.0"><stream:features><bind xmlns="urn:ietf:params:xml:ns:xmpp-bind"/><session xmlns="urn:ietf:params:xml:ns:xmpp-session"/></stream:features>
<iq type="result" id="CHWuJ-2" to="test@xuser/god"><query xmlns="jabber:iq:roster"><item jid="test" name="test" subscription="none"/></query></iq>
<iq type="error" id="CHWuJ-4" to="test@xuser/god" from="pubsub.my.openfire.server"><pubsub xmlns="http://jabber.org/protocol/pubsub"><create node="TestNode2323"/><configure><x xmlns="jabber:x:data" type="submit"><field var="pubsub#persist_items" type="boolean"><value>0</value></field><field var="pubsub#deliver_payloads" type="boolean"><value>1</value></field><field var="pubsub#access_model" type="list-single"><value>open</value></field></x></configure></pubsub><error code="404" type="cancel"><remote-server-not-found xmlns="urn:ietf:params:xml:ns:xmpp-stanzas"/></error></iq>

Intepreted ..

<iq id="CHWuJ-0" to="xuser/d0689fdf" type="result"><bind xmlns="urn:ietf:params:xml:ns:xmpp-bind"><jid>test@xuser/god</jid></bind></iq>
<iq id="CHWuJ-1" to="test@xuser/god" type="result"></iq>
<iq id="CHWuJ-2" to="test@xuser/god" type="result"><query xmlns="jabber:iq:roster"><item jid="test" name="test" subscription="none"></item></query></iq>
<iq id="CHWuJ-4" to="test@xuser/god" from="pubsub.my.openfire.server" type="error"><pubsub xmlns="http://jabber.org/protocol/pubsub"><create node='TestNode2323'/><configure xmlns="http://jabber.org/protocol/pubsub"><value>0</value></configure></pubsub><error code="404" type="CANCEL"><remote-server-not-found xmlns="urn:ietf:params:xml:ns:xmpp-stanzas"/></error></iq>

3 个答案:

答案 0 :(得分:5)

我遇到了一个类似的问题,我刚刚解决了。

我在本地计算机上运行了一个Openfire服务器,我正在使用Smack API与服务器通信。在Openfire中,我定义了两个用户:发送者和接收者。我没有使用电子邮件地址作为用户名。

在我的代码中,我在一个线程上连接了“sender”,在一个单独的线程上连接了“receiver”。最初,在发送消息时,我收到了来自Openfire服务器的remote-server-not-found(404)错误响应。我发现,在发件人创建聊天请求时,我需要将参与者设置为receiver@[Openfire domain]

因此,如果您的Openfire域名为 foo ,则为receiver@foo。显然,这不是“接收者”用户的电子邮件地址。通常,域实际上只是运行Openfire服务器的计算机的名称。

答案 1 :(得分:4)

此错误由服务器生成(请参阅XMPPError)。我试着自己得到完全相同的错误代码,但失败了。但是,我觉得这是服务器的错误配置。您尝试与其他客户端连接,例如使用您最喜欢的Jabber客户端?

您还可以尝试启用Smacks XMPP调试功能并发布导致错误的消息:

static {
    XMPPConnection.DEBUG_ENABLED = true;
}

(您可能还想添加smackx-debug.jar以获得更多调试功能)

答案 2 :(得分:2)

请检查数据包是否发送给了正确的用户!

您应该为iq数据包的“to”属性设置有效的JID,以便服务器可以将数据包发送到接收方。 之前我收到此错误,因为我将错误的JID设置为数据包。

顺便说一句,您可以在代码中添加XMPPConnection.DEBUG_ENABLED = true,以查看您发送的内容或查看openfire Web控制台中的错误日志,您可能会发现以下错误: 尝试连接到远程服务器时出错:theWrongHost(DNS查找:theWrongHost:5269)