@Test public void retrieveTokenKeys_usesGivenURI() throws OAuth2ServiceException { mockResponse(); cut.retrieveTokenKeys(TOKEN_KEYS_ENDPOINT_URI); Mockito.verify(restOperationsMock, times(1)) .getForEntity(TOKEN_KEYS_ENDPOINT_URI, String.class); }
@Override public String retrieveTokenKeys(URI tokenKeysEndpointUri) throws OAuth2ServiceException { Assertions.assertNotNull(tokenKeysEndpointUri, "Token key endpoint must not be null!"); try { ResponseEntity<String> response = restOperations.getForEntity(tokenKeysEndpointUri, String.class); if (HttpStatus.OK.value() == response.getStatusCode().value()) { return response.getBody(); } else { throw OAuth2ServiceException.builder("Error retrieving token keys") .withUri(tokenKeysEndpointUri) .withStatusCode(response.getStatusCodeValue()) .withResponseBody(response.getBody()) .build(); } } catch (HttpClientErrorException ex) { throw OAuth2ServiceException.builder("Error retrieving token keys") .withUri(tokenKeysEndpointUri) .withStatusCode(ex.getStatusCode().value()) .withResponseBody(ex.getResponseBodyAsString()) .build(); } catch (Exception e) { throw OAuth2ServiceException.builder("Unexpected error retrieving token keys: " + e.getMessage()) .withUri(tokenKeysEndpointUri) .build(); } }
SpringOAuth2TokenKeyService implements OAuth2TokenKeyService { @Override public String retrieveTokenKeys(URI tokenKeysEndpointUri) throws OAuth2ServiceException { Assertions.assertNotNull(tokenKeysEndpointUri, "Token key endpoint must not be null!"); try { ResponseEntity<String> response = restOperations.getForEntity(tokenKeysEndpointUri, String.class); if (HttpStatus.OK.value() == response.getStatusCode().value()) { return response.getBody(); } else { throw OAuth2ServiceException.builder("Error retrieving token keys") .withUri(tokenKeysEndpointUri) .withStatusCode(response.getStatusCodeValue()) .withResponseBody(response.getBody()) .build(); } } catch (HttpClientErrorException ex) { throw OAuth2ServiceException.builder("Error retrieving token keys") .withUri(tokenKeysEndpointUri) .withStatusCode(ex.getStatusCode().value()) .withResponseBody(ex.getResponseBodyAsString()) .build(); } catch (Exception e) { throw OAuth2ServiceException.builder("Unexpected error retrieving token keys: " + e.getMessage()) .withUri(tokenKeysEndpointUri) .build(); } } }
SpringOAuth2TokenKeyService implements OAuth2TokenKeyService { @Override public String retrieveTokenKeys(URI tokenKeysEndpointUri) throws OAuth2ServiceException { Assertions.assertNotNull(tokenKeysEndpointUri, "Token key endpoint must not be null!"); try { ResponseEntity<String> response = restOperations.getForEntity(tokenKeysEndpointUri, String.class); if (HttpStatus.OK.value() == response.getStatusCode().value()) { return response.getBody(); } else { throw OAuth2ServiceException.builder("Error retrieving token keys") .withUri(tokenKeysEndpointUri) .withStatusCode(response.getStatusCodeValue()) .withResponseBody(response.getBody()) .build(); } } catch (HttpClientErrorException ex) { throw OAuth2ServiceException.builder("Error retrieving token keys") .withUri(tokenKeysEndpointUri) .withStatusCode(ex.getStatusCode().value()) .withResponseBody(ex.getResponseBodyAsString()) .build(); } catch (Exception e) { throw OAuth2ServiceException.builder("Unexpected error retrieving token keys: " + e.getMessage()) .withUri(tokenKeysEndpointUri) .build(); } } SpringOAuth2TokenKeyService(@Nonnull RestOperations restOperations); }
SpringOAuth2TokenKeyService implements OAuth2TokenKeyService { @Override public String retrieveTokenKeys(URI tokenKeysEndpointUri) throws OAuth2ServiceException { Assertions.assertNotNull(tokenKeysEndpointUri, "Token key endpoint must not be null!"); try { ResponseEntity<String> response = restOperations.getForEntity(tokenKeysEndpointUri, String.class); if (HttpStatus.OK.value() == response.getStatusCode().value()) { return response.getBody(); } else { throw OAuth2ServiceException.builder("Error retrieving token keys") .withUri(tokenKeysEndpointUri) .withStatusCode(response.getStatusCodeValue()) .withResponseBody(response.getBody()) .build(); } } catch (HttpClientErrorException ex) { throw OAuth2ServiceException.builder("Error retrieving token keys") .withUri(tokenKeysEndpointUri) .withStatusCode(ex.getStatusCode().value()) .withResponseBody(ex.getResponseBodyAsString()) .build(); } catch (Exception e) { throw OAuth2ServiceException.builder("Unexpected error retrieving token keys: " + e.getMessage()) .withUri(tokenKeysEndpointUri) .build(); } } SpringOAuth2TokenKeyService(@Nonnull RestOperations restOperations); @Override String retrieveTokenKeys(URI tokenKeysEndpointUri); }
SpringOAuth2TokenKeyService implements OAuth2TokenKeyService { @Override public String retrieveTokenKeys(URI tokenKeysEndpointUri) throws OAuth2ServiceException { Assertions.assertNotNull(tokenKeysEndpointUri, "Token key endpoint must not be null!"); try { ResponseEntity<String> response = restOperations.getForEntity(tokenKeysEndpointUri, String.class); if (HttpStatus.OK.value() == response.getStatusCode().value()) { return response.getBody(); } else { throw OAuth2ServiceException.builder("Error retrieving token keys") .withUri(tokenKeysEndpointUri) .withStatusCode(response.getStatusCodeValue()) .withResponseBody(response.getBody()) .build(); } } catch (HttpClientErrorException ex) { throw OAuth2ServiceException.builder("Error retrieving token keys") .withUri(tokenKeysEndpointUri) .withStatusCode(ex.getStatusCode().value()) .withResponseBody(ex.getResponseBodyAsString()) .build(); } catch (Exception e) { throw OAuth2ServiceException.builder("Unexpected error retrieving token keys: " + e.getMessage()) .withUri(tokenKeysEndpointUri) .build(); } } SpringOAuth2TokenKeyService(@Nonnull RestOperations restOperations); @Override String retrieveTokenKeys(URI tokenKeysEndpointUri);  }