Anyway to make Adobe Air Application keeping the socket open until download finish?

65 Views Asked by At

I'm creating the Adobe Air Application working as Web browser to show the Flex Application as Flash won't be supported by any browser anymore this end of the year.

But there is a file download function in Flex Application called by using ActionForm like below url

http://localhost:8080/project/action/create

then file will be written in ResponseOutputStream like the code below.

public void download(Inputstream in, HttpServletResponse response) throws IOException
{
    OutputStream out = null;
    try
    {
        response.setContentType("application/octet-stream");
        response.setHeader("Content-Disposition", "attachment; filename=\"dummy.pdf\"");
        out = response.getOutputStream();
        int len = 0;
        byte[] buffer = new byte[1024];
        while((len = in.read(buffer,0,1024)) != -1) { out.write(buffer,0, len); }
    } 
    catch (SocketException e)
    { ...

There is no problem if I use any browser to download the file but this exception has been caught if I use Air Application to download.

java.net.SocketException: Software caused connection abort: socket write error at java.net.SocketOutputStream.socketWrite0(Native Method) at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:113) at java.net.SocketOutputStream.write(SocketOutputStream.java:159) at org.apache.coyote.http11.InternalOutputBuffer.realWriteBytes(InternalOutputBuffer.java:741) at org.apache.tomcat.util.buf.ByteChunk.flushBuffer(ByteChunk.java:432) at org.apache.tomcat.util.buf.ByteChunk.append(ByteChunk.java:347) at org.apache.coyote.http11.InternalOutputBuffer$OutputStreamOutputBuffer.doWrite(InternalOutputBuffer.java:765) at org.apache.coyote.http11.filters.ChunkedOutputFilter.doWrite(ChunkedOutputFilter.java:126) at org.apache.coyote.http11.InternalOutputBuffer.doWrite(InternalOutputBuffer.java:574) at org.apache.coyote.Response.doWrite(Response.java:560) at org.apache.catalina.connector.OutputBuffer.realWriteBytes(OutputBuffer.java:353) at org.apache.tomcat.util.buf.ByteChunk.flushBuffer(ByteChunk.java:432) at org.apache.tomcat.util.buf.ByteChunk.append(ByteChunk.java:347) at org.apache.catalina.connector.OutputBuffer.writeBytes(OutputBuffer.java:381) at org.apache.catalina.connector.OutputBuffer.write(OutputBuffer.java:370) at org.apache.catalina.connector.CoyoteOutputStream.write(CoyoteOutputStream.java:89)

Problem:
I think that after /action/create url is called, air application closed the socket so ResponseOutputStream won't be able to connect to socket.

Is there anyway to keep Air Application open its socket until response has been received ? I'm trying to keep Flex Application code untouch and this is my first time create Application using Air. or if the socket is not the real cause, is there anyway I can send back this response to Air Application?

Thank you for your answer in advance.

0

There are 0 best solutions below