From 8c56a0f0b396f77c2b7543e09803d679a9e2aacf Mon Sep 17 00:00:00 2001 From: lolodomo Date: Mon, 20 Feb 2023 21:47:46 +0100 Subject: [PATCH] [volvooncall] Adjust thread name for HTTP client (#14469) Signed-off-by: Laurent Garnier --- .../internal/VolvoOnCallHandlerFactory.java | 7 +++---- .../binding/volvooncall/internal/api/VocHttpApi.java | 7 ++++--- .../internal/handler/VolvoOnCallBridgeHandler.java | 12 +++++++----- 3 files changed, 14 insertions(+), 12 deletions(-) diff --git a/bundles/org.openhab.binding.volvooncall/src/main/java/org/openhab/binding/volvooncall/internal/VolvoOnCallHandlerFactory.java b/bundles/org.openhab.binding.volvooncall/src/main/java/org/openhab/binding/volvooncall/internal/VolvoOnCallHandlerFactory.java index 4d79c6661cf..a7cf6af52a6 100644 --- a/bundles/org.openhab.binding.volvooncall/src/main/java/org/openhab/binding/volvooncall/internal/VolvoOnCallHandlerFactory.java +++ b/bundles/org.openhab.binding.volvooncall/src/main/java/org/openhab/binding/volvooncall/internal/VolvoOnCallHandlerFactory.java @@ -18,7 +18,6 @@ import java.time.ZonedDateTime; import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.Nullable; -import org.eclipse.jetty.client.HttpClient; import org.openhab.binding.volvooncall.internal.handler.VehicleHandler; import org.openhab.binding.volvooncall.internal.handler.VehicleStateDescriptionProvider; import org.openhab.binding.volvooncall.internal.handler.VolvoOnCallBridgeHandler; @@ -55,13 +54,13 @@ public class VolvoOnCallHandlerFactory extends BaseThingHandlerFactory { private final Logger logger = LoggerFactory.getLogger(VolvoOnCallHandlerFactory.class); private final VehicleStateDescriptionProvider stateDescriptionProvider; private final Gson gson; - private final HttpClient httpClient; + private final HttpClientFactory httpClientFactory; @Activate public VolvoOnCallHandlerFactory(@Reference VehicleStateDescriptionProvider provider, @Reference HttpClientFactory httpClientFactory) { this.stateDescriptionProvider = provider; - this.httpClient = httpClientFactory.createHttpClient(BINDING_ID); + this.httpClientFactory = httpClientFactory; this.gson = new GsonBuilder() .registerTypeAdapter(ZonedDateTime.class, (JsonDeserializer) (json, type, jsonDeserializationContext) -> ZonedDateTime @@ -87,7 +86,7 @@ public class VolvoOnCallHandlerFactory extends BaseThingHandlerFactory { protected @Nullable ThingHandler createHandler(Thing thing) { ThingTypeUID thingTypeUID = thing.getThingTypeUID(); if (APIBRIDGE_THING_TYPE.equals(thingTypeUID)) { - return new VolvoOnCallBridgeHandler((Bridge) thing, gson, httpClient); + return new VolvoOnCallBridgeHandler((Bridge) thing, gson, httpClientFactory); } else if (VEHICLE_THING_TYPE.equals(thingTypeUID)) { return new VehicleHandler(thing, stateDescriptionProvider); } diff --git a/bundles/org.openhab.binding.volvooncall/src/main/java/org/openhab/binding/volvooncall/internal/api/VocHttpApi.java b/bundles/org.openhab.binding.volvooncall/src/main/java/org/openhab/binding/volvooncall/internal/api/VocHttpApi.java index e960bfc58d6..f0f9d99b87c 100644 --- a/bundles/org.openhab.binding.volvooncall/src/main/java/org/openhab/binding/volvooncall/internal/api/VocHttpApi.java +++ b/bundles/org.openhab.binding.volvooncall/src/main/java/org/openhab/binding/volvooncall/internal/api/VocHttpApi.java @@ -36,6 +36,7 @@ import org.openhab.binding.volvooncall.internal.dto.PostResponse; import org.openhab.binding.volvooncall.internal.dto.VocAnswer; import org.openhab.core.cache.ExpiringCacheMap; import org.openhab.core.id.InstanceUUID; +import org.openhab.core.io.net.http.HttpClientFactory; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -61,12 +62,12 @@ public class VocHttpApi { private final HttpClient httpClient; private final ApiBridgeConfiguration configuration; - public VocHttpApi(ApiBridgeConfiguration configuration, Gson gson, HttpClient httpClient) - throws VolvoOnCallException { + public VocHttpApi(String clientName, ApiBridgeConfiguration configuration, Gson gson, + HttpClientFactory httpClientFactory) throws VolvoOnCallException { this.gson = gson; this.cache = new ExpiringCacheMap<>(120 * 1000); this.configuration = configuration; - this.httpClient = httpClient; + this.httpClient = httpClientFactory.createHttpClient(clientName); httpClient.setUserAgentField(new HttpField(HttpHeader.USER_AGENT, "openhab/voc_binding/" + InstanceUUID.get())); try { diff --git a/bundles/org.openhab.binding.volvooncall/src/main/java/org/openhab/binding/volvooncall/internal/handler/VolvoOnCallBridgeHandler.java b/bundles/org.openhab.binding.volvooncall/src/main/java/org/openhab/binding/volvooncall/internal/handler/VolvoOnCallBridgeHandler.java index 713fbbe6f67..a255302b53e 100644 --- a/bundles/org.openhab.binding.volvooncall/src/main/java/org/openhab/binding/volvooncall/internal/handler/VolvoOnCallBridgeHandler.java +++ b/bundles/org.openhab.binding.volvooncall/src/main/java/org/openhab/binding/volvooncall/internal/handler/VolvoOnCallBridgeHandler.java @@ -17,18 +17,19 @@ import java.util.Collections; import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.Nullable; -import org.eclipse.jetty.client.HttpClient; import org.openhab.binding.volvooncall.internal.VolvoOnCallException; import org.openhab.binding.volvooncall.internal.api.VocHttpApi; import org.openhab.binding.volvooncall.internal.config.ApiBridgeConfiguration; import org.openhab.binding.volvooncall.internal.discovery.VolvoVehicleDiscoveryService; import org.openhab.binding.volvooncall.internal.dto.CustomerAccounts; +import org.openhab.core.io.net.http.HttpClientFactory; import org.openhab.core.thing.Bridge; import org.openhab.core.thing.ChannelUID; import org.openhab.core.thing.ThingStatus; import org.openhab.core.thing.ThingStatusDetail; import org.openhab.core.thing.binding.BaseBridgeHandler; import org.openhab.core.thing.binding.ThingHandlerService; +import org.openhab.core.thing.util.ThingWebClientUtil; import org.openhab.core.types.Command; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -46,14 +47,14 @@ public class VolvoOnCallBridgeHandler extends BaseBridgeHandler { private final Logger logger = LoggerFactory.getLogger(VolvoOnCallBridgeHandler.class); private final Gson gson; - private final HttpClient httpClient; + private final HttpClientFactory httpClientFactory; private @Nullable VocHttpApi api; - public VolvoOnCallBridgeHandler(Bridge bridge, Gson gson, HttpClient httpClient) { + public VolvoOnCallBridgeHandler(Bridge bridge, Gson gson, HttpClientFactory httpClientFactory) { super(bridge); this.gson = gson; - this.httpClient = httpClient; + this.httpClientFactory = httpClientFactory; } @Override @@ -62,7 +63,8 @@ public class VolvoOnCallBridgeHandler extends BaseBridgeHandler { ApiBridgeConfiguration configuration = getConfigAs(ApiBridgeConfiguration.class); try { - VocHttpApi vocApi = new VocHttpApi(configuration, gson, httpClient); + String clientName = ThingWebClientUtil.buildWebClientConsumerName(thing.getUID(), null); + VocHttpApi vocApi = new VocHttpApi(clientName, configuration, gson, httpClientFactory); CustomerAccounts account = vocApi.getURL("customeraccounts/", CustomerAccounts.class); if (account.username != null) { updateStatus(ThingStatus.ONLINE, ThingStatusDetail.NONE, account.username);