Skip to content

Commit

Permalink
use status codes instead of integer value
Browse files Browse the repository at this point in the history
  • Loading branch information
wwelling committed Mar 4, 2021
1 parent 831c9bb commit de05887
Showing 1 changed file with 3 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.client.RestClientResponseException;
Expand Down Expand Up @@ -461,7 +462,7 @@ private <T> ResponseEntity<T> okapiRequest(int attempt, String url, HttpMethod m
try {
return restTemplate.exchange(url, method, requestEntity, responseType, uriVariables);
} catch(RestClientResponseException e) {
if (e.getRawStatusCode() == 401 && attempt == 1) {
if (e.getRawStatusCode() == HttpStatus.UNAUTHORIZED.value() && attempt == 1) {
requestEntity = new HttpEntity<>(requestEntity.getBody(), headers(properties.getTenant(), okapiLogin()));
return okapiRequest(++attempt, url, method, requestEntity, responseType, uriVariables);
}
Expand All @@ -481,7 +482,7 @@ private String okapiLogin() {
String url = properties.getBaseOkapiUrl() + "/authn/login";
HttpEntity<Credentials> entity = new HttpEntity<>(properties.getCredentials(), headers(properties.getTenant()));
ResponseEntity<String> response = restTemplate.exchange(url, HttpMethod.POST, entity, String.class);
if (response.getStatusCodeValue() == 201) {
if (response.getStatusCode().equals(HttpStatus.CREATED)) {
String token = response.getHeaders().getFirst(OKAPI_TOKEN_HEADER);
TokenUtility.setToken(getName(), token);
return token;
Expand Down

0 comments on commit de05887

Please sign in to comment.