<commit_before>package <%=packageName%>.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.loadbalancer.LoadBalancerClient;
import org.springframework.security.oauth2.client.token.grant.client.ClientCredentialsResourceDetails;
import org.springframework.stereotype.Component;

import java.net.URI;
import java.net.URISyntaxException;


@Component
public class LoadBalancedResourceDetails extends ClientCredentialsResourceDetails {

    @Autowired
    public LoadBalancedResourceDetails(JHipsterProperties jHipsterProperties) {
        this.jHipsterProperties = jHipsterProperties;

        setAccessTokenUri(jHipsterProperties.getSecurity().getClientAuthorization().getTokenUrl());
        setClientId(jHipsterProperties.getSecurity().getClientAuthorization().getClientId());
        setClientSecret(jHipsterProperties.getSecurity().getClientAuthorization().getClientSecret());
        setGrantType("client_credentials");

    }

    private LoadBalancerClient loadBalancerClient;

    private JHipsterProperties jHipsterProperties;


    @Autowired(required = false)
    public void setLoadBalancerClient(LoadBalancerClient loadBalancerClient) {
        this.loadBalancerClient = loadBalancerClient;
    }

    @Override
    public String getAccessTokenUri() {
        String serviceName = jHipsterProperties.getSecurity().getClientAuthorization().getTokenServiceId();
        if (loadBalancerClient != null && !serviceName.isEmpty()) {
            String newUrl;
            try {
                newUrl = loadBalancerClient.reconstructURI(
                    loadBalancerClient.choose(serviceName),
                    new URI(super.getAccessTokenUri())
                ).toString();

                return newUrl;
            } catch (URISyntaxException e) {
                e.printStackTrace();

                return super.getAccessTokenUri();
            }
        } else {
            return super.getAccessTokenUri();
        }
    }<commit_msg>adds logger instead of printing stacktrace<commit_after>package <%=packageName%>.config;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.loadbalancer.LoadBalancerClient;
import org.springframework.security.oauth2.client.token.grant.client.ClientCredentialsResourceDetails;
import org.springframework.stereotype.Component;

import java.net.URI;
import java.net.URISyntaxException;


@Component
public class LoadBalancedResourceDetails extends ClientCredentialsResourceDetails {
    
    Logger log = LoggerFactory.getLogger(this.getClass());

    @Autowired
    public LoadBalancedResourceDetails(JHipsterProperties jHipsterProperties) {
        this.jHipsterProperties = jHipsterProperties;

        setAccessTokenUri(jHipsterProperties.getSecurity().getClientAuthorization().getTokenUrl());
        setClientId(jHipsterProperties.getSecurity().getClientAuthorization().getClientId());
        setClientSecret(jHipsterProperties.getSecurity().getClientAuthorization().getClientSecret());
        setGrantType("client_credentials");

    }

    private LoadBalancerClient loadBalancerClient;

    private JHipsterProperties jHipsterProperties;


    @Autowired(required = false)
    public void setLoadBalancerClient(LoadBalancerClient loadBalancerClient) {
        this.loadBalancerClient = loadBalancerClient;
    }

    @Override
    public String getAccessTokenUri() {
        String serviceName = jHipsterProperties.getSecurity().getClientAuthorization().getTokenServiceId();
        if (loadBalancerClient != null && !serviceName.isEmpty()) {
            String newUrl;
            try {
                newUrl = loadBalancerClient.reconstructURI(
                    loadBalancerClient.choose(serviceName),
                    new URI(super.getAccessTokenUri())
                ).toString();

                return newUrl;
            } catch (URISyntaxException e) {
                log.error("{}: {}", e.getClass().toString(), e.getMessage());

                return super.getAccessTokenUri();
            }
        } else {
            return super.getAccessTokenUri();
        }
    }
{'fraction_non_alphanumeric': 0.08895197539626212, 'fraction_numerical': 0.0009462976105985332, 'mean_word_length': 3.408759124087591, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '4234880', 'n_tokens_mistral': 1089, 'n_tokens_neox': 1069, 'n_words': 164}