<commit_before>package com.feedeo.bingadsapi.impl;

import com.feedeo.bingadsapi.session.BingAdsSession;
import com.google.api.client.auth.oauth2.Credential;
import org.apache.axis.client.Stub;
import org.apache.log4j.Logger;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

/**
 * User: maglju
 * Date: 2013-11-13
 * Time: 09:50
 */
public class CredentialRefreshInvocationHandler<T extends java.rmi.Remote> implements InvocationHandler {
    private static final Logger log = Logger.getLogger(CredentialRefreshInvocationHandler.class);

    private BingAdsSession session;
    private T service;
    private StubHeaderSetterService stubHeaderSetterService;
    private String apiNamespace;

    public CredentialRefreshInvocationHandler(BingAdsSession session, T service, StubHeaderSetterService stubHeaderSetterService, String apiNamespace) {
        this.session = session;
        this.service = service;
        this.stubHeaderSetterService = stubHeaderSetterService;
        this.apiNamespace = apiNamespace;
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        if(isCredentialRefreshable(session.getOAuth2Credential(), session.getRefreshWindowSeconds())) {
            log.debug("Refreshing token for BingAds session for account id " + session.getAccountId() + " and customer id " + session.getCustomerId());
            log.debug("Current token: " + session.getOAuth2Credential().getAccessToken());
            session.getOAuth2Credential().refreshToken();
            stubHeaderSetterService.updateAuthenticationToken((Stub) service, session, apiNamespace);
            log.debug("Refreshed token: " + session.getOAuth2Credential().getAccessToken());
        }

        if (service instanceof Stub) {
            Stub stub = (Stub) service;
            log.debug("Invoking service with authentication header: " + stub.getHeader(apiNamespace, "AuthenticationToken"));
        }
        return method.invoke(service, args);
    }

    private boolean isCredentialRefreshable(Credential credential, long refreshWindowSeconds) {
        return credential.getAccessToken() == null ||
               (credential.getExpiresInSeconds() != null && credential.getExpiresInSeconds() <= refreshWindowSeconds);
    }
}<commit_msg>Removed extraneous logging<commit_after>package com.feedeo.bingadsapi.impl;

import com.feedeo.bingadsapi.session.BingAdsSession;
import com.google.api.client.auth.oauth2.Credential;
import org.apache.axis.client.Stub;
import org.apache.log4j.Logger;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

/**
 * User: maglju
 * Date: 2013-11-13
 * Time: 09:50
 */
public class CredentialRefreshInvocationHandler<T extends java.rmi.Remote> implements InvocationHandler {
    private static final Logger log = Logger.getLogger(CredentialRefreshInvocationHandler.class);

    private BingAdsSession session;
    private T service;
    private StubHeaderSetterService stubHeaderSetterService;
    private String apiNamespace;

    public CredentialRefreshInvocationHandler(BingAdsSession session, T service, StubHeaderSetterService stubHeaderSetterService, String apiNamespace) {
        this.session = session;
        this.service = service;
        this.stubHeaderSetterService = stubHeaderSetterService;
        this.apiNamespace = apiNamespace;
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        if(isCredentialRefreshable(session.getOAuth2Credential(), session.getRefreshWindowSeconds())) {
            log.debug("Refreshing token for BingAds session for account id " + session.getAccountId() + " and customer id " + session.getCustomerId());
            session.getOAuth2Credential().refreshToken();
            stubHeaderSetterService.updateAuthenticationToken((Stub) service, session, apiNamespace);
        }

        return method.invoke(service, args);
    }

    private boolean isCredentialRefreshable(Credential credential, long refreshWindowSeconds) {
        return credential.getAccessToken() == null ||
               (credential.getExpiresInSeconds() != null && credential.getExpiresInSeconds() <= refreshWindowSeconds);
    }
}
{'fraction_non_alphanumeric': 0.09210526315789473, 'fraction_numerical': 0.007988721804511278, 'mean_word_length': 4.110444177671068, 'pattern_counts': {'":': 0, '<': 7, '<?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': '7490913', 'n_tokens_mistral': 1164, 'n_tokens_neox': 1121, 'n_words': 241}