diff --git a/components/camel-jira/src/main/java/org/apache/camel/component/jira/consumer/AbstractJiraConsumer.java b/components/camel-jira/src/main/java/org/apache/camel/component/jira/consumer/AbstractJiraConsumer.java index 5329a1a64f44c..c9210811a5dd0 100644 --- a/components/camel-jira/src/main/java/org/apache/camel/component/jira/consumer/AbstractJiraConsumer.java +++ b/components/camel-jira/src/main/java/org/apache/camel/component/jira/consumer/AbstractJiraConsumer.java @@ -26,6 +26,7 @@ import com.atlassian.jira.rest.client.api.SearchRestClient; import com.atlassian.jira.rest.client.api.domain.Issue; import com.atlassian.jira.rest.client.api.domain.SearchResult; +import com.atlassian.jira.rest.client.internal.async.AsynchronousCloudSearchRestClient; import org.apache.camel.Exchange; import org.apache.camel.ExchangePropertyKey; import org.apache.camel.Processor; @@ -125,18 +126,26 @@ protected Queue getIssues(String jql, int start, int maxPerQuery, int max Set issues = new LinkedHashSet<>(); while (true) { SearchRestClient searchRestClient = endpoint.getClient().getSearchClient(); - SearchResult searchResult = searchRestClient.searchJql(jql, maxPerQuery, start, null).claim(); + // *navigable should be the default value, but it does not seem to be true with 6.0.2 client + SearchResult searchResult = searchRestClient.searchJql(jql, maxPerQuery, start, Set.of("*navigable")).claim(); for (Issue issue : searchResult.getIssues()) { issues.add(issue); } - // Note: #getTotal == the total # the query would return *without* pagination, effectively telling us + // Note: the total # the query would return *without* pagination, effectively telling us // we've reached the end. Also exit early if we're limiting the # of results or // if total # of returned issues is lower than the actual page size. - if (maxPerQuery >= searchResult.getTotal() || - start >= searchResult.getTotal() || - maxResults > 0 && issues.size() >= maxResults) { + int total; + if (searchRestClient instanceof AsynchronousCloudSearchRestClient) { + // calling searchResult.getTotal() on AsynchronousCloudSearchRestClient throws an exception: + // Total is not available in the Cloud version of the new Search API response. + // Please use `SearchRestClient.totalCount` instead to fetch the estimated count of the issues for a given JQL + total = searchRestClient.totalCount(jql).claim().getCount(); + } else { + total = searchResult.getTotal(); + } + if (maxPerQuery >= total || start >= total || maxResults > 0 && issues.size() >= maxResults) { break; }