HttpURLConnection - file sent twice without asking for
I'm writing a client app, and I use the class java.net.HttpURLConnection to connect to a server (servlet) to send and retreive XML messages.
It works fine on my test box (Linux with Jarkarta tomcat and my perso servlet code to copy the file on the server) on the intranet.
The problem happens when I send this file/message on a server on the internet (port 80).
It seems when the server take too much time (2 mins), my client app resends the XML message again. Then I receive an error message from the server saying I've sent the message twice !
I sniffed my connection, and it looks like my client on the firts sending receives some response after a while (2 mins), then it changes the client port and resends the message again.
Is there someone to explain me that ?
Here is my connection code :
try
{
URL url = new URL(urlstring);
URLConnection conn = url.openConnection();
if (conn==null)
throw new IOException("Can't connect to "+urlstring);
if ( conn instanceof HttpURLConnection)
httpcon = (HttpURLConnection)conn;
else
throw new IOException("http Connection to "+urlstring+" failed:");
httpcon.setRequestProperty("Content-Type", "text/plain" );
httpcon.setDoOutput(true);
httpcon.setDoInput(true);
httpcon.setUseCaches (false);
httpcon.setDefaultUseCaches(false);
}
catch (MalformedURLException e)
{
throw new IOException(e.getMessage());
}
The method I use to write to the server (nothing original) :
httpcon.setRequestMethod("POST");
outputStream = httpcon.getOutputStream();
...
BufferedInputStream in = new BufferedInputStream(inputStream);
OutputStream out = getOutputStream();
byte buff[] = new byte[512];
int len;
try {
while ( (len = in.read(buff, 0, buff.length)) >= 0) {
out.write(buff, 0, len);
}
} catch (java.io.EOFException e) {//REVIEW !!
throw e;
}
Thanks for your help.

