]> git.basschouten.com Git - openhab-addons.git/commitdiff
[volvooncall] Adjust thread name for HTTP client (#14469)
authorlolodomo <lg.hc@free.fr>
Mon, 20 Feb 2023 20:47:46 +0000 (21:47 +0100)
committerGitHub <noreply@github.com>
Mon, 20 Feb 2023 20:47:46 +0000 (21:47 +0100)
Signed-off-by: Laurent Garnier <lg.hc@free.fr>
bundles/org.openhab.binding.volvooncall/src/main/java/org/openhab/binding/volvooncall/internal/VolvoOnCallHandlerFactory.java
bundles/org.openhab.binding.volvooncall/src/main/java/org/openhab/binding/volvooncall/internal/api/VocHttpApi.java
bundles/org.openhab.binding.volvooncall/src/main/java/org/openhab/binding/volvooncall/internal/handler/VolvoOnCallBridgeHandler.java

index 4d79c6661cffe86045760a729336f415f41d1667..a7cf6af52a6c4865e8c5056d833f0e8be599fc66 100644 (file)
@@ -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<ZonedDateTime>) (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);
         }
index e960bfc58d688af1ba7fd37a848eb4ee01c38ed5..f0f9d99b87c767362cecb9f0e219236084747ea1 100644 (file)
@@ -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 {
index 713fbbe6f67c52fd60c0f81db2551c832cb60e8a..a255302b53e69fc7b799f2b83e998606a1dd65ad 100644 (file)
@@ -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);