从运行Java Jersey Rest API的HTTP服务器传输大文件 [英] Large file transfer from HTTP server running Java Jersey Rest API

查看:298
本文介绍了从运行Java Jersey Rest API的HTTP服务器传输大文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Java JDK 1.7和Jersey Web服务框架编写Web服务。我需要提供的一件事是允许经过身份验证的客户端下载某些大型数据文件(1-3 GB)。理想情况下,我希望这是一个暂停和恢复类型可下载选项。我尝试了jersey多部分API,并且能够在我的客户端计算机上运行高达400 MB,但除此之外,它遇到了内存不足的问题。我也担心服务器在遇到同时下载请求时可能会失败。有关如何做到这一点的任何想法? Netty是一个选择吗?关于如何将Netty集成到基于Jersey的现有Web服务的任何指针?是否有其他框架可用于帮助实现此目的?我必须使用java作为Web服务。任何指针都会有所帮助。

I am writing a web service using Java JDK 1.7 and Jersey Web service Framework. One of the things I need to provide is a way to allow authenticated clients to download certain large data files ( 1-3 GB). Ideally I would like this to be a pause and resume type downloadable option. I tried the jersey multi-part API and was able to get it to work on my client machine upto 400 MB but beyond that it ran into out-of memory issues. I am also worried that the server might fail when faced with simultaneous download requests. Any thoughts on how this can be done? Is Netty an option? Any pointers on how Netty can be integrated into a existing Jersey based web service? Are there other frame works available to help accomplish this? I do have to use java for the web service. Any pointers will be helpful.

推荐答案

如果您遇到内存不足问题,应检查处理正在下载的数据的方式。如果您使用的是Jersey的ClientResponse,请确保使用的是getEntityInputStream()而不是getEntity()。这样,您可以流式传输数据,将其写入文件,并将其抛在一边,而不是让它在Java堆空间中建立。

If you are getting stuck on out-of-memory issues, you should check how you are handling the data you are downloading. If you are using Jersey's ClientResponse, make sure you are using getEntityInputStream() and not getEntity(). This way, you can stream the data, write it to file, and toss it aside, rather than letting it build up in the Java heap space.

我不能真的谈论你的同时下载问题,但如果你正在使用Web服务框架,那么它应该被正确处理。

I can't really speak about your simultaneous download concerns, but if you are using the web services framework, then it should be handled properly.

对于这两个问题,有关具体实现的更多信息,尤其是代码,将帮助您获得更好的响应。

For both issues, more info on your specific implementation, especially code, will help you get a better response.

这篇关于从运行Java Jersey Rest API的HTTP服务器传输大文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆