Fix: check if the server is down
This commit is contained in:
@@ -219,7 +219,7 @@ public class Server extends Thread {
|
||||
|
||||
this.log.debug("Server::getConfiguration url " + remoteURL.build().toString());
|
||||
|
||||
Response response = this.HTTPRequest(remoteURL, formBody);
|
||||
Response response = this.HTTPRequest(remoteURL, formBody, false);
|
||||
int r = response.code();
|
||||
String contentType = response.body().contentType().toString();
|
||||
|
||||
@@ -239,6 +239,10 @@ public class Server extends Thread {
|
||||
this.user_config.setPassword(publickey);
|
||||
}
|
||||
}
|
||||
else if (r == HttpURLConnection.HTTP_NOT_FOUND) {
|
||||
// most likely the server instance is down but not the frontend proxy (traefik)
|
||||
return Error.Type.SERVER_DOWN;
|
||||
}
|
||||
}
|
||||
catch (ConnectException e) {
|
||||
this.log.error("Server::getConfiguration error ConnectException " + e);
|
||||
@@ -451,6 +455,34 @@ public class Server extends Thread {
|
||||
}
|
||||
}
|
||||
|
||||
public Response HTTPRequest(HttpUrl.Builder httpUrlBuilder, RequestBody data_, boolean checkIsSuccessful) throws IOException {
|
||||
String url = httpUrlBuilder.build().toString();
|
||||
Request.Builder builder = new Request.Builder().addHeader("User-Agent", HTTP_USER_AGENT).url(url);
|
||||
|
||||
this.log.debug("Server::HTTPRequest url(" + url + ")");
|
||||
|
||||
if (data_ != null) {
|
||||
builder.post(data_);
|
||||
}
|
||||
|
||||
Request request = builder.build();
|
||||
Response response = null;
|
||||
|
||||
try {
|
||||
response = httpClient.newCall(request).execute();
|
||||
|
||||
if (checkIsSuccessful && !response.isSuccessful()) {
|
||||
throw new IOException("Unexpected code " + response);
|
||||
}
|
||||
|
||||
this.lastRequestTime = new Date().getTime();
|
||||
return response;
|
||||
}
|
||||
catch (IOException e) {
|
||||
throw new IOException("Unexpected response from HTTP Stack" + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public Error.Type HTTPGetFile(String url_, String destination_, Gui gui_, String status_) throws FermeException {
|
||||
InputStream is = null;
|
||||
OutputStream output = null;
|
||||
|
||||
Reference in New Issue
Block a user