private String getDefaultServiceAccount() throws IOException { HttpResponse response = getMetadataResponse(getServiceAccountsUrl()); int statusCode = response.getStatusCode(); if (statusCode == HttpStatusCodes.STATUS_CODE_NOT_FOUND) { throw new IOException(String.format("Error code %s trying to get service accounts from" + " Compute Engine metadata. This may be because the virtual machine instance" + " does not have permission scopes specified.", statusCode)); } if (statusCode != HttpStatusCodes.STATUS_CODE_OK) { throw new IOException(String.format("Unexpected Error code %s trying to get service accounts" + " from Compute Engine metadata: %s", statusCode, response.parseAsString())); } InputStream content = response.getContent(); if (content == null) { // Throw explicitly here on empty content to avoid NullPointerException from parseAs call. // Mock transports will have success code with empty content by default. throw new IOException("Empty content from metadata token server request."); } GenericData responseData = response.parseAs(GenericData.class); Map<String, Object> defaultAccount = OAuth2Utils.validateMap(responseData, "default", PARSE_ERROR_ACCOUNT); return OAuth2Utils.validateString(defaultAccount, "email", PARSE_ERROR_ACCOUNT); }
private String getDefaultServiceAccount() throws IOException { HttpResponse response = getMetadataResponse(getServiceAccountsUrl()); int statusCode = response.getStatusCode(); if (statusCode == HttpStatusCodes.STATUS_CODE_NOT_FOUND) { throw new IOException(String.format("Error code %s trying to get service accounts from" + " Compute Engine metadata. This may be because the virtual machine instance" + " does not have permission scopes specified.", statusCode)); } if (statusCode != HttpStatusCodes.STATUS_CODE_OK) { throw new IOException(String.format("Unexpected Error code %s trying to get service accounts" + " from Compute Engine metadata: %s", statusCode, response.parseAsString())); } InputStream content = response.getContent(); if (content == null) { // Throw explicitly here on empty content to avoid NullPointerException from parseAs call. // Mock transports will have success code with empty content by default. throw new IOException("Empty content from metadata token server request."); } GenericData responseData = response.parseAs(GenericData.class); Map<String, Object> defaultAccount = OAuth2Utils.validateMap(responseData, "default", PARSE_ERROR_ACCOUNT); return OAuth2Utils.validateString(defaultAccount, "email", PARSE_ERROR_ACCOUNT); }
HttpResponse response = getMetadataResponse(getTokenServerEncodedUrl()); int statusCode = response.getStatusCode(); if (statusCode == HttpStatusCodes.STATUS_CODE_NOT_FOUND) {
HttpResponse response = getMetadataResponse(getTokenServerEncodedUrl()); int statusCode = response.getStatusCode(); if (statusCode == HttpStatusCodes.STATUS_CODE_NOT_FOUND) {