How to set connection timeout in citrix sharefile java sdk?

17 views Asked by At

I am using citrix sharefile java sdk for sharefile operations. I need to control the connection timeout and I couldn't find anything about this in the project. How to set timeout?

        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);
        }
1

There are 1 answers

0
Rahogata On

I went through the source code and I able to find the solution. An extension point is given but its not documented. This is how I am setting timeouts.

{
        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);
        }
    }