File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes urgent help - java.net.SocketException: Connection reset by peer: socket write error Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "urgent help - java.net.SocketException: Connection reset by peer: socket write error" Watch "urgent help - java.net.SocketException: Connection reset by peer: socket write error" New topic
Author

urgent help - java.net.SocketException: Connection reset by peer: socket write error

mudit khandelwal
Greenhorn

Joined: Sep 28, 2004
Posts: 1
Strangely and unluckily, I have a problem that's happening only in PRODUCTION env and not on DEVELOPMENT/CERT :-(

When I make an Http request to a server (using java.net.URL and URLConnection classes) which sends a pdf as a response, I get the response and read it in a BufferedInputStream. Then in order to display the pdf on my browser, am trying to write bytes to ServletOutputStream using byte array:
bis is the BufferedInputStream;

byte[] buff = new byte[1024];
int bytesRead;
while (-1 != (bytesRead = bis.read(buff, 0, buff.length))){
out.write(buff, 0, bytesRead);
}

Many a times it works properly and the pdf is rendered but sometimes I get 'java.net.SocketException: Connection reset by peer: socket write error' exception while trying to write to the ServletOutputStream in the while loop - out.write(buff, 0, bytesRead);

(Am using weblogc 8.1 sp2)

error log:
java.net.SocketException: Connection reset by peer: socket write error
at java.net.SocketOutputStream.socketWrite0(Native Method)
at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:92)
at java.net.SocketOutputStream.write(SocketOutputStream.java:136)
at weblogic.servlet.internal.ChunkUtils.writeChunkTransfer(ChunkUtils.java:247)
at weblogic.servlet.internal.ChunkUtils.writeChunks(ChunkUtils.java:223)
at weblogic.servlet.internal.ChunkOutput.flush(ChunkOutput.java:296)
at weblogic.servlet.internal.ChunkOutput.checkForFlush(ChunkOutput.java:371)
at weblogic.servlet.internal.ChunkOutput.write(ChunkOutput.java:241)
at weblogic.servlet.internal.ChunkOutputWrapper.write(ChunkOutputWrapper.java:113)
at weblogic.servlet.internal.ServletOutputStreamImpl.write(ServletOutputStreamImpl.java:184)
at tavant.olympus.common.utils.ServletHelper.writeToServletOutputStream(ServletHelper.java:48)
at tavant.olympus.base.GenericRetrievalServlet.sendRequestAndPrintTheResponse(GenericRetrievalServlet.java:90)
at

tavant.olympus.client.aereports.AEStaticReportsRetrievalServlet.serviceRequest(AEStaticReportsRetrievalServlet.java:34)
at tavant.olympus.base.GenericRetrievalServlet.doPost(GenericRetrievalServlet.java:57)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:760)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at weblogic.servlet.internal.ServletStubImpl$ServletInvocationAction.run(ServletStubImpl.java:971)
at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:402)
at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:305)
at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:6350)
at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:317)
at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:118)
at weblogic.servlet.internal.WebAppServletContext.invokeServlet(WebAppServletContext.java:3635)
at weblogic.servlet.internal.ServletRequestImpl.execute(ServletRequestImpl.java:2585)
at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:197)
at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:170)

Any kinna help will be highly appreciated !!
Thanx in advance.
Mudit
Vijay Vaddem
Ranch Hand

Joined: Feb 13, 2004
Posts: 243
Hi,

Please go through the below given link. Could be helpful to you...

Connection Reset

Go through the response given by Kartik Ruppa and the link being provided.

Vijay
yerri swamy moke
Greenhorn

Joined: Jan 30, 2009
Posts: 1
Hi,

I am also facing same issue, please give me the solution for this issue.
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

The same issue? So you are using WebLogic v8.1 and are streaming a PDF to the client?


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12835
    
    5
Just dont worry about it.

The client side closed the connection for some reason, nothing can be done on the server side to prevent this.

You could catch the Exception in your servlet method if you need to log that the transfer was incomplete.

Bill
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: urgent help - java.net.SocketException: Connection reset by peer: socket write error