Handle when server doesn't send the expected response

This commit is contained in:
Laurent Clouet
2016-09-11 13:46:12 +02:00
parent 0d660b023b
commit 018382ac6f
4 changed files with 39 additions and 0 deletions

View File

@@ -75,6 +75,7 @@ import org.xml.sax.SAXException;
import com.sheepit.client.Configuration.ComputeType;
import com.sheepit.client.Error.ServerCode;
import com.sheepit.client.exception.FermeException;
import com.sheepit.client.exception.FermeExceptionBadResponseFromServer;
import com.sheepit.client.exception.FermeExceptionNoRightToRender;
import com.sheepit.client.exception.FermeExceptionNoSession;
import com.sheepit.client.exception.FermeExceptionNoSpaceLeftOnDevice;
@@ -254,6 +255,9 @@ public class Server extends Thread implements HostnameVerifier, X509TrustManager
}
}
}
else if (r == HttpURLConnection.HTTP_OK && contentType.startsWith("text/html")) {
return Error.Type.ERROR_BAD_RESPONSE;
}
else {
this.log.error("Server::getConfiguration: Invalid response " + contentType + " " + r);
return Error.Type.WRONG_CONFIGURATION;
@@ -443,6 +447,9 @@ public class Server extends Thread implements HostnameVerifier, X509TrustManager
// most likely varnish is up but apache down
throw new FermeServerDown();
}
else if (r == HttpURLConnection.HTTP_OK && contentType.startsWith("text/html")) {
throw new FermeExceptionBadResponseFromServer();
}
InputStream in = connection.getInputStream();
String line;
BufferedReader reader = new BufferedReader(new InputStreamReader(in, "UTF-8"));
@@ -732,6 +739,9 @@ public class Server extends Thread implements HostnameVerifier, X509TrustManager
}
return ServerCode.OK;
}
else if (r == HttpURLConnection.HTTP_OK && contentType.startsWith("text/html")) {
return ServerCode.ERROR_BAD_RESPONSE;
}
else {
try {
inStream = new BufferedReader(new InputStreamReader(conn.getInputStream()));