General J2EE: how can I pass an InputStream over RMI?
My EJB application stores files as blobs in a database. I would like to be able to invoke a method on an EJB and pass in an InputStream object representing the file to blob.
- Posted by: Ed Roman
- Posted on: June 19 2001 12:58 EDT
However, since InputStream is not serializable, that won't work. I've considered converting the InputStream's into byte arrays, and back into InputStreams to blob in the database, but that doesn't seem like a good idea when dealing with large files.
You could open a server socket on the client and route the stream directly from the database to the client socket on the server (as you may not open server sockets on the server, as strange as it sounds ;-). I'm not sure if this is feasible but you could give it a try.
i wouldn't directly call the ejb. maybe it doesn't make to much sense to get it via an ejb out of the db.
in fact, i had an similar idea half an year ago: i tryed to pass System.out via RMI to be able to print to it from a remote client. just as an rmi investigation ...
that time i just accepted that it doesnt work.
but it seems logic: there is the concept of streams. jdbc gives a stream. probably on the client side you would really like to have a stream. never leaving the concept of streams would give a good jdbc driver the possibility to never have the whole BIG-DATA in the servers ram, so it would save resources. hm?
in using a servlet approach (and sending the data out like html data) this optimization may or may not work, it depends on your jdbc driver AND on your servlet engine.
to reduce the dependency to the jdbc driver alone, one could implement two rmi-servers:
you could pass an special inputStream along with your request parameters to an pusher-rmi-server inside the app-server. the special inputStream would also be an rmi-server. after you have created it on the client side, you pass it to the pusher-rmi-server, and he can use the stub of the stream to push the data in blocks (by doing callbacks).
if your rmi-inputStream implements java.io.InputStream you may also pass it to the jdbc functions so that they will push the data block by block - and the data should flow.
hope this helps - i never tryed it.
if you'll try it: give feedback.
--- you've got a great j2ee project and search still
--- the right java-guys? contact me: markus dot lado at gmx dot de
You can use library made for this purposes