PDA

View Full Version : How to download file over Hessian servlet


tiberiu.benedek
07-15-2011, 06:57 AM
Hi all,


I am trying with no success to implement a download scenario between an Applet and a Hessian Servlet. The applet needs to display files that are stored on a machine behind a firewall, where the Applet cannot access, as such I send to the hessian servlet the file URL, and the hessian downloads from this URL and sends the data to the Applet. The files can be quite large as such caching the file on server side is out of the question.

Here is what I tried with no success
public interface Document{
InputStream download(String fileURL);
}

Hessian Servlet implementaion:
....
@Override
public InputStream download(String fileURL) {
try {
URL conn = new URL(contentObject.getFileURL());
URLConnection urlConn = conn.openConnection();
return urlConn.getInputStream();
} catch (IOException e) {
//handle error;
}
}
....
Client implementation:
HessianProxyFactory factory = new HessianProxyFactory();
Object hessianProxy = (Document) factory.create(Document.class, hessianUrl);
InputStream in = hessianProxy.download("url to the file");

At this point, when reading from the InputStream i get following exception on server side:
SEVERE: Servlet.service() for servlet viewerHessianServlet threw exception
java.net.SocketException: Software caused connection abort: socket write error
at java.net.SocketOutputStream.socketWrite0(Native Method)
at java.net.SocketOutputStream.socketWrite(SocketOutp utStream.java:92)
at java.net.SocketOutputStream.write(SocketOutputStre am.java:136)
at org.apache.coyote.http11.InternalOutputBuffer.real WriteBytes(InternalOutputBuffer.java:741)
at org.apache.tomcat.util.buf.ByteChunk.flushBuffer(B yteChunk.java:432)
at org.apache.tomcat.util.buf.ByteChunk.append(ByteCh unk.java:347)
at org.apache.coyote.http11.InternalOutputBuffer$Outp utStreamOutputBuffer.doWrite(InternalOutputBuffer. java:765)
at org.apache.coyote.http11.filters.ChunkedOutputFilt er.doWrite(ChunkedOutputFilter.java:124)
at org.apache.coyote.http11.InternalOutputBuffer.doWr ite(InternalOutputBuffer.java:574)
at org.apache.coyote.Response.doWrite(Response.java:5 60)
at org.apache.catalina.connector.OutputBuffer.realWri teBytes(OutputBuffer.java:353)
at org.apache.tomcat.util.buf.ByteChunk.flushBuffer(B yteChunk.java:432)
at org.apache.catalina.connector.OutputBuffer.doFlush (OutputBuffer.java:309)
at org.apache.catalina.connector.OutputBuffer.flush(O utputBuffer.java:288)
at org.apache.catalina.connector.CoyoteOutputStream.f lush(CoyoteOutputStream.java:98)
at com.caucho.hessian.io.Hessian2Output.flush(Hessian 2Output.java:1540)
at com.caucho.hessian.io.Hessian2Output.close(Hessian 2Output.java:1576)
at com.caucho.hessian.server.HessianSkeleton.invoke(H essianSkeleton.java:205)
at com.caucho.hessian.server.HessianServlet.invoke(He ssianServlet.java:389)
at com.caucho.hessian.server.HessianServlet.service(H essianServlet.java:369)
at org.apache.catalina.core.ApplicationFilterChain.in ternalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.do Filter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invo ke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invo ke(StandardContextValve.java:191)
at org.apache.catalina.authenticator.AuthenticatorBas e.invoke(AuthenticatorBase.java:563)
at org.apache.catalina.core.StandardHostValve.invoke( StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke (ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invok e(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.servic e(CoyoteAdapter.java:298)
at org.apache.coyote.http11.Http11Processor.process(H ttp11Processor.java:857)
at org.apache.coyote.http11.Http11Protocol$Http11Conn ectionHandler.process(Http11Protocol.java:588)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run( JIoEndpoint.java:489)
at java.lang.Thread.run(Thread.java:662)


and on client side:
ava.io.IOException: stream is closed
at sun.net.www.http.ChunkedInputStream.ensureOpen(Unk nown Source)
at sun.net.www.http.ChunkedInputStream.read(Unknown Source)
at java.io.FilterInputStream.read(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection$HttpIn putStream.read(Unknown Source)
at com.caucho.hessian.io.Hessian2Input.readBuffer(Hes sian2Input.java:2783)
at com.caucho.hessian.io.Hessian2Input.read(Hessian2I nput.java:2729)
at com.caucho.hessian.io.Hessian2Input$ReadInputStrea m.read(Hessian2Input.java:2917)
at java.io.InputStream.read(Unknown Source)
at java.util.concurrent.FutureTask$Sync.innerRun(Unkn own Source)
at java.util.concurrent.FutureTask.run(Unknown Source)
at javax.swing.SwingWorker.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run Task(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run (Unknown Source)
at java.lang.Thread.run(Unknown Source)


Any input is most appreciated.

res1122
08-05-2011, 06:52 AM
Very useful and authentic information. You mention here. I read it. Great work done.

tiberiu.benedek
08-10-2011, 07:14 AM
I was hoping for a solution to my problem, not to "cheers" that I have done excellent copy/paste from a stack trace