I’ve been writing a little application that will let people upload & download files to me. I’ve added a web service to this applciation to provide the upload/download functionality that way but I’m not too sure on how well my implementation is going to cope with large files.
At the moment the definitions of the upload & download methods look like this (written using Apache CXF):
boolean uploadFile(@WebParam(name = 'username') String username, @WebParam(name = 'password') String password, @WebParam(name = 'filename') String filename, @WebParam(name = 'fileContents') byte[] fileContents) throws UploadException, LoginException; byte[] downloadFile(@WebParam(name = 'username') String username, @WebParam(name = 'password') String password, @WebParam(name = 'filename') String filename) throws DownloadException, LoginException;
So the file gets uploaded and downloaded as a byte array. But if I have a file of some stupid size (e.g. 1GB) surely this will try and put all that information into memory and crash my service.
So my question is – is it possible to return some kind of stream instead? I would imagine this isn’t going to be terribly OS independent though. Although I know the theory behind web services, the practical side is something that I still need to pick up a bit of information on.
Cheers for any input, Lee
Stephen Denne has a Metro implementation that satisfies your requirement. My answer is provided below after a short explination as to why that is the case.
Most Web Service implementations that are built using HTTP as the message protocol are REST compliant, in that they only allow simple send-receive patterns and nothing more. This greatly improves interoperability, as all the various platforms can understand this simple architecture (for instance a Java web service talking to a .NET web service).
If you want to maintain this you could provide chunking.
This would require some footwork in cases where you don’t get the chunks in the right order (Or you can just require the chunks come in the right order), but it would probably be pretty easy to implement.