Detecting gateways with ServiceDiscoveryManager, service-unavailable(503) ERROR

Hi,

I´m trying to detect gateways to other protocols using Smack. I´m using this code from the forums, that is supposed to work well.

I´m using the class “ServiceDiscoveryManager” and I´m getting an error “service-unavailable(503)”

This is the code I´m using.

We can call this function with “msn” and the current connection and look for an MSN gateway for example.

public static boolean isGateway(String gwPrefix,XMPPConnection connection) throws XMPPException {

System.out.println("starting for gateway " + gwPrefix);
ServiceDiscoveryManager discoveryManager = new ServiceDiscoveryManager(connection);

String connHost = connection.getHost(); //getHost();
String gatewayJid = gwPrefix + “.” + connHost;

    System.out.println("discoverin item "+gatewayJid+" on " + connHost);
    DiscoverItems items = discoveryManager.discoverItems(connHost);
    Iterator itemIter = items.getItems();
    boolean gatewaySupported = false;
    while (itemIter.hasNext()) {
        DiscoverItems.Item item = (DiscoverItems.Item) itemIter.next();
        if (item.getEntityID().startsWith(gwPrefix)) {
            gatewaySupported = true;
        }
    }
    return gatewaySupported;

}

I have spent several hours and I haven´t found the clue.

Thanks in advance

That code looks like it should work. The only thing i would do differently is use connection.getServiceName(), it may return exactly the same thing but from reading the api it looks like getHost() will return the IP address sometimes if the DNS doesn’t have an entry.

Have a look at http://www.igniterealtime.org/community/message/180504

I just dumped a heap of code there that does what you are trying to do.

-Mandy

At the end the problem was, that:

With Smack you should be registered at the same server you are trying to use the gateways.

With “psy” client you can use gateways from other servers.

That´s why I get the error.