Skip navigation
3790 Views 9 Replies Latest reply: Jan 29, 2010 4:08 PM by rcollier RSS
snapshot Bronze 4 posts since
Jan 14, 2010
Currently Being Moderated

Jan 14, 2010 8:16 AM

400 bad request when retrieving pubsub messages

Hi.  I am trying to use the smack api and pubsub to retrieve persisted pubsub messages but I am getting a 400 bad request error instead of the list of messages.  I have a node named theNode created that has a number of messages associated with it.  I have verified that the node and messages exists on the openfire server using the xml console in psi.  I am using the latest svn of the smack api and the latest binary release of openfire.  I am using the following code. 

import java.util.*;
import org.jivesoftware.smack.*;
import org.jivesoftware.smack.packet.*;
import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smackx.pubsub.ConfigureForm;
import org.jivesoftware.smackx.pubsub.AccessModel;
import org.jivesoftware.smackx.pubsub.FormType;
import org.jivesoftware.smackx.pubsub.LeafNode;
import org.jivesoftware.smackx.pubsub.PubSubManager;
import org.jivesoftware.smackx.pubsub.Node;
import org.jivesoftware.smackx.pubsub.listener.*;
import org.jivesoftware.smackx.pubsub.*;
import org.jivesoftware.smackx.pubsub.PayloadItem;
import org.jivesoftware.smackx.pubsub.Node;
import org.jivesoftware.smackx.packet.DiscoverItems;
import org.jivesoftware.smackx.packet.DiscoverItems.Item;
        
ConnectionConfiguration config = new ConnectionConfiguration("mymachine", 5222);
XMPPConnection connection = new XMPPConnection(config);
connection.connect();
connection.login("notify@mymachine", "");
PubSubManager manager = new PubSubManager(connection, "pubsub.mymachine");
 
LeafNode myNode = (LeafNode) manager.getNode("theNode");
 
Collection<? extends org.jivesoftware.smackx.pubsub.Item> items = myNode.getItems();
       
       
However, when I run this I get a bad request 400.  I have looked at the packet being sent to the server for the getItems request and it looks like this:
<iq id="B9tI0-4" to="pubsub.mymachine" type="get"><query xmlns="http://jabber.org/protocol/disco#info" node="theNode"></query></iq>
<iq id="B9tI0-5" to="pubsub.mymachine" type="get"><pubsub xmlns="http://jabber.org/protocol/pubsub"><items node='theNode'/></pubsub></iq>
One thought: it seems that the iq packet is sending a <pubsub> node for the request.  Is this correct?  When I look at the reference specs it says something like the following should be sent:
<iq type='get'
    from='notifyserver@mymachine'
    to='pubsub.mymachine'
    id='items1'>
  <query xmlns='http://jabber.org/protocol/disco#items'
         node='theNode'/>
</iq>
and when I send this directly to the server using the xml condole in psi I get back the proper results. Can anyone help with this?  Thanks very much.
  • rcollier KeyContributor 600 posts since
    Mar 4, 2009
    Currently Being Moderated
    Jan 14, 2010 11:32 AM (in response to snapshot)
    Re: 400 bad request when retrieving pubsub messages

    Can you post the full reply stanza. It will have reasons as to why it failed.

     

    This method is used many times within the testcases for pubsub included within the Smack source code, and it runs fine there.

  • rcollier KeyContributor 600 posts since
    Mar 4, 2009
    Currently Being Moderated
    Jan 14, 2010 11:40 AM (in response to snapshot)
    Re: 400 bad request when retrieving pubsub messages
    This is the stanza (as per the spec) for retrieving the items from a node.

    <iq type='get'
        from='francisco@denmark.lit/barracks'
        to='pubsub.shakespeare.lit'
        id='items1'>
      <pubsub xmlns='http://jabber.org/protocol/pubsub'>
        <items node='princely_musings'/>
      </pubsub>
    </iq>

     

     

    The example you gave is for the generic discovery mechanism, which will also retrieve the list of items from the node as disco items, which is a standardized format for information defined in the Service Discovery specification.  The results of this will not include pubsub item specifics, like the payload.  The LeafNode.discoverItems() is what actually sends that particular stanza.

    • rcollier KeyContributor 600 posts since
      Mar 4, 2009
      Currently Being Moderated
      Jan 28, 2010 7:40 AM (in response to snapshot)
      Re: 400 bad request when retrieving pubsub messages

      OK, I logged that issue under OF-338.  I am assuming that you mean the subId is in the message when you say the subId is sent back, even though you do not have multiple subscriptions.

       

      I have noticed that when a node is created, the owner is automatically subscribed.  So if you create a node and then subscribe to it, I am pretty sure you will end up being subscribed twice.  This is already logged as OF-8.

More Like This

  • Retrieving data ...

Bookmarked By (0)

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points