File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Tomcat and the fly likes Can't download large file from url by tomcat Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Products » Tomcat
Bookmark "Can Watch "Can New topic
Author

Can't download large file from url by tomcat

Ori Brill
Greenhorn

Joined: Jun 12, 2011
Posts: 2
Hi all..

I have a problem that's been bothering me for a month already.

I write a code that download url file to my workspace. My code works well for any size file.
Here is my code:



But, i want to do it automaticly, so i packaged this code by Java Service. I use tomcat 7.0.12.

Now, this code works well only for small files. If i try to download large file like the second one, I get this error for "byteCount = in.read(buffer);" line:


java.net.SocketException: Connection reset
at java.net.SocketInputStream.read(SocketInputStream.java:185)
at java.io.BufferedInputStream.fill(BufferedInputStream.java:235)
at java.io.BufferedInputStream.read(BufferedInputStream.java:254)
at sun.net.ftp.impl.FtpClient.readServerResponse(FtpClient.java:417)
at sun.net.ftp.impl.FtpClient.readReply(FtpClient.java:494)
at sun.net.ftp.impl.FtpClient.issueCommand(FtpClient.java:529)
at sun.net.ftp.impl.FtpClient.issueCommandCheck(FtpClient.java:540)
at sun.net.ftp.impl.FtpClient.openPassiveDataConnection(FtpClient.java:603)
at sun.net.ftp.impl.FtpClient.openDataConnection(FtpClient.java:696)
at sun.net.ftp.impl.FtpClient.getFileStream(FtpClient.java:1269)
at sun.net.www.protocol.ftp.FtpURLConnection.getInputStream(FtpURLConnection.java:427)
at java.net.URL.openStream(URL.java:1035)
at MyService.downloadFilesToWorkspace(MyService.java:137)
at MyService.doDownloadForToday(MyService.java:87)
at MyService.start(MyService.java:47)
at MyService.windowsService(MyService.java:35)
java.lang.NullPointerException
at MyService.downloadFilesToWorkspace(MyService.java:153)
at MyService.doDownloadForToday(MyService.java:87)
at MyService.start(MyService.java:47)
at MyService.windowsService(MyService.java:35)


If someone has any idea why this happens and what sould i change, i would be glad to hear them.

Thanks,

Ori
Daniel Yan
Greenhorn

Joined: Nov 24, 2011
Posts: 1
Hi Ori,

Have you got an answer?
I have exactly the same problem. I have tried different solutions but with the same result.
Goes well for small files, not for big ones.
The read() function stops until it get's connection reset after a while.

Also tried apache.commons.io.FileUtils.getURLToFile(URL ..., File ...) but with same result.

Curious, is that instead of getting an url file (http://...), I tried with the same file (downloaded by browser) already saved at my disk (file:///...). And from filesystem it works with the same code.
I suspect the problem is the connections opened.

Hope for a solution,
DnlCY
Ori Brill
Greenhorn

Joined: Jun 12, 2011
Posts: 2
Hi daniel,

Unfortunately, I did not find a solution then. It was part of my BSc's finish project and i was supposed to have it ready by the deadline.
Without a solution, I changed the project design so that the operation <file downloading> will not occur automatically by Java Servise but by the task scheduler of the operating system.

But still nice to find people who read my problems

Sorry And Tnx,

Ori
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Can't download large file from url by tomcat