powered by Jive Software

Gateway Related Help? <Urgent>

Hi,

I have an msn account testuser@yahoo.com and i have added many users via msn. Now i want to add this msn account as msn transport in Openfire using smack API.

I am able to add gateway registration through smack but can’t login. How to retreive rosters from my msn transport.

msn.xenon173 (msn.zenon173) [subscribe] - [none][null] -------------> When and How this will be “subscribed”

SASL authentication failed using mechanism DIGEST-MD5:

Here is the code

import java.awt.image.BufferedImage;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.*;
import javax.imageio.ImageIO;

import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.filter.OrFilter;
import org.jivesoftware.smack.filter.PacketFilter;
import org.jivesoftware.smack.filter.PacketIDFilter;
import org.jivesoftware.smack.filter.PacketTypeFilter;
import org.jivesoftware.smack.packet.;
import org.jivesoftware.smackx.packet.VCard;
import org.jivesoftware.smack.
;

public class XMPPTest {

// ++++++++++++++++++ RosterListener ++++++++++++++++++++++++++++ //
   
public static void CreateRosterListener(Roster roster)
{
    roster.addRosterListener(new RosterListener() {
    public void entriesAdded(Collection addresses) {}
    public void entriesDeleted(Collection addresses) {}
    public void entriesUpdated(Collection addresses) {}              
    public void presenceChanged(Presence presence) {
                           
        System.out.println("Presence changed: " + presence.getFrom() + " " + presence+ "\n");
    }
    });
}

// ++++++++++++++++++++ RetreiveRosters +++++++++++++++++++++++++++++++ //
   
    public static void RetreiveRosters(Roster roster,Collection entries)
    {
        Iterator it = entries.iterator();
       
        while(it.hasNext())
        {
            RosterEntry entry  = (RosterEntry) it.next();   
           
            Presence prsn = roster.getPresence(entry.getUser());
           
            System.out.println(entry.getName() + " (" + entry.getUser() + ")  ["+entry.getStatus()+ "] - [" + entry.getType() + "][" + prsn.getStatus() + "]" );                               
        }           
    }                           
   
static class GatewayRegisterExtension implements PacketExtension
{
     public String getElementName()
     {
          return "x";
     }

     public String getNamespace()
     {
          return "jabber:iq:gateway:register";
     }

     public String toXML()
     {
          StringBuilder builder = new StringBuilder();
          builder.append("<").append(getElementName()).append(" xmlns=\"").append(getNamespace()).append("\"/>");
          return builder.toString();
     }
}   


public static void register(XMPPConnection conn, String gateway, String username, String password, String nickname) throws XMPPException
{     if(username == null || username.length() == 0 ||
               password == null || password.length() == 0 ||
               nickname == null || nickname.length() == 0 ||
               gateway == null || gateway.length() == 0)
          throw new XMPPException("Incorrect paramaters");

     Registration registration = new Registration();
     registration.setType(IQ.Type.SET);
     registration.setTo(gateway);
     registration.addExtension(new GatewayRegisterExtension());

     Map attributes = new HashMap();
     if (username != null) attributes.put("username", username);
     if (password != null) attributes.put("password", password);
     if (nickname != null) attributes.put("nick", nickname);
     registration.setAttributes(attributes);             
    
     PacketCollector collector = conn.createPacketCollector(new PacketIDFilter(registration.getPacketID()));
     conn.sendPacket(registration);

     IQ response = (IQ) collector.nextResult(SmackConfiguration.getPacketReplyTimeout());
     collector.cancel();
     if(response == null) throw new XMPPException("Server timed out");
     if(response.getType() == IQ.Type.ERROR)
     {
         System.out.println(response.getXmlns());
         System.out.println(response.getChildElementXML());
         throw new XMPPException("Error registering user", response.getError());
     }                
                      
     if(!conn.getRoster().contains(gateway))
          conn.getRoster().createEntry(gateway, gateway, null);

     Presence subscribe = new Presence(Presence.Type.subscribe);
     subscribe.setTo(gateway);
     subscribe.setFrom(conn.getUser());
     conn.sendPacket(subscribe);                                                             
}

public static void main(String args[])
{
    try
    {
        XMPPConnection connection = new XMPPConnection("213.152.231.133");         
                   
        connection.connect();
           
        if(connection.isConnected())
         {                               
            connection.login("testuser@xeno173", "test123");                           
           
            Roster roster = connection.getRoster();
            Collection entries = roster.getEntries();
       
            RetreiveRosters(roster,entries);
            CreateRosterListener(roster);                                                                   
        }
                                                                                                      
        register(connection,"msn.xeno173","testuser@yahoo.com","test123","MyMSN");
       
        XMPPConnection connection1 = new XMPPConnection("213.152.231.133");
        connection1.connect();
        SASLAuthentication.supportSASLMechanism("DIGEST-MD5", 0);
        connection1.login("msn.xeno173", "testuser@yahoo.com", "test123");
                   
    }
    catch(Exception e)
    {
              System.out.println(e);
    }

}

}

Hi,

I got the solution myself.

  1. Register gateway / transport like msn, gtalk,yahoo as shown in the avobe code
  2. Next you have to add that transport to your roster means gtalk.domain_name, msn.domain_name etc…

public void XMPPAddRosterEntry(Roster roster, String userIDWithDomainName, String userNickName, String Reserved)
{
try
{
roster.createEntry(userIDWithDomainName, userNickName, null);
}
catch(Exception e)
{
System.out.println("ADD_ROSTER_ERROR: "+ e);
}
}

XMPPAddRosterEntry(roster, “gtalk.yourdomain”, “MyGtalk”,null);

avobe code works for me.

But is there a way to check that roster is properly added to my roster?

is there a way that transport / gateway registration is successfull?

is there a way to know whether registering a new user is done correctly?

Thanks,

Samba

  • Edit
  • Reply