提交 691f2305 编写于 作者: K Kohsuke Kawaguchi

Merge branch 'JENKINS-8660'

* JENKINS-8660:
  fail more gracefully if the header is not provided.
  JENKINS-8660: loading the build history cause an NPE on the History Widget
......@@ -27,16 +27,20 @@ import hudson.Functions;
import hudson.model.ModelObject;
import hudson.model.Run;
import org.kohsuke.stapler.Header;
import org.kohsuke.stapler.HttpResponses;
import org.kohsuke.stapler.Stapler;
import org.kohsuke.stapler.StaplerRequest;
import org.kohsuke.stapler.StaplerResponse;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import static javax.servlet.http.HttpServletResponse.SC_BAD_REQUEST;
/**
* Displays the history of records (normally {@link Run}s) on the side panel.
*
......@@ -151,6 +155,8 @@ public class HistoryWidget<O extends ModelObject,T> extends Widget {
public void doAjax( StaplerRequest req, StaplerResponse rsp,
@Header("n") String n ) throws IOException, ServletException {
if (n==null) throw HttpResponses.error(SC_BAD_REQUEST,new Exception("Missing the 'n' HTTP header"));
rsp.setContentType("text/html;charset=UTF-8");
// pick up builds to send back
......
......@@ -48,6 +48,13 @@ THE SOFTWARE.
<tr class="build-row">
<td colspan="3" align="right">
<script>
function replace(a, b) {
var p = a.parentNode;
var next = a.nextSibling;
p.removeChild(a);
p.insertBefore(b,next);
}
function loadAllBuildHistory() {
// first display the "loading..." icon
var box = $("loadAllBuildHistory");
......@@ -59,14 +66,12 @@ THE SOFTWARE.
onComplete: function(rsp,_) {
<!-- neither outerHTML nor responseXML works in Firefox 2.0 -->
var hist = $$("buildHistory");
var p = hist.parentNode;
var next = hist.nextSibling;
p.removeChild(hist);
var div = document.createElement('div');
div.innerHTML = rsp.responseText;
var newhist = document.createElement('div');
newhist.innerHTML = rsp.responseText;
newhist.headers = hist.headers
p.insertBefore(div,next);
replace(hist, newhist);
}
});
}
......
......@@ -1472,6 +1472,9 @@ function updateBuildHistory(ajaxUrl,nBuild) {
function updateBuilds() {
var bh = $('buildHistory');
if (bh.headers == null) {
// Yahoo.log("Missing headers in buildHistory element");
}
new Ajax.Request(ajaxUrl, {
requestHeaders: bh.headers,
onSuccess: function(rsp) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册