提交 0e244a69 编写于 作者: K kohsuke

write to a file first and used the fixed content-length mode to avoid buffering.


git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@7102 71c3de6d-444a-0410-be80-ed276b4c234a
上级 b40d0cad
......@@ -3,9 +3,12 @@ package hudson;
import hudson.util.DualOutputStream;
import hudson.util.EncodingStream;
import java.io.OutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.OutputStreamWriter;
import java.io.Writer;
import java.net.HttpRetryException;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLEncoder;
......@@ -74,11 +77,11 @@ public class Main {
}
}
// start a remote connection
HttpURLConnection con = (HttpURLConnection) new URL(home+"job/"+projectNameEnc+"/postBuildResult").openConnection();
con.setDoOutput(true);
con.connect();
OutputStream os = con.getOutputStream();
// write the output to a temporary file first.
File tmpFile = File.createTempFile("hudson","log");
tmpFile.deleteOnExit();
FileOutputStream os = new FileOutputStream(tmpFile);
Writer w = new OutputStreamWriter(os,"UTF-8");
w.write("<?xml version='1.0' encoding='UTF-8'?>");
w.write("<run><log encoding='hexBinary'>");
......@@ -98,10 +101,34 @@ public class Main {
w.write("</log><result>"+ret+"</result><duration>"+(System.currentTimeMillis()-start)+"</duration></run>");
w.close();
if(con.getResponseCode()!=200) {
Util.copyStream(con.getErrorStream(),System.err);
String location = home+"job/"+projectNameEnc+"/postBuildResult";
while(true) {
try {
// start a remote connection
HttpURLConnection con = (HttpURLConnection) new URL(location).openConnection();
con.setDoOutput(true);
// this tells HttpURLConnection not to buffer the whole thing
con.setFixedLengthStreamingMode((int)tmpFile.length());
con.connect();
// send the data
FileInputStream in = new FileInputStream(tmpFile);
Util.copyStream(in,con.getOutputStream());
in.close();
if(con.getResponseCode()!=200) {
Util.copyStream(con.getErrorStream(),System.err);
}
return ret;
} catch (HttpRetryException e) {
if(e.getLocation()!=null) {
// retry with the new location
location = e.getLocation();
continue;
}
// otherwise failed for reasons beyond us.
throw e;
}
}
return ret;
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册