Java 11 HttpClient

Hi all I am dealing with a REST api as part of a new binding I have been developing. Is there any issue in using Java 11 Http Client instead of Jetty Http client ?
Thanks

If you plan to contribute it to openHAB, you should develop fo version 4.0 at Java 17.
Any reason why you can not use the provided http client ?

There are no issues at all since it is part of standard library. I am using it with for websockets. It works without any troubles.
Jetty http client pre-dates java 11, it was there with Eclipse SmartHome and OH 2.x, thus some of its use is historical. Personally I try to avoid using jetty client for basic use cases where I can. Obviously in favor of java 11 client.

Are you targeting a custom API or one which has openapi descriptor?

Best,
Łukasz

I use both the OH provided Jetty client, and also the Java Http client. I use the former inside osgi component classes such as bindings, where one can benefit from using the Jetty libraries, and rely on OH to do the Jetty initialisation, clean up, and load balancing. But I also use the latter when I just need to do a plain HTTP GET (say during discovery to ping an IP address to check if it eventually represents something that could be instantiated as an OH thing).

PS (… I guess you know it really … but) the Java version evolution is a cumulative process, so Java version N always includes features from prior Java versions <N (unless specifically deprecated). So to be specific a class (such as an Http client) that had been introduced in Java 11 continues to be a fully valid part of Java 17…

Of course, but OP explicitly asking for Java11, gave me the impression he is developing for openHAB 3

You can compile bindings targeting Java 11 and deploy with Java 17 runtime. It will work because never runtimes still support older bytecode.

OP question is more about standard Java library and not runtime/compile version thus probably all of us are delivering right answers. :wink:

@splatch I have been developing an API to interact with Weatherxm station via Openhab. Frankly I did not know what Openapi descriptor was so I googled it to grasp information. I’d like to know more about ! Thank you so much to this wonderful community for the prompt reply!

Hello @Giovanni_Fabiani,
OpenAPI is descriptor for HTTP services which allow to generate clients or server stubs, thanks to which you save time needed to develop solution. From very quick look at weatherxm I can’t see any official descriptor, however it can always be made manually. Given that weather station have rather limited set of operations I think its not worth investing time into this, unless you feel eager to do so. :wink:

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.