Set explicit timeout for http request (#15505)

* Bondhome
* chatgpt
* electroluxair
* energidataservice
* freeboxos
* gardena
* generacmobilelink
* hdpowerview
* icalendar
* juicenet
* kostalinverter
* liquidcheck
* mcd
* meater
* miele
* mercedesme
* mybmw
* myq
* ojelectronics
* plex
* radiothermostat
* renault
* semsportal
* sensibo
* tapocontrol
* tellstick
* verisure
* vizio

---------

Signed-off-by: lsiepel <leosiepel@gmail.com>
Signed-off-by: Leo Siepel <leosiepel@gmail.com>
This commit is contained in:
lsiepel
2023-10-19 22:30:41 +02:00
committed by GitHub
parent c7568cb206
commit 7313415ae0
32 changed files with 135 additions and 48 deletions

View File

@@ -17,6 +17,7 @@ import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Base64;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import org.eclipse.jdt.annotation.NonNullByDefault;
@@ -42,6 +43,8 @@ import com.google.gson.JsonParser;
@NonNullByDefault
public class SecondGenerationConfigurationHandler {
private static final int REQUEST_TIMEOUT_MS = 5000;
public static void executeConfigurationChanges(HttpClient httpClient, String url, String username, String password,
String dxsId, String value)
throws InterruptedException, ExecutionException, TimeoutException, NoSuchAlgorithmException {
@@ -75,7 +78,8 @@ public class SecondGenerationConfigurationHandler {
String loginPostJsonData = "{\"mode\":1,\"userId\":\"" + username + "\",\"pwh\":\"" + saltedmDigestedPwd
+ "\"}";
Request loginPostJsonResponse = httpClient.POST(urlLogin + "?sessionId=" + sessionId);
Request loginPostJsonResponse = httpClient.POST(urlLogin + "?sessionId=" + sessionId)
.timeout(REQUEST_TIMEOUT_MS, TimeUnit.MILLISECONDS);
loginPostJsonResponse.header(HttpHeader.CONTENT_TYPE, "application/json");
loginPostJsonResponse.content(new StringContentProvider(loginPostJsonData));
ContentResponse loginPostJsonDataContentResponse = loginPostJsonResponse.send();
@@ -91,7 +95,8 @@ public class SecondGenerationConfigurationHandler {
// Part for sending data to Inverter
String postJsonData = "{\"dxsEntries\":[{\"dxsId\":" + dxsId + ",\"value\":" + value + "}]}";
Request postJsonDataRequest = httpClient.POST(url + "/api/dxs.json?sessionId=" + sessionId);
Request postJsonDataRequest = httpClient.POST(url + "/api/dxs.json?sessionId=" + sessionId)
.timeout(REQUEST_TIMEOUT_MS, TimeUnit.MILLISECONDS);
postJsonDataRequest.header(HttpHeader.CONTENT_TYPE, "application/json");
postJsonDataRequest.content(new StringContentProvider(postJsonData));
postJsonDataRequest.send();