Yahoo Gateway Access using toXML() function

Hi,

I am a user who is very new to JAVA, SMACK and JABBER. I have written a very very simple program to access a jabber account. This program works with following basic settings in the initial…

XMPPConnection connection = new XMPPConnection("jabber.org");
connection.login(MyJabberUsername,MyJabberPassword);
Presence presence = new Presence(Presence.Type.AVAILABLE);
presence.setStatus("Available");
connection.sendPacket(presence);

Then I connect to a jabber server that runs a gateway to Yahoo! called as theoretic.com using …

YahooPackets yp = new YahooPackets();
connection.sendPacket(yp.RegPacket);
connection.sendPacket(yp.AuthPacket);
connection.sendPacket(yp.PresencePacket);

Where each packet is made using the toXML method as I do follows…

class YahooPackets
{
   public Packet RegPacket = new Packet() {
   public String toXML() {
      return "<iq id=''jcl_1'' to=''yahoo.theoretic.com'' type=''get''>"+
         "<query xmlns=''jabber:iq:register''/></iq> ";       }
   };    public Packet AuthPacket = new Packet() {
      public String toXML() {
      return " <iq id=''jcl_2'' to=''yahoo.theoretic.com'' type=''set''>"+
         "<query xmlns=''jabber:iq:register''>"+
         "<username>vinit</username> <password>ScoobyDoo</password></iq>";
      }
   };    public Packet PresencePacket = new Packet() {
      public String toXML() {
         return "<presence to=''yahoo.theoretic.com/registered'' type=''subscribed''/>";
      }
   };
     
   public YahooPackets() {} /* Constructor */
};

All the process goes fine in compilation and when I run the program I see myself (vinit@yahoo.com) online on Yahoo Messenger on my other yahoo account (say vinit_sankhe@yahoo.com) where I have added myself in contacts as


vinit@yahoo.com

Then I send messages from my program to yahoo and yahoo receives it fine. But from Yahoo when I try to send messages then my program which is a JAVA Swings based Chat window doesn’'t accept it. Only SIMPLEX communication is done.

My window works perfectly fine when I chat between my program and EXODUS on my jabber account over jabber.org. here FULL DUPLEX Communication is done well.

What must be the problem?

I suppose its the IQ IDs in my XML queries. Is it. If yes then what should I do then.

Note:

  1. I have not implemented any PacketListener Yet in my program.

  2. It is me who makes the first contact with yahoo messenger by manually inputting jabber id as "vinit_sankhe@yahoo.theoretic.com" in smack based createchat()function.

  3. I have noted down these XML queries (given here) from the Debug XML function given on EXODUS when I accessed theoretic.com Yahoo agent from there.

I am a bit confused about these IQ IDs ‘‘jcl_1’’ , ‘‘jcl_2’’ etc. in these XML queries. So plz help me out.

Thanx.

Vinit Sankhe

Hi,

Two things may help. First, turn on debug in Smack and you’'ll see the XML passed between your client and the server:

http://www.jivesoftware.com/xmpp/smack/documentation/debugging.html

That should help you debug what’'s going on.

Second, since you’‘re hacking on the packets themselves, you need to get a better background on the protocol - Smack can’‘t protect you from the low level details when you’'re implementing a protocol yourself. One place to start is http://www.jabber.org. Look at the protocol descriptions and read up on the existing standards and relevant JEPs. My book http://www.manning.com/shigeoka is a good place to go if you want a book to guide you through the protocol. There are also other good books on Jabber (search on Amazon).

For starters, the iq ‘‘id’’ attribute should be a unique identifier for each packet. This allows you to match iq queries you send, with iq responses you receive. So hard coding a single id is probably not going to work for you in general. See how iq id’'s are being generated in othen Smack IQ packets and follow that example.

I suspect that you are receiving messages from Yahoo, but are not seeing them because you’‘re not listening for the correct packets. Once again, turn Smack debugging on and you can see what’‘s being sent (and hence, what you’'re either not getting, or are receiving but not detecting in your code).

Unfortunately, I’‘m not too familiar with the Yahoo gateway so you’'re going to have to do some research to figure out how that protocol works. Should be a fun hacking session though.

-iain

Hi Iain,

I have already purchased your book on Amazon.com (Instant Messaging in JAVA that helped me in gaining knowledge about the JABBER system and made my academic project report easier. )

Thank you for ur valuable help. The SMACK DEBUGGER was Great!

It showed me that I was actually receiving Yahoo! Messages. … (Interoperabilty on smack works!).

Now I just need to implement a PacketListener and perform Packet processing on PacketReceiving Event.

But tell me one thing, what are these filters all about ?Whats the difference between OR and AND filters in smack. Are they abosolutely essential?

Any good example of implementing PacketListener and processing a packetevent when received on this listener. So that I can continue with my work to add more and more smack features.

I hope u will reply me soon,

Bye,

Vinit Sankhe.

Vinit,

A PacketFilter is used to filter the packets that are delivered to a PacketListener or PacketCollector (in other words, the filter decides which packets get processed). The AndFilter and OrFilter let you combine a few filters together. For example, let’'s say you want to listen for all packets that are message packets AND that have a packet ID 5. You could do this with:

PacketFilter filter = new AndFilter(new PacketTypeFilter(Message.class), new PacketIDFilter(5));

Or, you could create a filter that listened for message packets OR presence packets using the OR filter.

I’'d definitely appreciate specific suggestions about how the documentation could be improved. Are there particular aspects that are confusing or not explained well enough?

Regards,

Matt