This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Servlets and the fly likes Can a servlet architecture download a file? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Can a servlet architecture download a file?" Watch "Can a servlet architecture download a file?" New topic
Author

Can a servlet architecture download a file?

Glenn Murray
Ranch Hand

Joined: Dec 07, 2001
Posts: 74
Hi, I'm a servlet newbie and thought they might be a solution to my
problem, but now I wonder.

I want to run a Big Ol' Number Cruncher (BONC) on a server. From my
Java client (NOT a web browser) I want to submit a job over the
network and have the BONC run it. Currently I do this locally,
which ties up the client machine.

If a servlet does this, can the servlet, at the client's request,
then send the BONC's zipped output file back to the client? (The
unzipped output may be hundreds of MB). Searches of the web and
O'Reilly's "Servlet Programming" have not indicated that this is
possible.

Are servlets too brain dead to do this sort of thing? I would prefer
not to run a web server on the BONC server. Should I be looking at a
different technology (Globus Toolkit seems like overkill)? Surely
this has been done before.

Any help would be appreciated! Many thanks,
Glenn


Glenn Murray
Author of Yo Soy Una Vaca De Hoy
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

You should be able to do this with a servlet.
Tomcat can even take care of the gzip compression for you.
http://jakarta.apache.org/tomcat/tomcat-5.5-doc/config/http.html


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Glenn Murray
Ranch Hand

Joined: Dec 07, 2001
Posts: 74
Thanks, Ben!

At first blush, this looks plausible, but I can't find any examples.
It seems the API is

http://jakarta.apache.org/tomcat/tomcat-5.0-doc/catalina/docs/api/org/apache/coyote/tomcat5/package-summary.html

With these classes it seems I could read a server file and write
it, but what is happening on the client side? I think I'll have
to learn what this HTTPResponse business is.

Also, I don't see anything about compression, yet. I'll poke around.
The HTTPConnector business is pretty mysterious.

Thanks for the link, though.

Cheers,
Glenn
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Also, I don't see anything about compression, yet. I'll poke around.
The HTTPConnector business is pretty mysterious.


A "ctl+f" on the link I gave you with "compressableMimeType" and "compression" should give you the Tomcat specific settings for gziping your responses.
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12761
    
    5
For the client side, you might look at the HttpClient package one of the Jakarta Commons projects. This will give you convenient methods for talking to a servlet from a non-browser client.
Bill
Jeffrey Spaulding
Ranch Hand

Joined: Jan 15, 2004
Posts: 149

I think I'll have
to learn what this HTTPResponse business is.


I think this is a brillant idea when working with Servlets.



J.
Glenn Murray
Ranch Hand

Joined: Dec 07, 2001
Posts: 74
Hi,

Thanks much to all who responded. I get the feeling that Tomcat actually
might do the job. I installed 5.5.9 and browsed to the default page.
Next I'll see if I can write a Java client to contact Tomcat, and then
see if I can send a servlet something and get a response.

The more fundamental question is how to upload input files for the
BONC and download output files.

As far as compression goes, in my new installation I found that in



there is Java code which seems to send a compressed Stream via an
HttpServletResponse. I don't know why this code is there.

Thanks again!

Cheers,
Glenn
Glenn Murray
Ranch Hand

Joined: Dec 07, 2001
Posts: 74
Hi,

I thought I'd add some code to this thread. First, there is a servlet
with doPost() and doGet() methods. Then there is a Java client which
connects to the servlet and calls one method or the other, depending
on the value of DO_POST. The doPost() method will read a Stream from
the client, and write one back. Presumably this will work for
uploading and downloading files; note the API has different streams
for binary files. Also of interest is this link for a tool which
might simplify uploading.

Jakarta Commons File Upload

Cheers,
Glenn



Here is the client code.


Note the doGet() is based on the Tomcat 5.5.9 sample.war. I repeat that
I am a newbie at this. If you go to this servlet with a browser, the
doGet() is invoked. I couldn't find the distinction in the spec.
[ June 17, 2005: Message edited by: Glenn Murray ]
 
Don't get me started about those stupid light bulbs.
 
subject: Can a servlet architecture download a file?
 
Similar Threads
DB2 jdbc driver 6.2 on linux red Hat 7.2 it doesn't Work with Iplanet web server 6.0
DB2 jdbc driver 6.2 on linux red Hat 7.2 it doesn't Work with Iplanet web server 6.0
How to print
how to knoe if the files are being generated?
How send file data to JSP/Servlet page and save to disk?