Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1126
  • Last Modified:

java.net.SocketException: Broken pipe

Hello,
I'm using this code ServletOutputStream to export image to file. It works OK on window, but on unix, sometime it works, sometime it doesn't work and I got an exeption java.net.SocketException: Broken pipe
Please help
Thanks
0
nphnhi
Asked:
nphnhi
  • 3
  • 2
1 Solution
 
TimYatesCommented:
Are you flushing the stream?

I take it you are sending it to a webbrowser?

It could be that the browser is closing or moving off the page before the image is shown...

maybe...
0
 
nphnhiAuthor Commented:

            try {
                  ServletOutputStream out = response.getOutputStream();
                  response.setContentType(imagetype);
                  response.setHeader("Content-disposition", "attachment;filename=" + filename);
                  int      index = chartnumber - 1;
                  String cdl = ((NFGraph) ngraph.elementAt(index)).getCDL();
                  NFGraph chart = NFGraph.getGraphFromTemplate(cdl);
                  NFImageGeneration.writeImage(chart, imagetype, out);
                  out.flush();
                  out.close();
            } catch (Exception ex) {
                  logger.error( "" + ex);
                  return -1;
            }
0
 
nphnhiAuthor Commented:
As TimYates said, if that, how can I solve it???
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
TimYatesCommented:
Not sure you can...  if the user is just navigating away from the page, the pipe will be broken...
0
 
nphnhiAuthor Commented:
I saw what's wrong, in fact, I have a jsp page which calls a servlet to export a chart (using ServletOutputStream to flush out the stream), and in jsp file, I have a code like that:
<form action="servlet_to_flush_stream">
..
<iframe name="f" src="" onreadystatechange="stateChanged()" style="display:none"></iframe>
..
</form>

...
<script>
function stateChanged()
{
   if (document.all['f'].readyState=="interactive")
   {
        if(document.all['f'].src != "")
        {
            // we need to call setInterval in a separated thread,
            // so it'll not be blocked by the save dialog.
            setTimeout(function()
            {
                interval = setInterval(function()
                {
                    if(!self.closed)
                    {
                        self.opener = null;
                        self.close();
                    }
                },1000); //// HERE I TRY TO CLOSE THE JSP PAGE EACH 1 second
            },1);///// HERE I set timeout is 1 msecond ??? but how can we know how much time we need to flush the stream
        }
   }
}
</script>
0
 
moduloCommented:
PAQed with points refunded (50)

modulo
Community Support Moderator
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now