提交 19f3b29f 编写于 作者: R Ryan Campbell

Correctly support direct updates of html update sites and other issues pointed...

Correctly support direct updates of html update sites and other issues pointed out by jglick in https://github.com/jenkinsci/jenkins/pull/692
上级 c1c97974
......@@ -122,6 +122,7 @@ public class UpdateCenter extends AbstractModelObject implements Saveable, OnMas
/**
* {@link ExecutorService} that performs installation.
* @since 1.501
*/
private final ExecutorService installerService = Executors.newSingleThreadExecutor(
new DaemonThreadFactory(new ThreadFactory() {
......
......@@ -42,15 +42,14 @@ import net.sf.json.JSONException;
import net.sf.json.JSONObject;
import org.kohsuke.stapler.DataBoundConstructor;
import org.kohsuke.stapler.HttpResponse;
import org.kohsuke.stapler.Stapler;
import org.kohsuke.stapler.StaplerRequest;
import org.kohsuke.stapler.export.Exported;
import org.kohsuke.stapler.export.ExportedBean;
import org.kohsuke.stapler.interceptor.RequirePOST;
import java.io.BufferedInputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
import java.net.URL;
import java.net.URLConnection;
......@@ -164,15 +163,16 @@ public class UpdateSite {
public FormValidation call() throws Exception {
URL src = new URL(getUrl());
URLConnection conn = ProxyConfiguration.open(src);
BufferedInputStream is = new BufferedInputStream(conn.getInputStream());
InputStream is = conn.getInputStream();
try {
// remove non-json characters from update center
is.mark(1);
for (int r = is.read(); r > 0 && (char)r != '{'; r = is.read()) {
is.mark(1);
String uncleanJson = IOUtils.toString(is,"UTF-8");
int jsonStart = uncleanJson.indexOf("{\"");
if (jsonStart >= 0) {
return updateData(uncleanJson.substring(jsonStart));
} else {
throw new IOException("Could not find json in content of " +
"update center from url: "+src.toExternalForm());
}
is.reset();
return updateData(is);
} finally {
if (is != null)
is.close();
......@@ -187,16 +187,14 @@ public class UpdateSite {
* This is the endpoint that receives the update center data file from the browser.
*/
public FormValidation doPostBack(StaplerRequest req) throws IOException, GeneralSecurityException {
dataTimestamp = System.currentTimeMillis();
return updateData(req.getInputStream());
return updateData(IOUtils.toString(req.getInputStream(),"UTF-8"));
}
private FormValidation updateData(java.io.InputStream is)
private FormValidation updateData(String json)
throws IOException {
dataTimestamp = System.currentTimeMillis();
String json = IOUtils.toString(is,"UTF-8");
JSONObject o = JSONObject.fromObject(json);
int v = o.getInt("updateCenterVersion");
......@@ -205,8 +203,8 @@ public class UpdateSite {
if (signatureCheck) {
FormValidation e = verifySignature(o);
if (e.kind!=Kind.OK && Stapler.getCurrentRequest() != null) {
LOGGER.severe(e.renderHtml());
if (e.kind!=Kind.OK) {
LOGGER.severe(e.getMessage());
return e;
}
}
......
......@@ -74,7 +74,7 @@ public class UpdateSiteTest {
}
@Test public void updateDirectlyWithHtml() throws Exception {
UpdateSite us = new UpdateSite("default", UpdateSiteTest.class.getResource("update-center.json").toExternalForm());
UpdateSite us = new UpdateSite("default", UpdateSiteTest.class.getResource("update-center.json.html").toExternalForm());
assertNull(us.getPlugin("AdaptivePlugin"));
FormValidation result = us.updateDirectly().get();
assertTrue(result.equals(FormValidation.ok()));
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册