Hi,
I have installed openfire and also installed IM plugins into openfire.
Registered a MSN transport into my openfire gateway page.
Now how / which smack API i should use to fetch my msn contacts?
Regards,
Samba
Hi,
I have installed openfire and also installed IM plugins into openfire.
Registered a MSN transport into my openfire gateway page.
Now how / which smack API i should use to fetch my msn contacts?
Regards,
Samba
I am using the code below. I am able to register yahoo , gtalk transports through my code but unable to fetch contact list. But aftre i logged in through pidgin and loged out my code is able to fetch contacts from msn / gtalk.
do i need to login after registration? How?
I guees i have posted same type of query before, SORRY!!!
import java.util.;
import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.filter.PacketIDFilter;
import org.jivesoftware.smack.packet.;
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.DEBUG_ENABLED = true; XMPPConnection connection = new XMPPConnection("213.151.231.133"); connection.connect(); if(connection.isConnected()) { connection.login("testuser@xenon173", "test123"); Roster roster = connection.getRoster(); Collection entries = roster.getEntries(); RetreiveRosters(roster,entries); CreateRosterListener(roster); } register(connection,"gtalk.xenon173","test123","test123","MyGtalk");
register(connection,"msn.xenon173","test123@yahoo.com","test123","MyMsn"); } catch(Exception e) { System.out.println(e); }
}
}
Hi,
I got the solution myself.
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
Questions:
But is there a way to check that roster is properly added to my roster?
is there a way that transport / gateway registration is success full?
is there a way to know whether registering a new user is done correctly?