2 * Copyright (c) 2010-2023 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
7 * This program and the accompanying materials are made available under the
8 * terms of the Eclipse Public License 2.0 which is available at
9 * http://www.eclipse.org/legal/epl-2.0
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.daikin.internal;
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16 import org.eclipse.jdt.annotation.Nullable;
17 import org.eclipse.jetty.client.HttpClient;
18 import org.eclipse.jetty.util.ssl.SslContextFactory;
19 import org.osgi.service.component.annotations.Component;
20 import org.osgi.service.component.annotations.Deactivate;
21 import org.slf4j.Logger;
22 import org.slf4j.LoggerFactory;
25 * Factory class to create Jetty web clients
27 * Some Daikin controllers communicate via https using a custom common name,
28 * and they are accessed using an ip address.
30 * The core HttpClientFactory creates a HttpClient that will fail because of this.
31 * This factory creates a HttpClient with SslContextFactory(true)
32 * which will accept any ssl certificate without checking for common name mismatches.
34 * @author Jimmy Tanagra - Initial contribution
38 public class DaikinHttpClientFactoryImpl implements DaikinHttpClientFactory {
40 private final Logger logger = LoggerFactory.getLogger(DaikinHttpClientFactoryImpl.class);
42 private @Nullable HttpClient httpClient;
45 protected void deactivate() {
46 if (httpClient != null) {
49 logger.debug("Daikin http client stopped");
50 } catch (Exception e) {
51 logger.debug("error while stopping Daikin http client", e);
58 public @Nullable HttpClient getHttpClient() {
63 private synchronized void initialize() {
64 if (httpClient == null) {
65 httpClient = new HttpClient(new SslContextFactory.Client(true));
68 logger.debug("Daikin http client started");
69 } catch (Exception e) {
70 logger.warn("Could not start Daikin http client", e);