Retreiving available transport from openfire using smack

Hi,

You can use the below function to retreive / list all the available transports from your open fire server.

Please call this function after connection and login otherwise you will get 401 not authorized error.

In the below code i am doing thisas shown below because openfire returns xmpp for gtalk

if(gatewayID.indexOf(“gtalk”) > -1)

{

        gatewayType = "gtalk";                                        

}

public static Hashtable<String, String> XMPPGetAvailableTransports(XMPPConnection connection)
        {
             ServiceDiscoveryManager manager = ServiceDiscoveryManager.getInstanceFor(connection);
             DiscoverItems items;
             try
             {
                  items = manager.discoverItems(connection.getServiceName());
             }
             catch (XMPPException e)              {
                  items = new DiscoverItems();
             }
                              Hashtable<String, String> availableTransports = new Hashtable<String, String>();
             Iterator<DiscoverItems.Item> iterator = items.getItems();
                          while(iterator.hasNext())
             {
                  DiscoverItems.Item item = iterator.next();
                  try
                  {
                       DiscoverInfo info = manager.discoverInfo(item.getEntityID());
                       if(info.containsFeature("jabber:iq:gateway"))
                       {
                            Iterator<DiscoverInfo.Identity> identities = info.getIdentities();
                            while(identities.hasNext())
                            {
                                 DiscoverInfo.Identity identity = identities.next();                                  if ("gateway".equals(identity.getCategory()))
                                 {
                                     String gatewayID    = item.getEntityID();
                                     String gatewayType = identity.getType();                                                                                                                                                   if(gatewayID.indexOf("gtalk") > -1)
                                     {
                                         gatewayType = "gtalk";                                                                              }
                                                                          availableTransports.put(identity.getType(), item.getEntityID());                                                                                                               System.out.println(gatewayType+", " +gatewayID);
                                 }
                                                                 }
                       }
                  }
                  catch(Exception e)
                  {
                  }                           }
                      return availableTransports;
        }

Regards,

Samba

answered in above post