Posting data to endpoints Here's the code I am trying to refactor. The same Http client is being used in each nested try with resource. I don't understand the rationale behind nesting client.execute() calls.
The code tries to Post data to an endpoint if resource is missing and retries to Post to a backup endpoint if earlier call fails
public void makeSeveralApiCalls() throws Exception {
  try (final CloseableHttpClient client = HttpClients.createDefault()) {
    try (final CloseableHttpResponse response = client.execute(httpGetUri())){
      if (response.getStatusLine().getStatusCode() == 404) {
        // Resource not found, Post data to Microservice A
        try (final CloseableHttpResponse nestedResponse = client.execute(httpPostToMicroserviceA())) {
          if (resp.getStatusLine().getStatusCode() == 201) {
            LOGGER.info(&quot;Success&quot;);
          } else {
            // Microservice A could not consume data, log error response
            final String responseString = EntityUtils.toString(resp.getEntity());
            LOGGER.debug(&quot;Error response: &quot; + responseString);
            // Try to Post to Microservice B
            try (final CloseableHttpResponse subResponse = client.execute(httpPostToMicroserviceB())) {
              if (resp.getStatusLine().getStatusCode() == 201) {
                LOGGER.info(&quot;Success&quot;);
              } else {
                // Is this exception propagated to the caller?
                throw new RuntimeException(&quot;Very bad unrecoverable state&quot;);
              }
          }
       }
    }
  }
}

Is this a valid way to call multiple executes on the same HTTP client in a nested fashion. Is it better to separate out each client.execute() call?
First of all you should split up this method into smaller ones. The inline comment give you a perfect sign what should be extracted.
Also *try with resource&quot; can handle more than one resource in a single statement.
public void makeSeveralApiCalls() throws Exception {
  try (final CloseableHttpClient client = HttpClients.createDefault();
       final CloseableHttpResponse response = client.execute(httpGetUri());
      ){
      if (response.getStatusLine().getStatusCode() == 404) {
        // Resource not found
        postDataToMicroserviceA(client, response);      
       }
    }
}

private void postDataToMicroserviceA(CloseableHttpClient client, CloseableHttpResponse response){
  try (final CloseableHttpResponse nestedResponse = client.execute(httpPostToMicroserviceA())) {
          if (resp.getStatusLine().getStatusCode() == 201) {
            LOGGER.info(&quot;Success&quot;);
          } else {
            // Microservice A could not consume data, 
            logErrorResponse(client, response);           
          }
  }
}

private void logErrorResponse(CloseableHttpClient client, CloseableHttpResponse response)
            final String responseString = EntityUtils.toString(resp.getEntity());
            LOGGER.debug(&quot;Error response: &quot; + responseString);
            // Try to Post to Microservice B
            try (final CloseableHttpResponse subResponse = client.execute(httpPostToMicroserviceB())) {
              if (resp.getStatusLine().getStatusCode() == 201) {
                LOGGER.info(&quot;Success&quot;);
              } else {
                // Is this exception propagated to the caller?
                throw new RuntimeException(&quot;Very bad unrecoverable state&quot;);
              }
}

Of cause this could be optimized a bit more if you find a more generalized solution to merge postDataToMicroserviceA() and logErrorResponse(), since basically they do the same...