public void renewToken() {
CreateTokenRequest createTokenRequest = new CreateTokenRequest();
createTokenRequest.setUser(credentials.getUserName());
createTokenRequest.setPassword(credentials.getPassword());
CreateTokenResponse createTokenResponse;
try {
createTokenResponse = send(createTokenRequest);
} catch (ValidationConstraintViolationException vcve) {
throw new AuthorizationException(vcve);
}
HttpStatus status = HttpStatus.getStatus(createTokenResponse.getStatusCode());
if (status.isError()) {
if (status.equals(HttpStatus.Unauthorized)) {
throw new AuthorizationException(HttpStatus.Unauthorized.toString());
} else {
throw new CommunicationErrorException(status);
}
}
String newToken = createTokenResponse.getToken();
tokenStore.setToken(newToken);
}