本文整理匯總了Java中com.dropbox.core.DbxRequestConfig類的典型用法代碼示例。如果您正苦於以下問題:Java DbxRequestConfig類的具體用法?Java DbxRequestConfig怎麽用?Java DbxRequestConfig使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
DbxRequestConfig類屬於com.dropbox.core包,在下文中一共展示了DbxRequestConfig類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: connect
import com.dropbox.core.DbxRequestConfig; //導入依賴的package包/類
@Override
protected DbxRawClientV2 connect(final HostKeyCallback callback, final LoginCallback prompt) {
authorizationService = new OAuth2RequestInterceptor(builder.build(this, prompt).build(), host.getProtocol())
.withRedirectUri(host.getProtocol().getOAuthRedirectUrl());
final HttpClientBuilder configuration = builder.build(this, prompt);
configuration.addInterceptorLast(authorizationService);
configuration.setServiceUnavailableRetryStrategy(new OAuth2ErrorResponseInterceptor(authorizationService));
final CloseableHttpClient client = configuration.build();
return new DbxRawClientV2(DbxRequestConfig.newBuilder(useragent.get())
.withAutoRetryDisabled()
.withHttpRequestor(new DropboxCommonsHttpRequestExecutor(client)).build(), DbxHost.DEFAULT) {
@Override
protected void addAuthHeaders(final List<HttpRequestor.Header> headers) {
// OAuth Bearer added in interceptor
}
};
}
示例2: upload
import com.dropbox.core.DbxRequestConfig; //導入依賴的package包/類
public String upload(File fileToUpload) throws UploadException {
DbxRequestConfig dconfig = new DbxRequestConfig("sc-java", Locale
.getDefault().toString());
DbxClient client = new DbxClient(dconfig, config.getDropboxConfig()
.getAccessToken());
DbxEntry.File uploadedFile = null;
String shareLink = null;
try (InputStream inputStream = new FileInputStream(fileToUpload);) {
uploadedFile = client.uploadFile("/" + fileToUpload.getName(),
DbxWriteMode.add(), fileToUpload.length(), inputStream);
shareLink = client.createShareableUrl(uploadedFile.path);
} catch (DbxException | IOException e) {
throw new UploadException(e);
}
return shareLink;
}
示例3: subirArchivo
import com.dropbox.core.DbxRequestConfig; //導入依賴的package包/類
/**
* Permite subir el fichero de log a una cuenta de Dropbox
* @throws DbxException
* @throws IOException
*/
public void subirArchivo() throws DbxException, IOException{
DbxRequestConfig config = new DbxRequestConfig(
"JavaTutorial/1.0", Locale.getDefault().toString());
String accessToken = "cGF10uurG7MAAAAAAAAFGGi0UJD9H-TpMKBgESMHV5kDy5jTeF7ou8It1HY8ZFC7";
DbxClient client = new DbxClient(config, accessToken);
System.out.println("Linked account: " + client.getAccountInfo().displayName);
FileInputStream inputStream = new FileInputStream(archivoLog);
try {
DbxEntry.File uploadedFile = client.uploadFile(
"/ArchivoLog_ " + TheHouseOfCrimes.getUsuario() + "_" + TheHouseOfCrimes.getFecha(),
DbxWriteMode.add(), archivoLog.length(), inputStream);
System.out.println("Uploaded: " + uploadedFile.toString());
} finally {
inputStream.close();
}
}
示例4: get_authorization
import com.dropbox.core.DbxRequestConfig; //導入依賴的package包/類
public static DbxAuthFinish get_authorization(JDialog parent, DbxAppInfo appInfo, DbxRequestConfig config) throws DbxException {
DbxWebAuthNoRedirect webAuth = new DbxWebAuthNoRedirect(config, appInfo);
// Have the user sign in and authorize your app.
String authorizeUrl = webAuth.start();
String auth_prompt = get_auth_prompt(authorizeUrl);
JTextArea text = new JTextArea(auth_prompt);
text.setLineWrap(true);
text.setWrapStyleWord(true);
JScrollPane scrollpane = new JScrollPane(text);
scrollpane.setPreferredSize(new Dimension(200, 200));
String code = JOptionPane.showInputDialog(scrollpane);
// This will fail if the user enters an invalid authorization code.
return webAuth.finish(code);
}
示例5: testRetryDisabled
import com.dropbox.core.DbxRequestConfig; //導入依賴的package包/類
@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());
}
}
示例6: testRetryRetriesExceeded
import com.dropbox.core.DbxRequestConfig; //導入依賴的package包/類
@Test(expectedExceptions = RetryException.class)
public void testRetryRetriesExceeded() throws DbxException, IOException {
HttpRequestor mockRequestor = mock(HttpRequestor.class);
DbxRequestConfig config = createRequestConfig()
.withAutoRetryEnabled(3)
.withHttpRequestor(mockRequestor)
.build();
DbxClientV1 client = new DbxClientV1(config, "fakeAccessToken");
// 503 always and forever
when(mockRequestor.doGet(anyString(), anyHeaders()))
.thenReturn(createEmptyResponse(503));
try {
client.getAccountInfo();
} finally {
// should only have been called 4: initial call + max number of retries (3)
verify(mockRequestor, times(4)).doGet(anyString(), anyHeaders());
}
}
示例7: testRetryOtherFailure
import com.dropbox.core.DbxRequestConfig; //導入依賴的package包/類
@Test(expectedExceptions = BadRequestException.class)
public void testRetryOtherFailure() throws DbxException, IOException {
HttpRequestor mockRequestor = mock(HttpRequestor.class);
DbxRequestConfig config = createRequestConfig()
.withAutoRetryEnabled(3)
.withHttpRequestor(mockRequestor)
.build();
DbxClientV1 client = new DbxClientV1(config, "fakeAccessToken");
// 503 once, then return 400
when(mockRequestor.doGet(anyString(), anyHeaders()))
.thenReturn(createEmptyResponse(503))
.thenReturn(createEmptyResponse(400));
try {
client.getAccountInfo();
} finally {
// should only have been called 2 times: initial call + one retry
verify(mockRequestor, times(2)).doGet(anyString(), anyHeaders());
}
}
示例8: testRetryDisabled
import com.dropbox.core.DbxRequestConfig; //導入依賴的package包/類
@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());
}
}
示例9: testRetryRetriesExceeded
import com.dropbox.core.DbxRequestConfig; //導入依賴的package包/類
@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());
}
}
示例10: testRetryOtherFailure
import com.dropbox.core.DbxRequestConfig; //導入依賴的package包/類
@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());
}
}
示例11: initialize
import com.dropbox.core.DbxRequestConfig; //導入依賴的package包/類
public Bell<DbxSession> initialize() {
// If an OAuth token is provided, use it.
if (credential instanceof StorkOAuthCred) {
StorkOAuthCred oauth = (StorkOAuthCred) credential;
DbxRequestConfig config =
DbxRequestConfig.newBuilder("StorkCloud").build();
client = new DbxClientV2(config, oauth.data());
return Bell.wrap(this);
}
throw new AuthenticationRequired("oauth");
}
示例12: getDbxClient
import com.dropbox.core.DbxRequestConfig; //導入依賴的package包/類
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);
}
示例13: readFile
import com.dropbox.core.DbxRequestConfig; //導入依賴的package包/類
@Override
public ResponseEntity<StreamingResponseBody> readFile(String fileLocation, String imageDir, String id,
String fileName) {
StreamingResponseBody streamingResponseBody = new StreamingResponseBody() {
@Override
public void writeTo(OutputStream outputStream) {
try {
String fileStr = SEPARATOR + imageDir + SEPARATOR + id + SEPARATOR + fileName;
DbxRequestConfig config = new DbxRequestConfig(APP_IDENTIFIER);
DbxClientV2 client = new DbxClientV2(config, ACCESS_TOKEN);
client.files().download(fileStr).download(outputStream);
} catch (Exception e) {
logger.error(e.getMessage());
throw new ResourceNotFoundException("Image Not Found : " + id + "/" + fileName);
}
}
};
HttpHeaders headers = new HttpHeaders();
headers.add(HttpHeaders.CONTENT_TYPE, "image/*");
return new ResponseEntity<StreamingResponseBody>(streamingResponseBody, headers, HttpStatus.OK);
}
示例14: getClient
import com.dropbox.core.DbxRequestConfig; //導入依賴的package包/類
/**
*
* get connection client
*/
@Override
public DbxClientV2 getClient(){
DbxRequestConfig config = DbxRequestConfig.newBuilder(appId).withAutoRetryEnabled(3).withUserLocaleFrom(Locale.ITALY).build();
return new DbxClientV2(config, accessToken);
}
示例15: dropboxGetFiles
import com.dropbox.core.DbxRequestConfig; //導入依賴的package包/類
public static List<String> dropboxGetFiles(String code) {
DbxRequestConfig config = new DbxRequestConfig("Media Information Service Configuration");
DbxClientV2 client = new DbxClientV2(config, code);
ListFolderResult result = null;
List<String> elements = new LinkedList<String>();
try {
result = client.files().listFolderBuilder("/media").withRecursive(true).start();
while (true) {
for (Metadata metadata : result.getEntries()) {
if (metadata instanceof FileMetadata) {
elements.add(metadata.getName());
}
}
if (!result.getHasMore()) {
break;
}
result = client.files().listFolderContinue(result.getCursor());
}
//System.out.println(elements.toString());
} catch (DbxException e) {
e.printStackTrace();
}
return elements;
}