]> git.basschouten.com Git - openhab-addons.git/commitdiff
[linky] Call createHttpClient with a SslContextFactory parameter (#14464)
authorlolodomo <lg.hc@free.fr>
Mon, 20 Feb 2023 19:32:09 +0000 (20:32 +0100)
committerGitHub <noreply@github.com>
Mon, 20 Feb 2023 19:32:09 +0000 (20:32 +0100)
Signed-off-by: Laurent Garnier <lg.hc@free.fr>
bundles/org.openhab.binding.linky/src/main/java/org/openhab/binding/linky/internal/LinkyHandlerFactory.java

index 2da48f935377458fc85222c7062f0d96053ebb4c..5ceaeb7b34aac9014b7a74fcdfe03bb4f2b01f06 100644 (file)
@@ -25,6 +25,7 @@ import javax.net.ssl.TrustManager;
 import org.eclipse.jdt.annotation.NonNullByDefault;
 import org.eclipse.jdt.annotation.Nullable;
 import org.eclipse.jetty.client.HttpClient;
+import org.eclipse.jetty.util.ssl.SslContextFactory;
 import org.openhab.binding.linky.internal.handler.LinkyHandler;
 import org.openhab.core.i18n.LocaleProvider;
 import org.openhab.core.io.net.http.HttpClientFactory;
@@ -68,25 +69,27 @@ public class LinkyHandlerFactory extends BaseThingHandlerFactory {
     public LinkyHandlerFactory(final @Reference LocaleProvider localeProvider,
             final @Reference HttpClientFactory httpClientFactory) {
         this.localeProvider = localeProvider;
-        this.httpClient = httpClientFactory.createHttpClient(LinkyBindingConstants.BINDING_ID);
-    }
-
-    @Override
-    protected void activate(ComponentContext componentContext) {
-        super.activate(componentContext);
-        httpClient.setFollowRedirects(false);
-        httpClient.setRequestBufferSize(REQUEST_BUFFER_SIZE);
-
+        SslContextFactory sslContextFactory = new SslContextFactory.Client();
         try {
             SSLContext sslContext = SSLContext.getInstance("SSL");
             sslContext.init(null, new TrustManager[] { TrustAllTrustManager.getInstance() }, null);
-            httpClient.getSslContextFactory().setSslContext(sslContext);
-            httpClient.start();
+            sslContextFactory.setSslContext(sslContext);
         } catch (NoSuchAlgorithmException e) {
             logger.warn("An exception occurred while requesting the SSL encryption algorithm : '{}'", e.getMessage(),
                     e);
         } catch (KeyManagementException e) {
             logger.warn("An exception occurred while initialising the SSL context : '{}'", e.getMessage(), e);
+        }
+        this.httpClient = httpClientFactory.createHttpClient(LinkyBindingConstants.BINDING_ID, sslContextFactory);
+        httpClient.setFollowRedirects(false);
+        httpClient.setRequestBufferSize(REQUEST_BUFFER_SIZE);
+    }
+
+    @Override
+    protected void activate(ComponentContext componentContext) {
+        super.activate(componentContext);
+        try {
+            httpClient.start();
         } catch (Exception e) {
             logger.warn("Unable to start Jetty HttpClient {}", e.getMessage());
         }