Skip to content

Commit

Permalink
Merge pull request kitodo#5908 from matthias-ronge/patch-87
Browse files Browse the repository at this point in the history
Enable debug logging from KitodoRestClient
  • Loading branch information
solth authored Feb 27, 2024
2 parents 28457e0 + 6e11ff1 commit ea08007
Showing 1 changed file with 16 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ private void initiateClientWithAuth(String host, Integer port, String protocol,
public String getServerInformation() throws IOException {
Request request = new Request(HttpMethod.GET, "/");
request.addParameter("pretty", "true");
Response response = client.performRequest(request);
Response response = performRequest(request);
return EntityUtils.toString(response.getEntity());
}

Expand All @@ -158,7 +158,7 @@ public String getServerInfo() throws IOException {
public String getMapping(String mappingType) throws IOException {
Request request = new Request(HttpMethod.GET, "/" + indexBase + "_" + mappingType + "/_mapping");
request.addParameter("pretty", "true");
Response response = client.performRequest(request);
Response response = performRequest(request);
return EntityUtils.toString(response.getEntity());
}

Expand Down Expand Up @@ -188,7 +188,7 @@ public boolean createIndex(String query, String mappingType) throws IOException,
HttpEntity entity = new NStringEntity(query, ContentType.APPLICATION_JSON);
Request request = new Request(HttpMethod.PUT, "/" + indexBase + "_" + mappingType);
request.setEntity(entity);
Response indexResponse = client.performRequest(request);
Response indexResponse = performRequest(request);
int statusCode = processStatusCode(indexResponse.getStatusLine());
return statusCode == 200 || statusCode == 201;
}
Expand All @@ -200,7 +200,7 @@ public boolean createIndex(String query, String mappingType) throws IOException,
*/
public boolean typeIndexesExist() throws IOException, CustomResponseException {
for (String mappingType : MAPPING_TYPES) {
Response indexResponse = client.performRequest(new Request(HttpMethod.GET, "/" + indexBase + "_" + mappingType));
Response indexResponse = performRequest(new Request(HttpMethod.GET, "/" + indexBase + "_" + mappingType));
int statusCode = processStatusCode(indexResponse.getStatusLine());
if (statusCode != 200 && statusCode != 201) {
return false;
Expand All @@ -214,15 +214,15 @@ public boolean typeIndexesExist() throws IOException, CustomResponseException {
* @param mappingType mapping type
*/
public void deleteIndex(String mappingType) throws IOException {
client.performRequest(new Request(HttpMethod.DELETE, "/" + indexBase + "_" + mappingType));
performRequest(new Request(HttpMethod.DELETE, "/" + indexBase + "_" + mappingType));
}

/**
* Delete all indexes. Used for cleaning after tests!
*/
public void deleteAllIndexes() throws IOException {
for (String mappingType : MAPPING_TYPES) {
client.performRequest(new Request(HttpMethod.DELETE, "/" + indexBase + "_" + mappingType));
performRequest(new Request(HttpMethod.DELETE, "/" + indexBase + "_" + mappingType));
}
}

Expand Down Expand Up @@ -287,4 +287,14 @@ private void processStatusCode(int statusCode, Object restStatus) throws CustomR
throw new CustomResponseException("Server error: " + restStatus.toString());
}
}

private Response performRequest(Request request) throws IOException {
Response response = client.performRequest(request);
if (logger.isDebugEnabled()) {
logger.debug(logger.isTraceEnabled()
? response.toString() + System.lineSeparator() + EntityUtils.toString(response.getEntity())
: response.toString());
}
return response;
}
}

0 comments on commit ea08007

Please sign in to comment.