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:
@@ -16,6 +16,7 @@ import java.nio.charset.StandardCharsets;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ScheduledFuture;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import javax.ws.rs.core.MediaType;
|
||||
|
||||
@@ -69,6 +70,7 @@ public class PortalHandler extends BaseBridgeHandler {
|
||||
private static final String LIST_URL = BASE_URL + "api/PowerStationMonitor/QueryPowerStationMonitorForApp";
|
||||
// the token holds the credential information for the portal
|
||||
private static final String HTTP_HEADER_TOKEN = "Token";
|
||||
private static final int REQUEST_TIMEOUT_MS = 10_000;
|
||||
|
||||
// used to parse json from / to the SEMS portal API
|
||||
private final Gson gson;
|
||||
@@ -147,7 +149,8 @@ public class PortalHandler extends BaseBridgeHandler {
|
||||
|
||||
private @Nullable String sendPost(String url, String payload) {
|
||||
try {
|
||||
Request request = httpClient.POST(url).header(HttpHeader.CONTENT_TYPE, MediaType.APPLICATION_JSON)
|
||||
Request request = httpClient.POST(url).timeout(REQUEST_TIMEOUT_MS, TimeUnit.MILLISECONDS)
|
||||
.header(HttpHeader.CONTENT_TYPE, MediaType.APPLICATION_JSON)
|
||||
.header(HTTP_HEADER_TOKEN, gson.toJson(sessionToken))
|
||||
.content(new StringContentProvider(payload, StandardCharsets.UTF_8.name()),
|
||||
MediaType.APPLICATION_JSON);
|
||||
|
||||
Reference in New Issue
Block a user