<commit_before>package com.hpe.caf.worker.datastore.cs;

import com.hpe.caf.storage.sdk.StorageClientCallback;
import com.hpe.caf.storage.sdk.exceptions.StorageClientException;
import com.hpe.caf.storage.sdk.exceptions.StorageServiceConnectException;
import com.hpe.caf.storage.sdk.exceptions.StorageServiceException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;

public class StorageServiceClientCallback implements StorageClientCallback {

    private static final Logger LOG = LoggerFactory.getLogger(StorageServiceClientCallback.class);

    private final KeycloakClient keycloakClient;

    public StorageServiceClientCallback (final StorageServiceDataStoreConfiguration storageServiceDataStoreConfiguration) {
        keycloakClient = storageServiceDataStoreConfiguration.getAuthenticationConfiguration() != null ? new KeycloakClient(storageServiceDataStoreConfiguration.getAuthenticationConfiguration()) : null;
    }

    @Override
    public String refreshToken() throws StorageClientException, StorageServiceException, StorageServiceConnectException {

        String accessToken = null;

        //  Supply an updated access token in the event that it expires in the middle of processing an asset.
        //  The storage SDK will call this method to get the updated token and continue working on the asset in progress.
        if (keycloakClient != null) {
            try {
                LOG.debug("About to request access token.");
                accessToken = keycloakClient.getAccessToken();
            } catch (IOException e) {
                LOG.error("Failed to retrieve access token.");
                e.printStackTrace();
            }
        }

        return accessToken;
    }
}<commit_msg>CAF-972 - throw appropriate exception in the event that we fail to retrieve an updated access token<commit_after>package com.hpe.caf.worker.datastore.cs;

import com.hpe.caf.storage.sdk.StorageClientCallback;
import com.hpe.caf.storage.sdk.exceptions.StorageClientException;
import com.hpe.caf.storage.sdk.exceptions.StorageServiceConnectException;
import com.hpe.caf.storage.sdk.exceptions.StorageServiceException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;

public class StorageServiceClientCallback implements StorageClientCallback {

    private static final Logger LOG = LoggerFactory.getLogger(StorageServiceClientCallback.class);

    private final KeycloakClient keycloakClient;

    public StorageServiceClientCallback (final StorageServiceDataStoreConfiguration storageServiceDataStoreConfiguration) {
        keycloakClient = storageServiceDataStoreConfiguration.getAuthenticationConfiguration() != null ? new KeycloakClient(storageServiceDataStoreConfiguration.getAuthenticationConfiguration()) : null;
    }

    @Override
    public String refreshToken() throws StorageClientException, StorageServiceException, StorageServiceConnectException {

        String accessToken = null;

        //  Supply an updated access token in the event that it expires in the middle of processing an asset.
        //  The storage SDK will call this method to get the updated token and continue working on the asset in progress.
        if (keycloakClient != null) {
            try {
                LOG.debug("About to request access token.");
                accessToken = keycloakClient.getAccessToken();
            } catch (IOException e) {
                LOG.error("Failed to retrieve access token.");
                throw new StorageClientException("Failed to retrieve access token.", e);
            }
        }

        return accessToken;
    }
}
{'fraction_non_alphanumeric': 0.0685417804478427, 'fraction_numerical': 0.0019115237575095577, 'mean_word_length': 3.6603053435114505, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2896110', 'n_tokens_mistral': 906, 'n_tokens_neox': 865, 'n_words': 248}