code: public Jid findRegistry()
                      throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
          if (preconfiguredRegistry != null) {
              return preconfiguredRegistry;
          }
  
          final XMPPConnection connection = connection();
          ServiceDiscoveryManager sdm = ServiceDiscoveryManager.getInstanceFor(connection);
          List<DiscoverInfo> discoverInfos = sdm.findServicesDiscoverInfo(Constants.IOT_DISCOVERY_NAMESPACE, true, true);
          if (!discoverInfos.isEmpty()) {
              return discoverInfos.get(0).getFrom();
          }
  
          return null;
      }
docs: Try to find an XMPP IoT registry.
  
  @return the JID of a Thing Registry if one could be found, <code>null</code> otherwise.
  @throws InterruptedException
  @throws NotConnectedException
  @throws XMPPErrorException
  @throws NoResponseException
  @see <a href="http://xmpp.org/extensions/xep-0347.html#findingregistry">XEP-0347 § 3.5 Finding Thing Registry</a>