private <T> T exchangeRest(RestMethodName methodName, Object request, Class<T> responseType)
throws LivingDocServerException {
RequestEntity<Object> requestEntity;
RequestEntity.BodyBuilder bodyBuilder = RequestEntity.post(getUri());
bodyBuilder.contentType(MediaType.APPLICATION_JSON)
.header("method-name", methodName.name());
if (!isAnonymousAccess()) {
try {
bodyBuilder.header("Authorization", "Basic " + ClientUtils.encodeToBase64(":", username, password));
} catch (UnsupportedEncodingException uee) {
throw new LivingDocServerException(LivingDocServerErrorKey.CALL_FAILED, uee.getMessage(), uee);
}
}
requestEntity = bodyBuilder.body(request);
ResponseEntity<T> responseEntity = template.exchange(requestEntity, responseType);
HttpStatus statusCode = responseEntity.getStatusCode();
if (!HttpStatus.OK.equals(statusCode)) {
throw new LivingDocServerException(LivingDocServerErrorKey.CALL_FAILED,
"call was not successful, status: " + statusCode);
}
return responseEntity.getBody();
}