From 11e423ea84634cf39728ece846f74a806758878e Mon Sep 17 00:00:00 2001 From: agazzarini Date: Wed, 8 Apr 2020 21:50:45 +0200 Subject: [PATCH] [ SEARCH-2180 ] Fix compilation errors --- .../alfresco/solr/client/SOLRAPIClient.java | 80 +++++++++++++++++-- 1 file changed, 75 insertions(+), 5 deletions(-) diff --git a/search-services/alfresco-solrclient-lib/src/main/java/org/alfresco/solr/client/SOLRAPIClient.java b/search-services/alfresco-solrclient-lib/src/main/java/org/alfresco/solr/client/SOLRAPIClient.java index c64fd87a2..9f4b61de2 100644 --- a/search-services/alfresco-solrclient-lib/src/main/java/org/alfresco/solr/client/SOLRAPIClient.java +++ b/search-services/alfresco-solrclient-lib/src/main/java/org/alfresco/solr/client/SOLRAPIClient.java @@ -1127,12 +1127,47 @@ public class SOLRAPIClient * @throws AuthenticationException * @throws NoSuchMethodException */ - public Long getNextTxCommitTime(String coreName, Long fromCommitTime) throws AuthenticationException, IOException + public Long getNextTxCommitTime(String coreName, Long fromCommitTime) throws AuthenticationException, IOException, NoSuchMethodException { StringBuilder url = new StringBuilder(GET_NEXT_TX_COMMIT_TIME); url.append("?").append("fromCommitTime").append("=").append(fromCommitTime); GetRequest get = new GetRequest(url.toString()); - JSONObject json = callRepository(GET_NEXT_TX_COMMIT_TIME, get); + Response response = null; + JSONObject json = null; + LookAheadBufferedReader reader = null; + try + { + response = repositoryHttpClient.sendRequest(get); + if (response.getStatus() != HttpStatus.SC_OK) + { + throw new NoSuchMethodException(coreName + " - GetNextTxCommitTime return status is " + + response.getStatus() + " when invoking " + url); + } + + reader = new LookAheadBufferedReader(new InputStreamReader(response.getContentAsStream(), StandardCharsets.UTF_8), LOGGER); + json = new JSONObject(new JSONTokener(reader)); + } + catch (JSONException exception) + { + String message = "Received a malformed JSON payload. Request was \"" + + get.getFullUri() + + "Data: " + + ofNullable(reader) + .map(LookAheadBufferedReader::lookAheadAndGetBufferedContent) + .orElse("Not available"); + LOGGER.error(message); + throw exception; + } + finally + { + ofNullable(response).ifPresent(Response::release); + silentlyClose(reader); + } + + if (LOGGER.isDebugEnabled()) + { + LOGGER.debug(json.toString()); + } return Long.parseLong(json.get("nextTransactionCommitTimeMs").toString()); } @@ -1149,15 +1184,50 @@ public class SOLRAPIClient * @throws NoSuchMethodException */ public Pair getTxIntervalCommitTime(String coreName, Long fromNodeId, Long toNodeId) - throws AuthenticationException, IOException + throws AuthenticationException, IOException, NoSuchMethodException { StringBuilder url = new StringBuilder(GET_TX_INTERVAL_COMMIT_TIME); url.append("?").append("fromNodeId").append("=").append(fromNodeId); url.append("&").append("toNodeId").append("=").append(toNodeId); GetRequest get = new GetRequest(url.toString()); - JSONObject json = callRepository(GET_TX_INTERVAL_COMMIT_TIME, get); + Response response = null; + JSONObject json = null; + LookAheadBufferedReader reader = null; + try + { + response = repositoryHttpClient.sendRequest(get); + if (response.getStatus() != HttpStatus.SC_OK) + { + throw new NoSuchMethodException(coreName + " - GetTxIntervalCommitTime return status is " + + response.getStatus() + " when invoking " + url); + } - return new Pair<>(Long.parseLong(json.get("minTransactionCommitTimeMs").toString()), + reader = new LookAheadBufferedReader(new InputStreamReader(response.getContentAsStream(), StandardCharsets.UTF_8), LOGGER); + json = new JSONObject(new JSONTokener(reader)); + } + catch(JSONException exception) + { + String message = "Received a malformed JSON payload. Request was \"" + + get.getFullUri() + + "Data: " + + ofNullable(reader) + .map(LookAheadBufferedReader::lookAheadAndGetBufferedContent) + .orElse("Not available"); + LOGGER.error(message); + throw exception; + } + finally + { + ofNullable(response).ifPresent(Response::release); + silentlyClose(reader); + } + + if (LOGGER.isDebugEnabled()) + { + LOGGER.debug(json.toString()); + } + + return new Pair(Long.parseLong(json.get("minTransactionCommitTimeMs").toString()), Long.parseLong(json.get("maxTransactionCommitTimeMs").toString())); }