title: UnknownHostException while connecting to Azure Cosmos DB from Java code
body: <p>I've created a simple <code>Java</code> project. And added the <code>JARs</code> to the <code>classpath</code>. In the file <strong>BulkImport.java</strong>, I'm trying to connect to the <code>Azure Cosmos DB</code>. However, I'm running into the following error.</p>
  
  <blockquote>
    <p>Warning : [main] WARN
    com.microsoft.azure.documentdb.GlobalEndpointManager - Failed to
    retrieve database account information.
    com.microsoft.azure.documentdb.DocumentClientException:
    java.net.UnknownHostException: This is usually a temporary error
    during hostname resolution and means that the local server did not
    receive a response from an authoritative server.</p>
  </blockquote>
  
  <p><strong>BulkImport.java</strong></p>
  
  <pre><code>public class BulkImport {
  
      //public static final Logger LOGGER = LoggerFactory.getLogger(BulkImport.class);
      public static final String ENDPOINT = "https://&lt;xxxx&gt;.documents.azure.com:443/";
      public static final String PRIMARY_KEY = xxxx
      public static final String DATABASE = "xxxx"
      public static final String CONTAINER = "xxxx";
      public static final String PARTITION_KEY = "/id";
      public static final int THROUGHPUT = 10000;
      public static void main(String args[]) throws Exception {
  
          executeBulkImport();
          System.out.print("Done");
      }
  
      public static void executeBulkImport() throws Exception
      {
          ConnectionPolicy connectionPolicy = new ConnectionPolicy();
          connectionPolicy.setMaxPoolSize(1000);
  
          // Below line is giving the error
          DocumentClient client = new DocumentClient(ENDPOINT, PRIMARY_KEY, connectionPolicy, ConsistencyLevel.Session);  
  
          DocumentCollection collection = Utilities.createEmptyCollectionIfNotExists(client, DATABASE, CONTAINER, PARTITION_KEY, THROUGHPUT);
          ArrayList&lt;String&gt; list = new ArrayList&lt;String&gt;();
          JSONParser jsonParser = new JSONParser();
          try (FileReader reader = new FileReader("C:\\samplejson.json")) {
  
              Object obj = jsonParser.parse(reader);
  
              JSONArray jsonArray  = (JSONArray) obj;
              System.out.println(jsonArray);
              if (jsonArray  != null) {
                  int len = jsonArray.size();
                  for (int i=0;i&lt;len;i++){
                      list.add(jsonArray.get(i).toString());
                  }
              }
              System.out.println(list.get(0));
  
          } catch (FileNotFoundException e) {
              e.printStackTrace();
          } catch (IOException e) {
              e.printStackTrace();
          } catch (ParseException e) {
              e.printStackTrace();
          }
          client.getConnectionPolicy().getRetryOptions().setMaxRetryWaitTimeInSeconds(30);
          client.getConnectionPolicy().getRetryOptions().setMaxRetryAttemptsOnThrottledRequests(9);
  
         // Builder pattern
          DocumentBulkExecutor.Builder bulkExecutorBuilder = DocumentBulkExecutor.builder().from(client, DATABASE, CONTAINER,
                  collection.getPartitionKey(), 20000);
          try {
              DocumentBulkExecutor bulkExecutor = bulkExecutorBuilder.build();
              client.getConnectionPolicy().getRetryOptions().setMaxRetryWaitTimeInSeconds(0);
              client.getConnectionPolicy().getRetryOptions().setMaxRetryAttemptsOnThrottledRequests(0);
              BulkImportResponse bulkImportResponse = bulkExecutor.importAll(list, false, false, null);
              System.out.println(bulkImportResponse.getNumberOfDocumentsImported());
          } catch (Exception e) {
              e.printStackTrace();
          }
          client.close();
      }
  }
  </code></pre>
  
  <p>Please help me understand the issue.</p>