use of com.dropbox.core.DbxRequestConfig in project dropbox-sdk-java by dropbox.
the class DbxClientV2Test method testRetryDisabled.
@Test(expectedExceptions = RetryException.class)
public void testRetryDisabled() throws DbxException, IOException {
HttpRequestor mockRequestor = mock(HttpRequestor.class);
DbxRequestConfig config = createRequestConfig().withAutoRetryDisabled().withHttpRequestor(mockRequestor).build();
DbxClientV2 client = new DbxClientV2(config, "fakeAccessToken");
// 503 every time
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 once since we disabled retry
verify(mockRequestor, times(1)).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 IOException {
// Only display important log messages.
Logger.getLogger("").setLevel(Level.WARNING);
if (args.length != 3) {
System.out.println("");
System.out.println("Usage: COMMAND <auth-file> <local-path> <dropbox-path>");
System.out.println("");
System.out.println(" <auth-file>: An \"auth file\" that contains the information necessary to make");
System.out.println(" an authorized Dropbox API request. Generate this file using the \"authorize\"");
System.out.println(" example program.");
System.out.println("");
System.out.println(" <local-path>: The path to a local file whose contents you want to upload.");
System.out.println("");
System.out.println(" <dropbox-path>: The path on Dropbox to save the file to.");
System.out.println("");
System.exit(1);
return;
}
String argAuthFile = args[0];
String localPath = args[1];
String dropboxPath = args[2];
// Read auth info file.
DbxAuthInfo authInfo;
try {
authInfo = DbxAuthInfo.Reader.readFromFile(argAuthFile);
} catch (JsonReader.FileLoadException ex) {
System.err.println("Error loading <auth-file>: " + ex.getMessage());
System.exit(1);
return;
}
String pathError = DbxPathV2.findError(dropboxPath);
if (pathError != null) {
System.err.println("Invalid <dropbox-path>: " + pathError);
System.exit(1);
return;
}
File localFile = new File(localPath);
if (!localFile.exists()) {
System.err.println("Invalid <local-path>: file does not exist.");
System.exit(1);
return;
}
if (!localFile.isFile()) {
System.err.println("Invalid <local-path>: not a file.");
System.exit(1);
return;
}
// Create a DbxClientV2, which is what you use to make API calls.
DbxRequestConfig requestConfig = new DbxRequestConfig("examples-upload-file");
DbxClientV2 dbxClient = new DbxClientV2(requestConfig, authInfo.getAccessToken(), authInfo.getHost());
// deciding factor. This should really depend on your network.
if (localFile.length() <= (2 * CHUNKED_UPLOAD_CHUNK_SIZE)) {
uploadFile(dbxClient, localFile, dropboxPath);
} else {
chunkedUploadFile(dbxClient, localFile, dropboxPath);
}
System.exit(0);
}
use of com.dropbox.core.DbxRequestConfig in project dropbox-sdk-java by dropbox.
the class Main method createClient.
private static DbxClientV2 createClient(String authFile) {
DbxAuthInfo authInfo;
try {
authInfo = DbxAuthInfo.Reader.readFromFile(authFile);
} catch (JsonReader.FileLoadException ex) {
System.err.println("Error loading <auth-file>: " + ex.getMessage());
System.exit(1);
return null;
}
DbxRequestConfig requestConfig = new DbxRequestConfig("examples-proguard");
return new DbxClientV2(requestConfig, authInfo.getAccessToken(), authInfo.getHost());
}
use of com.dropbox.core.DbxRequestConfig in project orgzly-android by orgzly.
the class DropboxClient method getDbxClient.
private DbxClientV2 getDbxClient(String accessToken) {
String userLocale = Locale.getDefault().toString();
String clientId = String.format("%s/%s", BuildConfig.APPLICATION_ID, BuildConfig.VERSION_NAME);
DbxRequestConfig requestConfig = DbxRequestConfig.newBuilder(clientId).withUserLocale(userLocale).build();
return new DbxClientV2(requestConfig, accessToken);
}
use of com.dropbox.core.DbxRequestConfig in project syndesis by syndesisio.
the class DropBoxVerifierExtension method verifyCredentials.
@SuppressWarnings("PMD.AvoidCatchingGenericException")
private void verifyCredentials(ResultBuilder builder, Map<String, Object> parameters) {
String token = (String) parameters.get("accessToken");
String clientId = (String) parameters.get("clientIdentifier");
try {
// Create Dropbox client
DbxRequestConfig config = new DbxRequestConfig(clientId, Locale.getDefault().toString());
DbxClientV2 client = new DbxClientV2(config, token);
client.users().getCurrentAccount();
client = null;
} catch (Exception e) {
builder.error(ResultErrorBuilder.withCodeAndDescription(VerificationError.StandardCode.AUTHENTICATION, "Invalid client identifier and/or access token").parameterKey("accessToken").parameterKey("clientIdentifier").build());
}
}
Aggregations