我使用 citrix sharefile java sdk 进行共享文件操作。我需要控制连接超时,但我在project中找不到任何与此相关的信息。如何设置超时?
try {
String token = """
{
"access_token" : "token",
"refresh_token" : "refresh token",
"token_type" : "Bearer",
"appcp" : "App cp",
"apicp" : "Api cp",
"subdomain" : "sf222",
"expires_in" : 3394757484
}
""";
ISFApiClient client = new SFApiClient(new SFOAuth2Token(token));
SFItem folder = client.items().get().execute();
} catch (SFInvalidStateException | SFJsonException | SFServerException | SFNotAuthorizedException |
SFOAuthTokenRenewException | SFOtherException e) {
fail(e);
}
我浏览了源代码,找到了解决方案。给出了扩展点,但没有记录。这就是我设置超时的方式。
{
try {
SFSdk.setConnectionMgr(new ISFConnectionManager() {
@Override
public void onBeforeConnect(URLConnection connection) {
connection.setConnectTimeout(30000);
connection.setReadTimeout(30000);
}
@Override
public void onConnectException(URLConnection connection, IOException e) {
}
@Override
public InputStream getInputStream(URLConnection conn) throws IOException {
return conn.getInputStream();
}
});
String token = """
{
"access_token" : "token",
"refresh_token" : "refresh token",
"token_type" : "Bearer",
"appcp" : "App cp",
"apicp" : "Api cp",
"subdomain" : "sf222",
"expires_in" : 3394757484
}
""";
ISFApiClient client = new SFApiClient(new SFOAuth2Token(token));
SFItem folder = client.items().get().execute();
} catch (SFInvalidStateException | SFJsonException | SFServerException | SFNotAuthorizedException |
SFOAuthTokenRenewException | SFOtherException e) {
fail(e);
}
}