0

I have created a java cucumber maven project. Now I want to push all report in dropbox once execution of test script is done.

My main goal is to push report folder on Dropbox.

I am using below maven dependency:

<dependency>
    <groupId>com.dropbox.core</groupId>
    <artifactId>dropbox-core-sdk</artifactId>
    <version>1.7.2</version>
</dependency>

I know it's old dependency but code provided by Dropbox is only supported by this lib. Later version is showing errors or deprecated methods.

Source:

https://www.dropbox.com/developers-v1/core/start/java

Code I am using is as below:

public class DropBoxUpload {
    public static void main(String[] args) throws IOException, DbxException {
        // Get your app key and secret from the Dropbox developers website.
        final String APP_KEY = "MyAppKey";
        final String APP_SECRET = "MyAppSecretKey";

        DbxAppInfo appInfo = new DbxAppInfo(APP_KEY, APP_SECRET);

        DbxRequestConfig config = new DbxRequestConfig("JavaTutorial/1.0",
            Locale.getDefault().toString());
        DbxWebAuthNoRedirect webAuth = new DbxWebAuthNoRedirect(config, appInfo);

        // Have the user sign in and authorize your app.
        String authorizeUrl = webAuth.start();
        System.out.println("1. Go to: " + authorizeUrl);
        System.out.println("2. Click \"Allow\" (you might have to log in first)");
        System.out.println("3. Copy the authorization code.");

        String code = new BufferedReader(new InputStreamReader(System.in)).readLine().trim();

        // This will fail if the user enters an invalid authorization code.
        DbxAuthFinish authFinish = webAuth.finish(code);
        String accessToken = authFinish.accessToken;

        DbxClient client = new DbxClient(config, accessToken);

        System.out.println("Linked account: " + client.getAccountInfo().displayName);

        File inputFile = new File("working-draft.txt");
        FileInputStream inputStream = new FileInputStream(inputFile);
        try {
            DbxEntry.File uploadedFile = client.uploadFile("/magnum-opus.txt",
                DbxWriteMode.add(), inputFile.length(), inputStream);
            System.out.println("Uploaded: " + uploadedFile.toString());
        } finally {
            inputStream.close();
        }

        DbxEntry.WithChildren listing = client.getMetadataWithChildren("D:\\MavenJenkinsCI\\target\\cucumber-html-reports");
        System.out.println("Files in the root path:");
        for (DbxEntry child : listing.children) {
            System.out.println("    " + child.name + ": " + child.toString());
        }

        FileOutputStream outputStream = new FileOutputStream("magnum-opus.txt");
        try {
            DbxEntry.File downloadedFile = client.getFile("/magnum-opus.txt", null,
                outputStream);
            System.out.println("Metadata: " + downloadedFile.toString());
        } finally {
            outputStream.close();
        }
    }

The problem is when I am running this code. It stuck on below line:

   String code = new BufferedReader(new InputStreamReader(System.in)).readLine().trim();

Any idea why?

Environment

  • Window 10
  • Java 8

If you have any workaround please share.

It will really help.

6
  • What do you mean by It stuck on below line ? It throws any kind of Exception? Commented Nov 3, 2017 at 13:21
  • nup no exception it throws. Just it stuck their with no result. so everytime I force close the execution after 10-15 min Commented Nov 3, 2017 at 13:22
  • 1
    The old version of the SDK you're trying to use is for Dropbox API v1, which is now retired. You should use the new version: github.com/dropbox/dropbox-sdk-java There's an uploading example here: github.com/dropbox/dropbox-sdk-java/blob/master/examples/… Commented Nov 3, 2017 at 14:53
  • @Greg - thanks a lot Greg .. I was actually looking something like same .... You can post it as answer ... I will implement it , currently I m out of office.. will let you know regarding same ... Commented Nov 3, 2017 at 14:57
  • @Greg - It's working thanks :) .. For future ref of other problem seekers .. This article also helps me .. blog.camilolopes.com.br/tag/dropbox-token Commented Nov 6, 2017 at 7:51

2 Answers 2

2

Greg has provided correct dependencies and example which leads me to accomplish by requirements.

The new version:

https://github.com/dropbox/dropbox-sdk-java

There's an uploading example here:

https://github.com/dropbox/dropbox-sdk-java/blob/master/examples/upload-file/src/main/java/com/dropbox/core/examples/upload_file/Main.java

I also add an article below which helps me during the integration :

http://blog.camilolopes.com.br/tag/dropbox-token/

Sign up to request clarification or add additional context in comments.

Comments

1

The fact that it stuck on that line is normal. The program just expects the user's input from the console in order to proceed to the next line of code.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.