use of com.dropbox.core.DbxRequestConfig in project dropbox-sdk-java by dropbox.
the class DbxClientV2Test method testRetryOtherFailure.
@Test(expectedExceptions = BadRequestException.class)
public void testRetryOtherFailure() throws DbxException, IOException {
HttpRequestor mockRequestor = mock(HttpRequestor.class);
DbxRequestConfig config = createRequestConfig().withAutoRetryEnabled(3).withHttpRequestor(mockRequestor).build();
DbxClientV2 client = new DbxClientV2(config, "fakeAccessToken");
// 503 once, then return 400
HttpRequestor.Uploader mockUploader = mockUploader();
when(mockUploader.finish()).thenReturn(createEmptyResponse(503)).thenReturn(createEmptyResponse(400));
when(mockRequestor.startPost(anyString(), anyHeaders())).thenReturn(mockUploader);
try {
client.users().getCurrentAccount();
} finally {
// should only have been called 2 times: initial call + retry
verify(mockRequestor, times(2)).startPost(anyString(), anyHeaders());
}
}
use of com.dropbox.core.DbxRequestConfig in project dropbox-sdk-java by dropbox.
the class DbxClientV1Test method testRetryDisabled.
@Test(expectedExceptions = RetryException.class)
public void testRetryDisabled() throws DbxException, IOException {
HttpRequestor mockRequestor = mock(HttpRequestor.class);
DbxRequestConfig config = createRequestConfig().withAutoRetryDisabled().withHttpRequestor(mockRequestor).build();
DbxClientV1 client = new DbxClientV1(config, "fakeAccessToken");
// 503 every time
when(mockRequestor.doGet(anyString(), anyHeaders())).thenReturn(createEmptyResponse(503));
try {
client.getAccountInfo();
} finally {
// should only have been called once since we disabled retry
verify(mockRequestor, times(1)).doGet(anyString(), anyHeaders());
}
}
use of com.dropbox.core.DbxRequestConfig in project dropbox-sdk-java by dropbox.
the class DbxClientV2Test method testRetryRetriesExceeded.
@Test(expectedExceptions = RetryException.class)
public void testRetryRetriesExceeded() throws DbxException, IOException {
HttpRequestor mockRequestor = mock(HttpRequestor.class);
DbxRequestConfig config = createRequestConfig().withAutoRetryEnabled(3).withHttpRequestor(mockRequestor).build();
DbxClientV2 client = new DbxClientV2(config, "fakeAccessToken");
// 503 always and forever
HttpRequestor.Uploader mockUploader = mockUploader();
when(mockUploader.finish()).thenReturn(createEmptyResponse(503));
when(mockRequestor.startPost(anyString(), anyHeaders())).thenReturn(mockUploader);
try {
client.users().getCurrentAccount();
} finally {
// should only have been called 4 times: initial call plus our maximum retry limit
verify(mockRequestor, times(1 + 3)).startPost(anyString(), anyHeaders());
}
}
use of com.dropbox.core.DbxRequestConfig in project dropbox-sdk-java by dropbox.
the class Main method main.
public static void main(String[] args) throws DbxException, IOException {
// Create Dropbox client
DbxRequestConfig config = new DbxRequestConfig("dropbox/java-tutorial");
DbxClientV2 client = new DbxClientV2(config, ACCESS_TOKEN);
// Instantiate factory and set shared factory
DbxRequestUtil.sharedCallbackFactory = new DbxExampleGlobalCallbackFactory();
try {
// Get files and folder metadata from Dropbox root directory
client.files().listFolder("/does/not/exist/folder/");
} catch (ListFolderErrorException ex) {
System.err.println("STANDARD ROUTE ERROR HANDLER: " + ex.errorValue + "\n");
} catch (DbxException ex) {
System.err.println("STANDARD NETWORK ERROR HANDLER: " + ex + "\n");
}
try {
// Get files and folder metadata from Dropbox root directory
client.auth().tokenRevoke();
client.files().listFolder("/does/not/exist");
} catch (ListFolderErrorException ex) {
System.err.println("STANDARD ROUTE ERROR HANDLER2: " + ex.errorValue + "\n");
} catch (DbxException ex) {
System.err.println("STANDARD NETWORK ERROR HANDLER2: " + ex + "\n");
}
}
use of com.dropbox.core.DbxRequestConfig in project dropbox-sdk-java by dropbox.
the class Main method main.
public static void main(String[] args) throws IOException {
// Only display important log messages.
Logger.getLogger("").setLevel(Level.INFO);
Config cfg = parseArgs(args);
if (cfg == null) {
System.exit(1);
return;
}
// Read app info file (contains app key and app secret)
DbxAppInfo appInfo;
try {
appInfo = DbxAppInfo.Reader.readFromFile(cfg.appInfoFile);
} catch (JsonReader.FileLoadException ex) {
System.err.println("Error reading <app-info-file>: " + ex.getMessage());
System.exit(1);
return;
}
DbxOAuth1AccessToken oauth1AccessToken = new DbxOAuth1AccessToken(cfg.accessTokenKey, cfg.accessTokenSecret);
// Get an OAuth 2 access token.
DbxRequestConfig requestConfig = new DbxRequestConfig("examples-authorize");
DbxOAuth1Upgrader upgrader = new DbxOAuth1Upgrader(requestConfig, appInfo);
String oauth2AccessToken;
try {
oauth2AccessToken = upgrader.createOAuth2AccessToken(oauth1AccessToken);
} catch (DbxException ex) {
System.err.println("Error getting OAuth 2 access token: " + ex.getMessage());
System.exit(1);
return;
}
System.out.println("OAuth 2 access token obtained.");
DbxAuthInfo authInfo = new DbxAuthInfo(oauth2AccessToken, appInfo.getHost());
DbxAuthInfo.Writer.writeToStream(authInfo, System.out);
System.out.println();
// Disable the OAuth 1 access token.
if (cfg.disable) {
try {
upgrader.disableOAuth1AccessToken(oauth1AccessToken);
} catch (DbxException ex) {
System.err.println("Error disabling OAuth 1 access token: " + ex.getMessage());
System.exit(1);
return;
}
System.out.println("OAuth 1 access token disabled.");
}
}
Aggregations