[ejabberd] Pubsub with Ejabberd and exmpp

shahzad bhatti shahbhat at gmail.com
Fri May 7 20:45:41 MSD 2010


I wrote a simple client using exmpp library to publish JSON structure. Here
is how I am initializing:


init() ->
    ok = application:start(exmpp),
    ok = application:start(crypto),
    ok = application:start(ssl),
    ok = application:start(lhttpc),
    exmpp_xml:start_parser(),
    MySession = exmpp_session:start({1,0}),
    MyJID = exmpp_jid:make(?BOSH_USER, ?XMPP_SERVER, random),
    exmpp_session:auth_basic_digest(MySession, MyJID, ?BOSH_PASSWORD),

    {ok, _StreamId, _Features} = exmpp_session:connect_BOSH(MySession,
?BOSH_URL,
             ?XMPP_SERVER, []),
    session(MySession, MyJID).

And here is how I am sending message (which is somewhat based on bosh_client
in exmpp examples):


session(MySession, MyJID) ->
    exmpp_session:login(MySession, "PLAIN")

    exmpp_session:send_packet(MySession,
            exmpp_presence:set_status(
        exmpp_presence:available(), "Ready to Publish ")),
    loop(MySession, MyJID).


loop(MySession, MyJID) ->
    receive
        stop ->
            exmpp_session:stop(MySession);
        Record = #received_packet{packet_type=message, raw_packet=_Packet}
->
            io:format("message: ~p~n", [Record]),
            loop(MySession, MyJID)
     after 1000 ->
        Json = "{'symbol':'MSFT', 'bid':28.66, 'ask':28.67, 'bidSize':61,
'askSize':13, 'volume':'65488100, 'last':28.66}",

        IQ = exmpp_client_pubsub:publish("pubsub." ++ ?XMPP_SERVER, Symbol,
exmpp_xml:cdata(Json)),
        _PacketId = exmpp_session:send_packet(MySession,
exmpp_stanza:set_sender(IQ, MyJID)),
        loop(MySession, MyJID)
    end.


However, I get following error:


{received_packet,iq,"error",
    {undefined,<<"pubsub.myhost.local">>,undefined},
    "pubsub-2485983295",'jabber:client',
    {xmlel,'jabber:client',
        [{'jabber:client',none}],
        iq,
        [{xmlattr,undefined,from,<<"pubsub.myhost.local">>},
         {xmlattr,undefined,to,
             <<"producer at myhost.local/exmpp#1273249497148131">>},
         {xmlattr,undefined,type,<<"error">>},
         {xmlattr,undefined,id,<<"pubsub-2485983295">>}],
        [{xmlel,'http://jabber.org/protocol/pubsub',
             [{'http://jabber.org/protocol/pubsub',none}],
             pubsub,[],
             [{xmlel,'http://jabber.org/protocol/pubsub',[],publish,
                  [{xmlattr,undefined,node,<<"MSFT">>}],
                  [{xmlel,'http://jabber.org/protocol/pubsub',[],item,[],
                       [{xmlcdata,<<"{">>},
                        {xmlcdata,<<"'">>},
                        {xmlcdata,<<"symbol">>},
                        {xmlcdata,<<"'">>},
                        {xmlcdata,<<":">>},
                        {xmlcdata,<<"'">>},
                        {xmlcdata,<<"MSFT">>},
                        {xmlcdata,<<"'">>},
                        {xmlcdata,<<", ">>},
                        {xmlcdata,<<"'">>},
                        {xmlcdata,<<"bid">>},
                        {xmlcdata,<<"'">>},
                        {xmlcdata,<<":28.66, ">>},
                        {xmlcdata,<<"'">>},
                        {xmlcdata,<<"ask">>},
                        {xmlcdata,<<"'">>},
                        {xmlcdata,<<":28.67, ">>},
                        {xmlcdata,<<"'">>},
                        {xmlcdata,<<"bidSize">>},
                        {xmlcdata,<<"'">>},
                        {xmlcdata,<<":61, ">>},
                        {xmlcdata,<<"'">>},
                        {xmlcdata,<<"askSize">>},
                        {xmlcdata,<<"'">>},
                        {xmlcdata,<<":13, ">>},
                        {xmlcdata,<<"'">>},
                        {xmlcdata,<<"volume">>},
                        {xmlcdata,<<"'">>},
                        {xmlcdata,<<":">>},
                        {xmlcdata,<<"'">>},
                        {xmlcdata,<<"65488100, ">>},
                        {xmlcdata,<<"'">>},
                        {xmlcdata,<<"last">>},
                        {xmlcdata,<<"'">>},
                        {xmlcdata,<<":28.66}">>}]}]}]},
         {xmlel,'jabber:client',[],error,
             [{xmlattr,undefined,code,<<"400">>},
              {xmlattr,undefined,type,<<"modify">>}],
             [{xmlel,'urn:ietf:params:xml:ns:xmpp-stanzas',
                  [{'urn:ietf:params:xml:ns:xmpp-stanzas',none}],
                  'bad-request',[],[]},
              {xmlel,'http://jabber.org/protocol/pubsub#errors',
                  [{'http://jabber.org/protocol/pubsub#errors',none}],
                  'invalid-payload',[],[]}]}]}}




Can someone explain why I am getting invalid-payload/bad-request errors?
Thanks in advance.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.jabber.ru/pipermail/ejabberd/attachments/20100507/dbb7ca3f/attachment.html>


More information about the ejabberd mailing list