mirror of
https://github.com/openhab/openhab-addons.git
synced 2025-02-04 11:24:10 +01:00
[linky] Call createHttpClient with a SslContextFactory parameter (#14464)
Signed-off-by: Laurent Garnier <lg.hc@free.fr>
This commit is contained in:
parent
d33f6916d2
commit
e33ce1b987
@ -25,6 +25,7 @@ import javax.net.ssl.TrustManager;
|
|||||||
import org.eclipse.jdt.annotation.NonNullByDefault;
|
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.openhab.binding.linky.internal.handler.LinkyHandler;
|
import org.openhab.binding.linky.internal.handler.LinkyHandler;
|
||||||
import org.openhab.core.i18n.LocaleProvider;
|
import org.openhab.core.i18n.LocaleProvider;
|
||||||
import org.openhab.core.io.net.http.HttpClientFactory;
|
import org.openhab.core.io.net.http.HttpClientFactory;
|
||||||
@ -68,25 +69,27 @@ public class LinkyHandlerFactory extends BaseThingHandlerFactory {
|
|||||||
public LinkyHandlerFactory(final @Reference LocaleProvider localeProvider,
|
public LinkyHandlerFactory(final @Reference LocaleProvider localeProvider,
|
||||||
final @Reference HttpClientFactory httpClientFactory) {
|
final @Reference HttpClientFactory httpClientFactory) {
|
||||||
this.localeProvider = localeProvider;
|
this.localeProvider = localeProvider;
|
||||||
this.httpClient = httpClientFactory.createHttpClient(LinkyBindingConstants.BINDING_ID);
|
SslContextFactory sslContextFactory = new SslContextFactory.Client();
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void activate(ComponentContext componentContext) {
|
|
||||||
super.activate(componentContext);
|
|
||||||
httpClient.setFollowRedirects(false);
|
|
||||||
httpClient.setRequestBufferSize(REQUEST_BUFFER_SIZE);
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
SSLContext sslContext = SSLContext.getInstance("SSL");
|
SSLContext sslContext = SSLContext.getInstance("SSL");
|
||||||
sslContext.init(null, new TrustManager[] { TrustAllTrustManager.getInstance() }, null);
|
sslContext.init(null, new TrustManager[] { TrustAllTrustManager.getInstance() }, null);
|
||||||
httpClient.getSslContextFactory().setSslContext(sslContext);
|
sslContextFactory.setSslContext(sslContext);
|
||||||
httpClient.start();
|
|
||||||
} catch (NoSuchAlgorithmException e) {
|
} catch (NoSuchAlgorithmException e) {
|
||||||
logger.warn("An exception occurred while requesting the SSL encryption algorithm : '{}'", e.getMessage(),
|
logger.warn("An exception occurred while requesting the SSL encryption algorithm : '{}'", e.getMessage(),
|
||||||
e);
|
e);
|
||||||
} catch (KeyManagementException e) {
|
} catch (KeyManagementException e) {
|
||||||
logger.warn("An exception occurred while initialising the SSL context : '{}'", e.getMessage(), 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) {
|
} catch (Exception e) {
|
||||||
logger.warn("Unable to start Jetty HttpClient {}", e.getMessage());
|
logger.warn("Unable to start Jetty HttpClient {}", e.getMessage());
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user