cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
Update: Find information on Dropbox support during COVID-19 here
Close

Dropbox API Support & Feedback

Find help with the Dropbox API from other developers.

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Highlighted

Exception in thread "main" com.dropbox.core.NetworkIOException: Read timed out

New member | Level 1
New member | Level 1

The code I'm running is this;

public class test {
static final String ACCESS_TOKEN = "<REDACTED>";
public static void main(String args[]) throws DbxException, IOException, InterruptedException
{
DbxRequestConfig config = new DbxRequestConfig("dropbox/java-tutorial", "en_US");
DbxClientV2 client = new DbxClientV2(config, ACCESS_TOKEN);
//System.out.println(config.httpRequestor.DefaultTimeoutMillis);
FullAccount account = null;
account = client.users.getCurrentAccount();
System.out.println(account);
List<Metadata> entries = client.files.listFolder("").getEntries();
//WritetoFile jal = new WritetoFile("/semesterProject.client/", "text.txt");
for (Metadata metadata : entries) {
System.out.println(metadata.getName());
//System.out.println(jal.getClass());
//jal.addtoFile(metadata.name);
}
File file = new File("/semesterProject.client/text.txt");
if(!file.exists()) {
System.out.println("File does not exist");
file.createNewFile();// create your file on the file system
}
if(file.exists())
{
System.out.println("File exists");
}
//InputStream in = new FileInputStream(file);
//FileMetadata metadata = client.files.uploadBuilder("/semesterProject.client/text.txt").uploadAndFinish(in);
//DisplayTextFile newfile = new DisplayTextFile("/semesterProject.client/text.txt");
//for(int i=0; i<newfile.getList().size(); i++)
//{
//System.out.println(newfile.getList().get(i));
//}
//System.out.println(DbxEntry.Folder.class);
DbxClientV1 client45 = new DbxClientV1(config, ACCESS_TOKEN);
client45.createFolder("/doggone");
DbxEntry.Folder fold= new DbxEntry.Folder("/doggone", "dog", false);
//System.out.println(fold.toString());
ArrayList kal = null;
//kal = new ArrayList(newfile.getList());
//OrderList kal2 = new OrderList(kal);
//Hashtable mak=kal2.orderAlphabetically();
//sortJava sorting =new sortJava(kal);
//final String[] get=sorting.sorted();
//System.out.println(get[2]);
JFrame frame = new JFrame("FrameDemo");
JTextArea text = new JTextArea();
int k=0;
//Set kalll=mak.keySet();
//Object[] objectarray= new Object[kalll.size()];
//kalll.toArray(objectarray);
//text.setColumns(objectarray.length);
/*while(k<objectarray.length)
{
/text.append((String) mak.get((objectarray[k]))+"\n");
k++;
}*/
frame.add(text);
frame.setVisible(true);
entries = client.files.listFolder("").getEntries();
for (Metadata metadata2 : entries) {
//System.out.println(metadata2.pathLower);
// jal.addtoFile(metadata.name);
}
frame.dispose();
getAllFolders(entries, client);
}
public static void getAllFolders(List <Metadata> entries, DbxClientV2 client ) throws DbxException, IOException
{
ArrayList<String> folders = new ArrayList<String>();
int count =0;
folders.add("");
getfolders(folders, count);
for(int foldercount=0; foldercount<folders.size();foldercount++)
{
System.out.println(folders.get(foldercount)+"KALL");
}
}
public static void getfolders(ArrayList<String> folders, int count) throws DbxException
{
for(int foldercount=count; foldercount<folders.size();foldercount++)
{
DbxRequestConfig config = new DbxRequestConfig("dropbox/java-tutorial", "en_US");
DbxClientV2 client2 = new DbxClientV2(config, ACCESS_TOKEN);
DbxClientV1 client3 = new DbxClientV1(config, ACCESS_TOKEN);
System.out.println(folders.get(foldercount));
List <Metadata>entries = client2.files.listFolder(folders.get(foldercount)).getEntries();
int hal=0;
for (Metadata metadata : entries)
{
DbxDelta<DbxEntry> result = null;
if(!folders.get(foldercount).startsWith("/"))
{
result = client3.getDeltaWithPathPrefix(null, "/"+folders.get(foldercount));
}
else
{
result = client3.getDeltaWithPathPrefix(null, folders.get(foldercount));
}
List<Entry<DbxEntry>> cursor = result.entries;
for (Entry<DbxEntry> entry : cursor)
{
if(entry.metadata.isFolder())
{
folders.add(entry.metadata.path);
}
}
hal++;
System.out.println(hal);
}
client3 = new DbxClientV1(config, ACCESS_TOKEN);
}
count++;
getfolders(folders, count);
}
}

 

And the error message I'm getting is this;

Exception in thread "main" com.dropbox.core.NetworkIOException: Read timed out
at com.dropbox.core.DbxRequestUtil.readJsonFromResponse(DbxRequestUtil.java:364)
at com.dropbox.core.v1.DbxClientV1$8.handle(DbxClientV1.java:1579)
at com.dropbox.core.v1.DbxClientV1$8.handle(DbxClientV1.java:1575)
at com.dropbox.core.DbxRequestUtil.finishResponse(DbxRequestUtil.java:432)
at com.dropbox.core.DbxRequestUtil$2.run(DbxRequestUtil.java:425)
at com.dropbox.core.DbxRequestUtil.runAndRetry(DbxRequestUtil.java:469)
at com.dropbox.core.DbxRequestUtil.doPostNoAuth(DbxRequestUtil.java:421)
at com.dropbox.core.DbxRequestUtil.doPost(DbxRequestUtil.java:410)
at com.dropbox.core.v1.DbxClientV1.doPost(DbxClientV1.java:2222)
at com.dropbox.core.v1.DbxClientV1._getDelta(DbxClientV1.java:1575)
at com.dropbox.core.v1.DbxClientV1.getDeltaWithPathPrefix(DbxClientV1.java:1536)
at test.getfolders(test.java:129)
at test.getAllFolders(test.java:10
at test.main(test.java:101)
Caused by: java.net.SocketTimeoutException: Read timed out
at java.net.SocketInputStream.socketRead0(Native Method)
at java.net.SocketInputStream.socketRead(SocketInputStream.java:116)
at java.net.SocketInputStream.read(SocketInputStream.java:170)
at java.net.SocketInputStream.read(SocketInputStream.java:141)
at sun.security.ssl.InputRecord.readFully(InputRecord.java:465)
at sun.security.ssl.InputRecord.readV3Record(InputRecord.java:593)
at sun.security.ssl.InputRecord.read(InputRecord.java:532)
at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:973)
at sun.security.ssl.SSLSocketImpl.readDataRecord(SSLSocketImpl.java:930)
at sun.security.ssl.AppInputStream.read(AppInputStream.java:105)
at java.io.BufferedInputStream.fill(BufferedInputStream.java:246)
at java.io.BufferedInputStream.read1(BufferedInputStream.java:286)
at java.io.BufferedInputStream.read(BufferedInputStream.java:345)
at sun.net.www.http.ChunkedInputStream.fastRead(ChunkedInputStream.java:244)
at sun.net.www.http.ChunkedInputStream.read(ChunkedInputStream.java:689)
at java.io.FilterInputStream.read(FilterInputStream.java:133)
at sun.net.www.protocol.http.HttpURLConnection$HttpInputStream.read(HttpURLConnection.java:3335)
at com.fasterxml.jackson.core.json.UTF8StreamJsonParser.loadMore(UTF8StreamJsonParser.java:207)
at com.fasterxml.jackson.core.json.UTF8StreamJsonParser.slowParseName(UTF8StreamJsonParser.java:1877)
at com.fasterxml.jackson.core.json.UTF8StreamJsonParser._parseName(UTF8StreamJsonParser.java:1669)
at com.fasterxml.jackson.core.json.UTF8StreamJsonParser.nextToken(UTF8StreamJsonParser.java:752)
at com.dropbox.core.json.JsonDateReader$1.read(JsonDateReader.java:29)
at com.dropbox.core.json.JsonDateReader$1.read(JsonDateReader.java:19)
at com.dropbox.core.json.JsonReader.readField(JsonReader.java:4
at com.dropbox.core.v1.DbxEntry._read(DbxEntry.java:872)
at com.dropbox.core.v1.DbxEntry.read(DbxEntry.java:827)
at com.dropbox.core.v1.DbxEntry$1.read(DbxEntry.java:611)
at com.dropbox.core.v1.DbxEntry$1.read(DbxEntry.java:607)
at com.dropbox.core.json.JsonReader.readOptional(JsonReader.java:5
at com.dropbox.core.v1.DbxDelta$Entry$Reader.read(DbxDelta.java:274)
at com.dropbox.core.v1.DbxDelta$Entry$Reader.read(DbxDelta.java:24
at com.dropbox.core.v1.DbxDelta$Entry$Reader.read(DbxDelta.java:237)
at com.dropbox.core.json.JsonArrayReader.read(JsonArrayReader.java:44)
at com.dropbox.core.json.JsonArrayReader.read(JsonArrayReader.java:33)
at com.dropbox.core.json.JsonReader.readField(JsonReader.java:4
at com.dropbox.core.v1.DbxDelta$Reader.read(DbxDelta.java:130)
at com.dropbox.core.v1.DbxDelta$Reader.read(DbxDelta.java:102)
at com.dropbox.core.v1.DbxDelta$Reader.read(DbxDelta.java:91)
at com.dropbox.core.json.JsonReader.readFully(JsonReader.java:565)
at com.dropbox.core.json.JsonReader.readFully(JsonReader.java:45
at com.dropbox.core.DbxRequestUtil.readJsonFromResponse(DbxRequestUtil.java:359)
... 13 more

 

Is there any way of solving this without changing the timeout timer? If there isn't, how can I change the timeout period?

 

8 Replies 8
Highlighted

Re: Exception in thread "main" com.dropbox.core.NetworkIOException: Read timed out

New member | Level 1
New member | Level 1

Not sure if it will work for others, but having 

static final DbxRequestConfig config = new DbxRequestConfig("testtest/1.0", "en_US");

has helped me.

Nonetheless, I have a problem of getting folders from shared files, as listfolder just gets the Metadata, which I cannot check if it contains folder or not.

Highlighted

Re: Exception in thread "main" com.dropbox.core.NetworkIOException: Read timed out

Dropboxer
Dropboxer

Hi Yusuf, I'm glad to hear you got that working already.

I'm not sure if I understand your follow up question though, can you elaborate? If you mean you need to distinguish between files and folders given a Metadata object, you can do so by checking the class. FileMetadata, FolderMetadata, and DeletedMetadata are subclasses of metadata. Here's a sample of checking between them:

https://github.com/dropbox/dropbox-sdk-java/blob/152c926bfe357f555e5714835c43fba0838a89b9/examples/a...

By the way, I redacted your access token, but for the sake of security, you should disable it now. You can do so by revoking access to the app entirely, if the access token is for your account, here:

https://www.dropbox.com/account/security

Or, you can disable just this access token using the /disable_access_token endpoint:

https://www.dropbox.com/developers/core/docs#disable-token

 

Highlighted

Re: Exception in thread "main" com.dropbox.core.NetworkIOException: Read timed out

New member | Level 1
New member | Level 1

The fundamantel problem I had was to check whether the files were folders or not. That wasn't possible with Metadata, but it was possible with client3.getMetadataWithChildren().

For some reason however, client3.getDeltaWithPathPrefix() does not get shared folders while getMetadataWithChildren does.

Highlighted

Re: Exception in thread "main" com.dropbox.core.NetworkIOException: Read timed out

Dropboxer
Dropboxer

Thanks for clarifying. It sounds like you're talking about using listFolder for API v2, which returns a Metadata object, as opposed to getMetadataWithChildren for API v1.

In that case, my reply does apply.  Check out this sample for an example of how you can tell between files and folders when you have a Metadata object:

https://github.com/dropbox/dropbox-sdk-java/blob/152c926bfe357f555e5714835c43fba0838a89b9/examples/a...

In short, you can use instanceof to check if it's a FolderMetadata or FileMetadata (or DeletedMetadata).

Also, when you use getDeltaWithPathPrefix, are you checking hasMore on the response? If getDeltaWithPathPrefix is true, you need to call back again to get more results.

 

Highlighted

Re: Exception in thread "main" com.dropbox.core.NetworkIOException: Read timed out

New member | Level 1
New member | Level 1

Alright, the problem seems to restart again, as after a while when I'm trying to access to client, same NetworkIOException occurs, regardless of how many times I reinitialize DbxClientV2 and DbxClientV1.

Highlighted

Re: Exception in thread "main" com.dropbox.core.NetworkIOException: Read timed out

Dropboxer
Dropboxer

Since it sounds like the NetworkIOException problem is intermittent, is it possible it's related to issues with your network connection. For example, are you able to reproduce the issue when using a different Internet connection?

Highlighted

Re: Exception in thread "main" com.dropbox.core.NetworkIOException: Read timed out

New member | Level 1
New member | Level 1

Took me long to response, but yes, regardless of the connection I get this.

Highlighted

Re: Exception in thread "main" com.dropbox.core.NetworkIOException: Read timed out

Dropboxer
Dropboxer

Thanks for following up. Can you give me a better idea of how much/often you see this so we can look into it? Specifically, does it happen consistently, or only sporadically, and in either case, when you are seeing failures, what percent of your API calls fail? Thanks in advance! 

Polls
Do you know how to organize your files and folders?
We have created a guide on folder best practice, so you can get organized now check it out here.

Work Smarter with Dropbox

The way we work is changing. Share and discover new ways to work smarter with Dropbox in our community.

Sound good? Let's get started.
Who's talking

Top contributors to this post

What do Dropbox user levels mean?
Need more support?