sangameshrh
asked on
java.net.SocketException: Connection reset While using Apache HTTPClient
I am using HTTPClient for file upload.
The first time it is giving an exception like this
java.net.SocketException: Connection reset
at java.net.SocketInputStream .read(Unkn own Source)
at java.io.BufferedInputStrea m.fill(Unk nown Source)
at java.io.BufferedInputStrea m.read(Unk nown Source)
at org.apache.commons.httpcli ent.HttpPa rser.readR awLine(Htt pParser.ja va:78)
at org.apache.commons.httpcli ent.HttpPa rser.readL ine(HttpPa rser.java: 106)
at org.apache.commons.httpcli ent.HttpCo nnection.r eadLine(Ht tpConnecti on.java:11 16)
at org.apache.commons.httpcli ent.HttpMe thodBase.r eadStatusL ine(HttpMe thodBase.j ava:1973)
at org.apache.commons.httpcli ent.HttpMe thodBase.r eadRespons e(HttpMeth odBase.jav a:1735)
at org.apache.commons.httpcli ent.HttpMe thodBase.e xecute(Htt pMethodBas e.java:109 8)
at org.apache.commons.httpcli ent.HttpMe thodDirect or.execute WithRetry( HttpMethod Director.j ava:398)
at org.apache.commons.httpcli ent.HttpMe thodDirect or.execute Method(Htt pMethodDir ector.java :171)
at org.apache.commons.httpcli ent.HttpCl ient.execu teMethod(H ttpClient. java:397)
at org.apache.commons.httpcli ent.HttpCl ient.execu teMethod(H ttpClient. java:323)
at test.Test.actionPerformed( Test.java: 459)
at javax.swing.AbstractButton .fireActio nPerformed (Unknown Source)
at javax.swing.AbstractButton $Handler.a ctionPerfo rmed(Unkno wn Source)
at javax.swing.DefaultButtonM odel.fireA ctionPerfo rmed(Unkno wn Source)
at javax.swing.DefaultButtonM odel.setPr essed(Unkn own Source)
at javax.swing.plaf.basic.Bas icButtonLi stener.mou seReleased (Unknown Source)
at java.awt.Component.process MouseEvent (Unknown Source)
at javax.swing.JComponent.pro cessMouseE vent(Unkno wn Source)
at java.awt.Component.process Event(Unkn own Source)
at java.awt.Container.process Event(Unkn own Source)
at java.awt.Component.dispatc hEventImpl (Unknown Source)
at java.awt.Container.dispatc hEventImpl (Unknown Source)
at java.awt.Component.dispatc hEvent(Unk nown Source)
at java.awt.LightweightDispat cher.retar getMouseEv ent(Unknow n Source)
at java.awt.LightweightDispat cher.proce ssMouseEve nt(Unknown Source)
at java.awt.LightweightDispat cher.dispa tchEvent(U nknown Source)
at java.awt.Container.dispatc hEventImpl (Unknown Source)
at java.awt.Window.dispatchEv entImpl(Un known Source)
at java.awt.Component.dispatc hEvent(Unk nown Source)
at java.awt.EventQueue.dispat chEvent(Un known Source)
at java.awt.EventDispatchThre ad.pumpOne EventForFi lters(Unkn own Source)
at java.awt.EventDispatchThre ad.pumpEve ntsForFilt er(Unknown Source)
at java.awt.EventDispatchThre ad.pumpEve ntsForHier archy(Unkn own Source)
at java.awt.EventDispatchThre ad.pumpEve nts(Unknow n Source)
at java.awt.EventDispatchThre ad.pumpEve nts(Unknow n Source)
at java.awt.EventDispatchThre ad.run(Unk nown Source)
But when I do it again (In JFrame by pressing submit button again) its working fine.
What is the problem?
My code looks like
client.getHostConfiguratio n().setPro xy(proxyHo st,port);
if(userName!=null)
{
HttpState httpState = new HttpState();
httpState.setProxyCredenti als(new AuthScope(proxySettings.pr oxyHost,po rt),new NTCredentials(proxySetting s.userName ,proxySett ings.passw ord,proxyS ettings.pr oxyHost,pr oxySetting s.proxyDom ain));
filePost.setDoAuthenticati on(true);
client.setState(httpState) ;
}
else
{
filePost.setDoAuthenticati on(false);
}
client.getHttpConnectionMa nager().ge tParams(). setConnect ionTimeout (1000*60*6 0);
int status = client.executeMethod(fileP ost);
line no. 459(indicated in error trace) is last line --->>int status = client.executeMethod(fileP ost);
The first time it is giving an exception like this
java.net.SocketException: Connection reset
at java.net.SocketInputStream
at java.io.BufferedInputStrea
at java.io.BufferedInputStrea
at org.apache.commons.httpcli
at org.apache.commons.httpcli
at org.apache.commons.httpcli
at org.apache.commons.httpcli
at org.apache.commons.httpcli
at org.apache.commons.httpcli
at org.apache.commons.httpcli
at org.apache.commons.httpcli
at org.apache.commons.httpcli
at org.apache.commons.httpcli
at test.Test.actionPerformed(
at javax.swing.AbstractButton
at javax.swing.AbstractButton
at javax.swing.DefaultButtonM
at javax.swing.DefaultButtonM
at javax.swing.plaf.basic.Bas
at java.awt.Component.process
at javax.swing.JComponent.pro
at java.awt.Component.process
at java.awt.Container.process
at java.awt.Component.dispatc
at java.awt.Container.dispatc
at java.awt.Component.dispatc
at java.awt.LightweightDispat
at java.awt.LightweightDispat
at java.awt.LightweightDispat
at java.awt.Container.dispatc
at java.awt.Window.dispatchEv
at java.awt.Component.dispatc
at java.awt.EventQueue.dispat
at java.awt.EventDispatchThre
at java.awt.EventDispatchThre
at java.awt.EventDispatchThre
at java.awt.EventDispatchThre
at java.awt.EventDispatchThre
at java.awt.EventDispatchThre
But when I do it again (In JFrame by pressing submit button again) its working fine.
What is the problem?
My code looks like
client.getHostConfiguratio
if(userName!=null)
{
HttpState httpState = new HttpState();
httpState.setProxyCredenti
filePost.setDoAuthenticati
client.setState(httpState)
}
else
{
filePost.setDoAuthenticati
}
client.getHttpConnectionMa
int status = client.executeMethod(fileP
line no. 459(indicated in error trace) is last line --->>int status = client.executeMethod(fileP
the server is closing the connection for some reason, check the server logs.
It means that the server for some reason closes the connection while the client is still reading from the socket. If you've got access to the server logs, take a look in there to see if you find an indication about what is happening.
ASKER
I am using Apache Tomcat 6.0 app server.
There I have checked for these files
stdout.log
localhost.log
Catalina.log
stderr.log
and unable to find any traces of it.
There I have checked for these files
stdout.log
localhost.log
Catalina.log
stderr.log
and unable to find any traces of it.
check whatever you are using to recieve the upload
ASKER
Its a servlet for receiving file upload & the code looks like
ServletFileUpload upload = new ServletFileUpload();
FileItemIterator iter = upload.getItemIterator(req uest);
FileItemStream fi = iter.next();
fileName = fi.getName();
Streams.copy(fi.openStream (), new BufferedOutputStream(new FileOutputStream(new File("c:\\upload\\temp\\", fileName)),1024*1024*10), true, new byte[(1 << 20)*10]);
and there sre some lines for database connection to MySQL.
ServletFileUpload upload = new ServletFileUpload();
FileItemIterator iter = upload.getItemIterator(req
FileItemStream fi = iter.next();
fileName = fi.getName();
Streams.copy(fi.openStream
and there sre some lines for database connection to MySQL.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Well in that case it should not work for the second time also.
The servlet may see a new request. You need to make the alteration in case you need to avoid a null pointer exception too
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.