Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/332.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在box java sdk中将代理添加到BoxApiConnection?_Java_Proxy_Sdk_Box - Fatal编程技术网

如何在box java sdk中将代理添加到BoxApiConnection?

如何在box java sdk中将代理添加到BoxApiConnection?,java,proxy,sdk,box,Java,Proxy,Sdk,Box,我需要在boxapiconnection中设置代理。但无法获得任何可使用的参考代码。有人能给我解决方案吗?BoxAPIConnection api=new-BoxAPIConnection(代码) 我对没有代理的BoxDeveloperEditionAPIConnection也有同样的问题。我创建了以下代码,以解决在到期后自动刷新令牌的问题: import com.box.sdk.BoxConfig; import com.box.sdk.BoxDeveloperEditionAPIConnec

我需要在boxapiconnection中设置代理。但无法获得任何可使用的参考代码。有人能给我解决方案吗?

BoxAPIConnection api=new-BoxAPIConnection(代码)


我对没有代理的BoxDeveloperEditionAPIConnection也有同样的问题。我创建了以下代码,以解决在到期后自动刷新令牌的问题:

import com.box.sdk.BoxConfig;
import com.box.sdk.BoxDeveloperEditionAPIConnection;
import com.box.sdk.DeveloperEditionEntityType;
import com.box.sdk.IAccessTokenCache;
import com.eclipsesource.json.JsonObject;

import java.net.Proxy;

public class MyBoxAPIConnection extends BoxDeveloperEditionAPIConnection {

private IAccessTokenCache accessTokenCache;
private String entityID;
private DeveloperEditionEntityType entityType;

public MyBoxAPIConnection(BoxConfig boxConfig, IAccessTokenCache accessTokenCache, Proxy proxy) {
    this(boxConfig.getEnterpriseId(), DeveloperEditionEntityType.ENTERPRISE, boxConfig, accessTokenCache);
    this.setProxy(proxy);
    this.tryRestoreUsingAccessTokenCache();
}

public MyBoxAPIConnection(String entityId, DeveloperEditionEntityType entityType, BoxConfig boxConfig,
        IAccessTokenCache accessTokenCache) {
    super(entityId, entityType, boxConfig, accessTokenCache);
}

private void tryRestoreUsingAccessTokenCache() {
    if (this.accessTokenCache == null) {
        // no cache specified so force authentication
        this.authenticate();
    } else {
        String cachedTokenInfo = this.accessTokenCache.get(this.getAccessTokenCacheKey());
        if (cachedTokenInfo == null) {
            // not found; probably first time for this client config so authenticate; info will then be cached
            this.authenticate();
        } else {
            // pull access token cache info; authentication will occur as needed (if token is expired)
            JsonObject json = JsonObject.readFrom(cachedTokenInfo);
            this.setAccessToken(json.get("accessToken").asString());
            this.setLastRefresh(json.get("lastRefresh").asLong());
            this.setExpires(json.get("expires").asLong());
        }
    }
}

private String getAccessTokenCacheKey() {
    return String.format("/%s/%s/%s/%s", this.getUserAgent(), this.getClientID(), this.entityType.toString(),
            this.entityID);
}

}
import com.box.sdk.BoxConfig;
import com.box.sdk.BoxDeveloperEditionAPIConnection;
import com.box.sdk.DeveloperEditionEntityType;
import com.box.sdk.IAccessTokenCache;
import com.eclipsesource.json.JsonObject;

import java.net.Proxy;

public class MyBoxAPIConnection extends BoxDeveloperEditionAPIConnection {

private IAccessTokenCache accessTokenCache;
private String entityID;
private DeveloperEditionEntityType entityType;

public MyBoxAPIConnection(BoxConfig boxConfig, IAccessTokenCache accessTokenCache, Proxy proxy) {
    this(boxConfig.getEnterpriseId(), DeveloperEditionEntityType.ENTERPRISE, boxConfig, accessTokenCache);
    this.setProxy(proxy);
    this.tryRestoreUsingAccessTokenCache();
}

public MyBoxAPIConnection(String entityId, DeveloperEditionEntityType entityType, BoxConfig boxConfig,
        IAccessTokenCache accessTokenCache) {
    super(entityId, entityType, boxConfig, accessTokenCache);
}

private void tryRestoreUsingAccessTokenCache() {
    if (this.accessTokenCache == null) {
        // no cache specified so force authentication
        this.authenticate();
    } else {
        String cachedTokenInfo = this.accessTokenCache.get(this.getAccessTokenCacheKey());
        if (cachedTokenInfo == null) {
            // not found; probably first time for this client config so authenticate; info will then be cached
            this.authenticate();
        } else {
            // pull access token cache info; authentication will occur as needed (if token is expired)
            JsonObject json = JsonObject.readFrom(cachedTokenInfo);
            this.setAccessToken(json.get("accessToken").asString());
            this.setLastRefresh(json.get("lastRefresh").asLong());
            this.setExpires(json.get("expires").asLong());
        }
    }
}

private String getAccessTokenCacheKey() {
    return String.format("/%s/%s/%s/%s", this.getUserAgent(), this.getClientID(), this.entityType.toString(),
            this.entityID);
}

}