OH2 binding: accessing via HTTP - which library should be used?


(Guenther Schreiner) #1

Hello together,

is there a prefered way of HTTP based communication?

Whereas the org.apache.http.client.methods works fine within the eclipse IDE there seems to be trouble in the real life (on pi3) which can be avoided by using org.apache.commons.httpclient.methods combined with the appropriate lib included in the binding.

Any pointers appreciated & regards,
Guenther


(Hans-Jörg Merk) #2

what about using eclipse smarthome httputil in

org.eclipse.smarthome.io.net.http

(Guenther Schreiner) #3

Thx. This one looks good to me.


(Luca Calcaterra) #4

It’s still valid ? Referring to smarthome docs seems must use jetty client… Which to use at this moment ?


(Hans-Jörg Merk) #5

It is using jetty, just giving you a simplified interface.


(Luca Calcaterra) #6

so better it or apache http util or what else ?


(Hans-Jörg Merk) #7

Use it, as it uses jetty. Please don’t use any other http util.


New Telegram Binding and updated Action - Tester and Feedback welcome
(Luca Calcaterra) #8

ok .thanks !


(Hilbrand Bouwkamp) #9

Like @hmerk mentioned the preferred method is to use org.eclipse.smarthome.io.net.http.HttpUtil.

If for some reason you really need a HttpClient for advanced usage you can get a HttpClient by injecting the HttpClientFactory in your service class:

    private @NonNullByDefault({}) HttpClient httpClient;

    ...

    @Reference
    protected void setHttpClientFactory(HttpClientFactory httpClientFactory) {
        this.httpClient = httpClientFactory.getCommonHttpClient();
    }

    protected void unsetHttpClientFactory(HttpClientFactory httpClientFactory) {
        this.httpClient = null;
    }