Check HTTP status when downloading a release, and report eventual error.

pull/97/head
luccioman 8 years ago
parent 8e2cef5f07
commit 00e81fcc15

@ -30,6 +30,9 @@
</select> </select>
&nbsp;&nbsp;<input type="submit" name="downloadRelease" class="btn btn-primary" value="Download Release"/> &nbsp;&nbsp;<input type="submit" name="downloadRelease" class="btn btn-primary" value="Download Release"/>
&nbsp;&nbsp;<input type="submit" name="checkRelease" class="btn btn-default" value="Check for new Release"/> &nbsp;&nbsp;<input type="submit" name="checkRelease" class="btn btn-default" value="Check for new Release"/>
#(downloadError)#::
<div class="error">Download of release #[releasedownload]# failed.</div>
#(/downloadError)#
</p></form></dd> </p></form></dd>
<dt><br />Downloaded Releases</dt> <dt><br />Downloaded Releases</dt>
<dd><form action="ConfigUpdate_p.html" method="get" accept-charset="UTF-8"><p> <dd><form action="ConfigUpdate_p.html" method="get" accept-charset="UTF-8"><p>

@ -70,6 +70,7 @@ public class ConfigUpdate_p {
prop.put("candeploy_configCommit", "0"); prop.put("candeploy_configCommit", "0");
prop.put("candeploy_autoUpdate", "0"); prop.put("candeploy_autoUpdate", "0");
prop.put("candeploy_downloadsAvailable", "0"); prop.put("candeploy_downloadsAvailable", "0");
prop.put("candeploy_downloadError", "0");
if (post != null) { if (post != null) {
// check if update is supposed to be installed and a release is defined // check if update is supposed to be installed and a release is defined
@ -86,21 +87,26 @@ public class ConfigUpdate_p {
final String release = post.get("releasedownload", ""); final String release = post.get("releasedownload", "");
if (!release.isEmpty()) { if (!release.isEmpty()) {
try { try {
yacyRelease versionToDownload = new yacyRelease(new DigestURL(release)); yacyRelease versionToDownload = new yacyRelease(new DigestURL(release));
// replace this version with version which contains public key // replace this version with version which contains public key
final yacyRelease.DevAndMainVersions allReleases = yacyRelease.allReleases(false, false); final yacyRelease.DevAndMainVersions allReleases = yacyRelease.allReleases(false, false);
final Set<yacyRelease> mostReleases = versionToDownload.isMainRelease() ? allReleases.main : allReleases.dev; final Set<yacyRelease> mostReleases = versionToDownload.isMainRelease() ? allReleases.main : allReleases.dev;
for (final yacyRelease rel : mostReleases) { for (final yacyRelease rel : mostReleases) {
if (rel.equals(versionToDownload)) { if (rel.equals(versionToDownload)) {
versionToDownload = rel; versionToDownload = rel;
break; break;
} }
} }
versionToDownload.downloadRelease(); File downloadedRelease = versionToDownload.downloadRelease();
if(downloadedRelease == null) {
prop.put("candeploy_downloadError", "1");
prop.putHTML("candeploy_downloadError_releasedownload", release);
}
} catch (final IOException e) { } catch (final IOException e) {
// TODO Auto-generated catch block ConcurrentLog.logException(e);
ConcurrentLog.logException(e); prop.put("candeploy_downloadError", "1");
prop.putHTML("candeploy_downloadError_releasedownload", release);
} }
} }
} }

@ -44,6 +44,8 @@ import java.util.SortedSet;
import java.util.TreeSet; import java.util.TreeSet;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import org.apache.http.HttpStatus;
import net.yacy.cora.document.encoding.UTF8; import net.yacy.cora.document.encoding.UTF8;
import net.yacy.cora.document.id.AnchorURL; import net.yacy.cora.document.id.AnchorURL;
import net.yacy.cora.document.id.DigestURL; import net.yacy.cora.document.id.DigestURL;
@ -304,6 +306,10 @@ public final class yacyRelease extends yacyVersion {
client.setTimout(120000); client.setTimout(120000);
client.GET(getUrl().toString(), false); client.GET(getUrl().toString(), false);
int statusCode = client.getHttpResponse().getStatusLine().getStatusCode(); int statusCode = client.getHttpResponse().getStatusLine().getStatusCode();
if(statusCode != HttpStatus.SC_OK) {
/* HTTP status is not OK (200) : let's stop here to avoid creating a invalid download file*/
throw new IOException("HTTP response status code : " + statusCode);
}
final ResponseHeader header = new ResponseHeader(statusCode, client.getHttpResponse().getAllHeaders()); final ResponseHeader header = new ResponseHeader(statusCode, client.getHttpResponse().getAllHeaders());
final boolean unzipped = header.gzip() && (header.mime().toLowerCase().equals("application/x-tar")); // if true, then the httpc has unzipped the file final boolean unzipped = header.gzip() && (header.mime().toLowerCase().equals("application/x-tar")); // if true, then the httpc has unzipped the file

Loading…
Cancel
Save