[daikin] Use createHttpClient (#14481)
Signed-off-by: Laurent Garnier <lg.hc@free.fr>
This commit is contained in:
parent
20ac69725a
commit
e7b0fc6c14
|
@ -30,7 +30,7 @@ import org.openhab.core.thing.ThingTypeUID;
|
||||||
@NonNullByDefault
|
@NonNullByDefault
|
||||||
public class DaikinBindingConstants {
|
public class DaikinBindingConstants {
|
||||||
|
|
||||||
private static final String BINDING_ID = "daikin";
|
public static final String BINDING_ID = "daikin";
|
||||||
|
|
||||||
// List of all Thing Type UIDs
|
// List of all Thing Type UIDs
|
||||||
public static final ThingTypeUID THING_TYPE_AC_UNIT = new ThingTypeUID(BINDING_ID, "ac_unit");
|
public static final ThingTypeUID THING_TYPE_AC_UNIT = new ThingTypeUID(BINDING_ID, "ac_unit");
|
||||||
|
|
|
@ -16,8 +16,11 @@ import org.eclipse.jdt.annotation.NonNullByDefault;
|
||||||
import org.eclipse.jdt.annotation.Nullable;
|
import org.eclipse.jdt.annotation.Nullable;
|
||||||
import org.eclipse.jetty.client.HttpClient;
|
import org.eclipse.jetty.client.HttpClient;
|
||||||
import org.eclipse.jetty.util.ssl.SslContextFactory;
|
import org.eclipse.jetty.util.ssl.SslContextFactory;
|
||||||
|
import org.openhab.core.io.net.http.HttpClientFactory;
|
||||||
|
import org.osgi.service.component.annotations.Activate;
|
||||||
import org.osgi.service.component.annotations.Component;
|
import org.osgi.service.component.annotations.Component;
|
||||||
import org.osgi.service.component.annotations.Deactivate;
|
import org.osgi.service.component.annotations.Deactivate;
|
||||||
|
import org.osgi.service.component.annotations.Reference;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
@ -39,37 +42,32 @@ public class DaikinHttpClientFactoryImpl implements DaikinHttpClientFactory {
|
||||||
|
|
||||||
private final Logger logger = LoggerFactory.getLogger(DaikinHttpClientFactoryImpl.class);
|
private final Logger logger = LoggerFactory.getLogger(DaikinHttpClientFactoryImpl.class);
|
||||||
|
|
||||||
private @Nullable HttpClient httpClient;
|
private HttpClient httpClient;
|
||||||
|
|
||||||
|
@Activate
|
||||||
|
public DaikinHttpClientFactoryImpl(@Reference HttpClientFactory httpClientFactory) {
|
||||||
|
this.httpClient = httpClientFactory.createHttpClient(DaikinBindingConstants.BINDING_ID,
|
||||||
|
new SslContextFactory.Client(true));
|
||||||
|
try {
|
||||||
|
httpClient.start();
|
||||||
|
logger.debug("Daikin http client started");
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.warn("Could not start Daikin http client", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Deactivate
|
@Deactivate
|
||||||
protected void deactivate() {
|
protected void deactivate() {
|
||||||
if (httpClient != null) {
|
|
||||||
try {
|
try {
|
||||||
httpClient.stop();
|
httpClient.stop();
|
||||||
logger.debug("Daikin http client stopped");
|
logger.debug("Daikin http client stopped");
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
logger.debug("error while stopping Daikin http client", e);
|
logger.debug("error while stopping Daikin http client", e);
|
||||||
}
|
}
|
||||||
httpClient = null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @Nullable HttpClient getHttpClient() {
|
public @Nullable HttpClient getHttpClient() {
|
||||||
initialize();
|
|
||||||
return httpClient;
|
return httpClient;
|
||||||
}
|
}
|
||||||
|
|
||||||
private synchronized void initialize() {
|
|
||||||
if (httpClient == null) {
|
|
||||||
httpClient = new HttpClient(new SslContextFactory.Client(true));
|
|
||||||
try {
|
|
||||||
httpClient.start();
|
|
||||||
logger.debug("Daikin http client started");
|
|
||||||
} catch (Exception e) {
|
|
||||||
logger.warn("Could not start Daikin http client", e);
|
|
||||||
httpClient = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue