Search in sources :

Example 1 with LookupError

use of com.dropbox.core.v2.files.LookupError in project dropbox-sdk-java by dropbox.

the class DropboxBrowse method doBrowse.

// -------------------------------------------------------------------------------------------
// GET /browse?path=...
// -------------------------------------------------------------------------------------------
// The page that lets you browse your Dropbox account.  Makes Dropbox API calls to figure out
// the contents of your files and folders and display them to you.
public void doBrowse(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
    if (!common.checkGet(request, response))
        return;
    User user = common.getLoggedInUser(request);
    if (user == null) {
        common.pageSoftError(response, "Can't do /browse.  Nobody is logged in.");
        return;
    }
    DbxClientV2 dbxClient = requireDbxClient(request, response, user);
    if (dbxClient == null)
        return;
    String path = request.getParameter("path");
    if (path == null || path.length() == 0) {
        renderFolder(response, user, dbxClient, "");
    } else {
        String pathError = DbxPathV2.findError(path);
        if (pathError != null) {
            response.sendError(400, "Invalid path: " + jq(path) + ": " + pathError);
            return;
        }
        Metadata metadata;
        try {
            metadata = dbxClient.files().getMetadata(path);
        } catch (GetMetadataErrorException ex) {
            if (ex.errorValue.isPath()) {
                LookupError le = ex.errorValue.getPathValue();
                if (le.isNotFound()) {
                    response.sendError(400, "Path doesn't exist on Dropbox: " + jq(path));
                    return;
                }
            }
            common.handleException(response, ex, "getMetadata(" + jq(path) + ")");
            return;
        } catch (DbxException ex) {
            common.handleDbxException(response, user, ex, "getMetadata(" + jq(path) + ")");
            return;
        }
        path = DbxPathV2.getParent(path) + "/" + metadata.getName();
        if (metadata instanceof FolderMetadata) {
            renderFolder(response, user, dbxClient, path);
        } else {
            renderFile(response, path, (FileMetadata) metadata);
        }
    }
}
Also used : DbxClientV2(com.dropbox.core.v2.DbxClientV2) FolderMetadata(com.dropbox.core.v2.files.FolderMetadata) DeletedMetadata(com.dropbox.core.v2.files.DeletedMetadata) FileMetadata(com.dropbox.core.v2.files.FileMetadata) Metadata(com.dropbox.core.v2.files.Metadata) FolderMetadata(com.dropbox.core.v2.files.FolderMetadata) LookupError(com.dropbox.core.v2.files.LookupError) DbxException(com.dropbox.core.DbxException) GetMetadataErrorException(com.dropbox.core.v2.files.GetMetadataErrorException)

Example 2 with LookupError

use of com.dropbox.core.v2.files.LookupError in project dropbox-sdk-java by dropbox.

the class DbxClientV2IT method testError409.

@Test(expectedExceptions = { GetMetadataErrorException.class })
public void testError409() throws Exception {
    DbxClientV2 client = ITUtil.newClientV2();
    String path = ITUtil.path(getClass(), "/testError409/" + ITUtil.format(new Date()));
    try {
        client.files().getMetadata(path);
    } catch (GetMetadataErrorException ex) {
        assertThat(ex.getRequestId()).isNotNull();
        if (ex.getUserMessage() != null) {
            assertThat(ex.getUserMessage().getLocale()).isNotNull();
            assertThat(ex.getUserMessage().getText()).isNotNull();
            assertThat(ex.getUserMessage().toString()).isNotNull();
        }
        GetMetadataError err = ex.errorValue;
        assertThat(err).isNotNull();
        assertThat(err.tag()).isEqualTo(GetMetadataError.Tag.PATH);
        assertThat(err.isPath()).isTrue();
        LookupError lookup = err.getPathValue();
        assertThat(lookup).isNotNull();
        assertThat(lookup.tag()).isEqualTo(LookupError.Tag.NOT_FOUND);
        assertThat(lookup.isNotFound()).isTrue();
        assertThat(lookup.isNotFile()).isFalse();
        assertThat(lookup.isOther()).isFalse();
        assertThat(lookup.isMalformedPath()).isFalse();
        // raise so test can confirm an exception was thrown
        throw ex;
    }
}
Also used : GetMetadataError(com.dropbox.core.v2.files.GetMetadataError) Date(java.util.Date) LookupError(com.dropbox.core.v2.files.LookupError) GetMetadataErrorException(com.dropbox.core.v2.files.GetMetadataErrorException) Test(org.testng.annotations.Test)

Aggregations

GetMetadataErrorException (com.dropbox.core.v2.files.GetMetadataErrorException)2 LookupError (com.dropbox.core.v2.files.LookupError)2 DbxException (com.dropbox.core.DbxException)1 DbxClientV2 (com.dropbox.core.v2.DbxClientV2)1 DeletedMetadata (com.dropbox.core.v2.files.DeletedMetadata)1 FileMetadata (com.dropbox.core.v2.files.FileMetadata)1 FolderMetadata (com.dropbox.core.v2.files.FolderMetadata)1 GetMetadataError (com.dropbox.core.v2.files.GetMetadataError)1 Metadata (com.dropbox.core.v2.files.Metadata)1 Date (java.util.Date)1 Test (org.testng.annotations.Test)1