Click to See Complete Forum and Search --> : ClientAbortExceptionError in struts..


irs_bandari
10-09-2006, 05:23 AM
Hi

I am writing a struts appliction to download a file that is on the server. When the user clicks the download button, its displaying the open,save cancel window. Open and save are working fine, but while downloading a word doc or pdf, when the user clicks cancel, its displaying a ClientAbort Exception.

ClientAbortException: java.net.SocketException: Connection reset by peer: socket write error
Oct 9, 2006 11:08:25 AM org.apache.struts.action.RequestProcessor processException
WARNING: Unhandled Exception thrown: class org.apache.catalina.connector.ClientAbortException

While downloading a image, if user clicks cancel, its working fine.
Please help me how to avoid this situation.

agent_x91
10-09-2006, 06:04 AM
Sounds like the server wasn't expecting the client to disconnect. I've had a similar error before. Can I see your code?

irs_bandari
10-09-2006, 06:12 AM
Hi, this is my code

FileOutputStream fs=null;
FileInputStream fis=null;

response.setHeader("Content-disposition","Attachment; filename="+selectedfile);
response.setContentType("application/octet-stream");
ServletContext context = getServlet().getServletContext();
String absolutePath = context.getRealPath("/downloads/"+selectedfile);
System.out.println("absolutepath----"+absolutePath);

try
{
con=DBUtil.getConnection();
Statement stm =con.createStatement();
ResultSet rs=stm.executeQuery("select FILECONTENT from TEST_DETAILS where PATH='"+selectedfile+"' AND MR_NO='"+mrno+"' AND PATIENT_ID='"+patid+"'AND CONDUCTED_DATE=to_date('"+conductedate+"','DD-MON-YYYY') AND to_char(CONDUCTED_TIME,'HH:MI:SS AM')='"+conductedtime+"' ");
fs=new FileOutputStream(absolutePath);
int n=0;
InputStream is=null;
while(rs.next())
{
is=rs.getBinaryStream(1);
int i=is.read();
while(i!=-1)
{
fs.write(i);
i=is.read();
}
}

b=true;

}catch(Exception e){System.out.println("Cause-->"+e);b=false;}


BufferedInputStream bis = null;
BufferedOutputStream bos = null;
File f=new File(absolutePath);
try{

fis=new FileInputStream(f);
int length = fis.available();
bis = new BufferedInputStream(fis);
bos = new BufferedOutputStream(out);
byte[] buff = new byte[length];
int bytesRead;
while(-1 != (bytesRead = bis.read(buff, 0, buff.length))) {
bos.write(buff, 0, bytesRead);

}

}
catch(Exception e){System.out.println("in reading "+ e);}

finally{


try{
if(out!=null)
out.flush();
}catch(java.net.SocketException cae){System.out.println("ClientAborted"+cae);}
if(bis!=null)
bis.close();
if(bos!=null)
bos.close();
try{
if(con!=null)
con.close();
}catch(SQLException sqle){System.out.println("Exception in closing connection"+sqle);}
f.deleteOnExit();
}

//out.close();

return null;

agent_x91
10-09-2006, 06:34 AM
Hmm, I'm not entirely sure what your problem is being caused by. When I experienced the problem before, I was using ServerSocket and Socket objects in the server, and I simply needed to close the ServerSocket object as soon as a client had connected, like so:


client=server.accept();
server.close();
//...


But it doesn't quite apply in the same way here. Sorry if this was no help at all :o