Normally, running this code in a servlet environment shouldn't make a
difference.
There are 2 things you can do:
- check the file length after the close (temp_file.length())
- do a client.setDebug() before excutemethod
If this doesn't give an answer please send a complete servlet example that
gives the error.
Dirk
Miguel Carvalho wrote:
> I'm tring to put a file in a webdav folder in my project. For experience
> I read a file from disk. If I do it in a single project, in a test
> class, everithing goes well.
> But I wan't to do do it in a Servlet environment. Using ServletServer
> that comes with jBuilder with the same exact code I get an exception.
> I've tried also with Jrun, TomCat and the same happens.
>
> Code and Exception fallows:
>
> InputStream input_stream = new FileInputStream(path+"/"+name);
>
> ...
>
> File temp_file = new File(temp_files_path, filename);
> BufferedReader in = new BufferedReader(new
> InputStreamReader(input_stream));
>
> PrintWriter out = new PrintWriter(new BufferedWriter(new
> FileWriter(temp_file)));
> while (in.ready())
> out.write(in.read());
> in.close();
> out.flush();
> out.close();
> try {
> method.sendData(temp_file);
> client.executeMethod(method);
> temp_file.delete();
> }
> catch(Exception ex){ex.printStackTrace();}
> }
>
> This works fine standalone. But in servlet environment I get:
>
> java.net.SocketException: Connection aborted by peer: socket write error
> at java.net.SocketOutputStream.socketWrite(Native Method)
> at java.net.SocketOutputStream.write(SocketOutputStream.java:83)
> at
> org.apache.commons.httpclient.RequestOutputStream.write(RequestOutputStr
> eam.java:281)
> at
> org.apache.commons.httpclient.methods.PutMethod.streamQuery(PutMethod.ja
> va:255)
> at
> org.apache.commons.httpclient.HttpClient.sendRequestBody(HttpClient.java
> :1012)
> at
> org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:5
> 07)
> ...
>
> I'm using Jakarta-Slide1.0.14 release in JDK1.3. . I've tried with
> Crimson.jar+jaxp.jar, and with Xerces.
>
> Please help me, it's the only problem I have now. My project it's
> finished and I need to solve this so I can graduate.
>
> THANKS IN ADVANCE,
>
> Regards
>
> Maik
>
> ----------------------------------------------------------
> Miguel Carvalho
> ----------------------------------------------------------
> Infopulse Portugal
> Pra�a dos Poveiros 56 2� Salas 4-8
> 4000 393 Porto
> Portugal
> Tel:+351 22 3389103
> Fax:+351 22 3389104
> http://www.infopulse.pt
> ----------------------------------------------------------
> The Netherlands: http://www.infopulse.nl
> Romania: http://www.infopulse.ro
> ----------------------------------------------------------
> icq: 48259534
> odigo: 1464770
> yahoo_id : maik_pt
> ----------------------------------------------------------
>
> ----------------------------------------------------------
> Miguel Carvalho
> ----------------------------------------------------------
> Infopulse Portugal
> Pra�a dos Poveiros 56 2� Salas 4-8
> 4000 393 Porto
> Portugal
> Tel:+351 22 3389103
> Fax:+351 22 3389104
> http://www.infopulse.pt
> ----------------------------------------------------------
> The Netherlands: http://www.infopulse.nl
> Romania: http://www.infopulse.ro
> ----------------------------------------------------------
> icq: 48259534
> odigo: 1464770
> yahoo_id : maik_pt
> ----------------------------------------------------------