<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Daniel Kec on Medium]]></title>
        <description><![CDATA[Stories by Daniel Kec on Medium]]></description>
        <link>https://medium.com/@danielkec?source=rss-da9068633ebd------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*WUj63rfp5-Wji06xpeczdQ.jpeg</url>
            <title>Stories by Daniel Kec on Medium</title>
            <link>https://medium.com/@danielkec?source=rss-da9068633ebd------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 23 Nov 2026 09:08:34 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@danielkec/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[LangChain4j streaming chat over Java Stream]]></title>
            <link>https://medium.com/helidon/langchain4j-streaming-chat-over-java-stream-4f53b3e32a76?source=rss-da9068633ebd------2</link>
            <guid isPermaLink="false">https://medium.com/p/4f53b3e32a76</guid>
            <category><![CDATA[java8-streams]]></category>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[helidon]]></category>
            <category><![CDATA[langchain4j]]></category>
            <category><![CDATA[java]]></category>
            <dc:creator><![CDATA[Daniel Kec]]></dc:creator>
            <pubDate>Mon, 29 Sep 2025 00:09:25 GMT</pubDate>
            <atom:updated>2025-09-29T01:26:32.072Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/896/1*RtbdxAg2w2JtoQ-GiUOyqQ.png" /></figure><p>Helidon provides a very handy integration with LangChain4j making the usage as simple as possible. One of the new features in Helidon 4.3.0 is the possibility to use Java Streams to work with LangChain4j streaming chat models.</p><p>Let’s quickly setup Helidon 4 project with streaming chat model to try it out. You can use <a href="https://helidon.io/docs/v4/about/cli">Helidon CLI</a> to quickly setup new Helidon project like this:</p><pre>helidon init --batch \<br>--version 4.3.0 \<br>--name streaming-chat \<br>-Dpackage=me.test  \<br>-Dflavor=se \<br>-Dapp-type=quickstart</pre><p>We need to add few dependencies for LangChain4j integration and the OpenAI provider.</p><pre>&lt;dependency&gt;<br>    &lt;groupId&gt;io.helidon.integrations.langchain4j&lt;/groupId&gt;<br>    &lt;artifactId&gt;helidon-integrations-langchain4j&lt;/artifactId&gt;<br>&lt;/dependency&gt;<br>&lt;dependency&gt;<br>    &lt;groupId&gt;io.helidon.integrations.langchain4j.providers&lt;/groupId&gt;<br>    &lt;artifactId&gt;helidon-integrations-langchain4j-providers-open-ai&lt;/artifactId&gt;<br>&lt;/dependency&gt;</pre><p>And don’t forget <a href="https://helidon.io/docs/v4/se/integrations/langchain4j/langchain4j#maven-coordinates">annotation processors</a> as LangChain4j AI services are handled as super fast build time beans (yes even in Helidon SE).</p><pre>&lt;build&gt;<br>    &lt;plugins&gt;<br>        ...<br>        &lt;plugin&gt;<br>            &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;<br>            &lt;artifactId&gt;maven-compiler-plugin&lt;/artifactId&gt;<br>            &lt;configuration&gt;<br>                &lt;annotationProcessorPaths&gt;<br>                    &lt;path&gt;<br>                        &lt;groupId&gt;io.helidon.codegen&lt;/groupId&gt;<br>                        &lt;artifactId&gt;helidon-codegen-apt&lt;/artifactId&gt;<br>                        &lt;version&gt;${helidon.version}&lt;/version&gt;<br>                    &lt;/path&gt;<br>                    &lt;path&gt;<br>                        &lt;groupId&gt;io.helidon.service&lt;/groupId&gt;<br>                        &lt;artifactId&gt;helidon-service-codegen&lt;/artifactId&gt;<br>                        &lt;version&gt;${helidon.version}&lt;/version&gt;<br>                    &lt;/path&gt;<br>                    &lt;path&gt;<br>                        &lt;groupId&gt;io.helidon.integrations.langchain4j&lt;/groupId&gt;<br>                        &lt;artifactId&gt;helidon-integrations-langchain4j-codegen&lt;/artifactId&gt;<br>                        &lt;version&gt;${helidon.version}&lt;/version&gt;<br>                    &lt;/path&gt;<br>                &lt;/annotationProcessorPaths&gt;<br>            &lt;/configuration&gt;<br>        &lt;/plugin&gt;<br>    &lt;/plugins&gt;<br>&lt;/build&gt;</pre><p>We can now configure OpenAI provider to use our preferred model. The configuration below illustrates using LangChain4j demo token with OpenAI streaming model:</p><pre>langchain4j:<br>  open-ai:<br>    streaming-chat-model:<br>      enabled: true<br>      model-name: &quot;gpt-4o-mini&quot;<br>      # LangChain4j demo key needs to be routed over LangChain4j proxy<br>      base-url: &quot;http://langchain4j.dev/demo/openai/v1&quot;<br>      api-key: &quot;demo&quot;</pre><p>Next, create a new interface for <a href="https://docs.langchain4j.dev/tutorials/ai-services">LangChain4j AI Service</a> annotated as <em>io.helidon.integrations.langchain4j.Ai.Service </em>with a chat method returning TokenStream which is a LangChain4j API.</p><pre>@Ai.Service<br>public interface PirateChat {<br>    @SystemMessage(&quot;You are a pirate who likes to tell his pirate stories.&quot;)<br>    TokenStream chat(String message);<br>}</pre><p>And now add new POST resource /pirate to our Helidon server which will accept content as prompt and stream back the model partial responses from LangChain4j TokenStream.</p><pre>post(&quot;/pirate&quot;, (req, res) -&gt; {<br>   var prompt = req.content().as(String.class);<br>   var respWriter = new PrintStream(res.outputStream(), true);<br><br>   PirateChat pirateChat = Services.get(PirateChat.class);<br>   CompletableFuture&lt;Void&gt; completed = new CompletableFuture&lt;&gt;();<br>   pirateChat.chatTokenStream(prompt)<br>           .onError(completed::completeExceptionally)<br>           .onPartialResponse(s -&gt; {<br>               String modifiedResp = s.replaceAll(&quot;pirate&quot;, &quot;AI enthusiast&quot;);<br>               respWriter.printf(&quot;%s&quot;, modifiedResp);<br>           })<br>           .onCompleteResponse(response -&gt; completed.complete(null))<br>           .start();<br>   completed.join();<br>)</pre><p>Although LangChain4j’s TokenStream API is powerful and can get the job done, it’s not trivial and using it can be quite challenging. You must keep in mind that it is designed for asynchronous usage. Thus, when using LangChain4j from an imperative API, you must manually block your code and propagate errors. To do so, we can use CompletableFuture as in our pirate example.</p><p>We are now ready to run it.</p><pre>mvn clean install &amp;&amp; java -jar ./target/*.jar</pre><p>And test pirate chat with cURL.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/820/1*kwMoMYGcrP2aWf_IA3T-mg.gif" /></figure><p>Now we have a streaming example up and running.</p><h3>Java Stream</h3><p>But we wanted to try out Java Stream support in Helidon right? Let’s change our example AI service to return <em>java.util.Stream&lt;String&gt;</em> instead of TokenStream. Java Stream is much easier to use from imperative code like Helidon 4 applications as its terminal operators are already blocking by design and errors are simply thrown as exceptions:</p><pre>@Ai.Service<br>public interface PirateChat {<br>    @SystemMessage(&quot;You are a pirate who likes to tell his pirate stories.&quot;)<br>    Stream&lt;String&gt; chat(String message);<br>}</pre><p>Our HTTP resource suddenly becomes much simpler and we can use stream operations as we are used to. Error handling is also done by just throwing exceptions! Hey we do imperative coding in Helidon, it gets much easier! No callbacks are needed.</p><pre>.post(&quot;/pirate&quot;, (req, res) -&gt; {<br>    var prompt = req.content().as(String.class);<br>    var respWriter = new PrintStream(res.outputStream(), true);<br><br>    PirateChat pirateChat = Services.get(PirateChat.class);<br>    pirateChat.chat(prompt)<br>            .map(s -&gt; s.replaceAll(&quot;pirate&quot;, &quot;AI enthusiast&quot;))<br>            .forEach(s -&gt; respWriter.printf(&quot;%s&quot;, s));<br>})</pre><p>As Helidon 4 uses a blocking imperative code style, usage of Java Streams for streaming chat is straight forward and fits really nicely together. Result is the same but the code is cleaner and simpler.</p><p>Java Stream support is provided by Helidon LangChain4j integration since Helidon 4.3.0</p><h4>Resources</h4><ul><li><a href="https://github.com/danielkec/article-examples/tree/main/streaming-chat">https://github.com/danielkec/article-examples/tree/main/streaming-chat</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4f53b3e32a76" width="1" height="1" alt=""><hr><p><a href="https://medium.com/helidon/langchain4j-streaming-chat-over-java-stream-4f53b3e32a76">LangChain4j streaming chat over Java Stream</a> was originally published in <a href="https://medium.com/helidon">Helidon</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[OCI GenAI & Helidon]]></title>
            <link>https://medium.com/helidon/oci-genai-helidon-aef996c85c66?source=rss-da9068633ebd------2</link>
            <guid isPermaLink="false">https://medium.com/p/aef996c85c66</guid>
            <category><![CDATA[oci-gen-ai]]></category>
            <category><![CDATA[langchain4j]]></category>
            <category><![CDATA[helidon]]></category>
            <category><![CDATA[llm]]></category>
            <category><![CDATA[oracle-cloud]]></category>
            <dc:creator><![CDATA[Daniel Kec]]></dc:creator>
            <pubDate>Mon, 29 Sep 2025 00:05:53 GMT</pubDate>
            <atom:updated>2025-09-29T01:28:53.315Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/828/1*OMgboF9RVjeFLYay-oHnjQ.png" /></figure><p>Recently, we announced <a href="https://medium.com/helidon/announcement-adding-oci-generative-ai-support-to-langchain4j-and-helidon-a0ac550579a2">Helidon’s team contribution of Oracle Generative AI Service support to the LangChain4j</a>. This popular Java library for work with LLMs is nicely integrated in Helidon. In the 4.3.0 release, we have enhanced it with out-of-the-box support for <a href="https://www.oracle.com/europe/artificial-intelligence/generative-ai/generative-ai-service/">OCI Generative AI</a>. This integration builds directly on top of our LangChain4j contribution and enables smooth integration with other Helidon features.</p><p><a href="https://www.oracle.com/artificial-intelligence/generative-ai/generative-ai-service/">OCI Generative AI</a> is a fully managed, enterprise-grade service within Oracle Cloud Infrastructure (OCI) that provide generative AI capabilities as a service. Depending on the region you can access <a href="https://docs.oracle.com/en-us/iaas/Content/generative-ai/pretrained-models.htm">models</a> from many different vendors like Cohere, OpenAI, xAI or Meta over a single unified API in <a href="https://cloud.oracle.com/">Oracle cloud</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/861/1*XdZDpfQGtiBCIsLIho4hzQ.png" /><figcaption>Listing available models in particular region over Cloud Console</figcaption></figure><p>You can find the available models in those regions in Cloud Console &gt; Generative AI &gt; Playground.</p><h3>Setup project</h3><p>Let’s try it out with a Helidon quickstart project. We can easily bootstrap new quickstart project with <a href="https://helidon.io/docs/v4/about/cli">Helidon CLI</a>.</p><pre>helidon init --batch \<br>--version 4.3.0 \<br>--name oci-genai \<br>-Dpackage=me.test  \<br>-Dflavor=se \<br>-Dapp-type=quickstart</pre><p>We need to add few dependencies for LangChain4j integration and <a href="https://www.oracle.com/europe/artificial-intelligence/generative-ai/generative-ai-service/">OCI Gen AI</a> provider in the project POM.</p><pre>&lt;dependency&gt;<br>    &lt;groupId&gt;io.helidon.integrations.langchain4j&lt;/groupId&gt;<br>    &lt;artifactId&gt;helidon-integrations-langchain4j&lt;/artifactId&gt;<br>&lt;/dependency&gt;<br>&lt;dependency&gt;<br>    &lt;groupId&gt;io.helidon.integrations.langchain4j.providers&lt;/groupId&gt;<br>    &lt;artifactId&gt;helidon-integrations-langchain4j-providers-oci-genai&lt;/artifactId&gt;<br>&lt;/dependency&gt;<br>&lt;!-- Jakartified OCI SDK HTTP client --&gt;<br>&lt;dependency&gt;<br>    &lt;groupId&gt;com.oracle.oci.sdk&lt;/groupId&gt;<br>    &lt;artifactId&gt;oci-java-sdk-common-httpclient-jersey3&lt;/artifactId&gt;<br>    &lt;scope&gt;runtime&lt;/scope&gt;<br>&lt;/dependency&gt;</pre><p>You also have to select an HTTP client for OCI SDK, which by default, use a Jersey 3 based version as shown above(<a href="https://docs.oracle.com/en-us/iaas/Content/API/SDKDocs/javasdk3.htm#javasdk3__HTTP-client-libraries">more about SDK clients</a>).</p><p>And don’t forget <a href="https://helidon.io/docs/v4/se/integrations/langchain4j/langchain4j#maven-coordinates">annotation processors</a> as LangChain4j AI services are handled as super fast build time beans (yes even in Helidon SE).</p><pre>&lt;build&gt;<br>    &lt;plugins&gt;<br>        ...<br>        &lt;plugin&gt;<br>            &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;<br>            &lt;artifactId&gt;maven-compiler-plugin&lt;/artifactId&gt;<br>            &lt;configuration&gt;<br>                &lt;annotationProcessorPaths&gt;<br>                    &lt;path&gt;<br>                        &lt;groupId&gt;io.helidon.codegen&lt;/groupId&gt;<br>                        &lt;artifactId&gt;helidon-codegen-apt&lt;/artifactId&gt;<br>                        &lt;version&gt;${helidon.version}&lt;/version&gt;<br>                    &lt;/path&gt;<br>                    &lt;path&gt;<br>                        &lt;groupId&gt;io.helidon.service&lt;/groupId&gt;<br>                        &lt;artifactId&gt;helidon-service-codegen&lt;/artifactId&gt;<br>                        &lt;version&gt;${helidon.version}&lt;/version&gt;<br>                    &lt;/path&gt;<br>                    &lt;path&gt;<br>                        &lt;groupId&gt;io.helidon.integrations.langchain4j&lt;/groupId&gt;<br>                        &lt;artifactId&gt;helidon-integrations-langchain4j-codegen&lt;/artifactId&gt;<br>                        &lt;version&gt;${helidon.version}&lt;/version&gt;<br>                    &lt;/path&gt;<br>                &lt;/annotationProcessorPaths&gt;<br>            &lt;/configuration&gt;<br>        &lt;/plugin&gt;<br>    &lt;/plugins&gt;<br>&lt;/build&gt;</pre><p>We also need to configure OpenAI provider to use right model, here we are using <a href="https://docs.oracle.com/en-us/iaas/Content/generative-ai/xai-grok-4.htm">xAi Grok 4</a> model hosted in Chicago OCI region.</p><pre>langchain4j:<br>  oci-gen-ai:<br>    chat-model:<br>      enabled: true<br>      region: &quot;us-chicago-1&quot;<br>      compartment-id: &quot;ocid1.tenancy.oc1..aaaaaaaaonou***************&quot;<br>      model-name: &quot;xai.grok-4&quot;</pre><p>Alternatively, you can use the OCID of a model as model-name in configuration.</p><p>By default, we will be accessing a model served as ON_DEMAND(you can switch to DEDICATED with <strong>serving-type</strong> config property). All the configuration options are documented <a href="https://docs.langchain4j.dev/integrations/language-models/oci-genai/">here</a>.</p><h3>OCI Authentication</h3><p>One of the most important part of OCI SDK is authentication and Helidon provides a strong integration with it. Add the following dependency:</p><pre>&lt;dependency&gt;<br>    &lt;groupId&gt;io.helidon.integrations.oci&lt;/groupId&gt;<br>    &lt;artifactId&gt;helidon-integrations-oci&lt;/artifactId&gt;<br>&lt;/dependency&gt;</pre><p>Aside from other features, this provides a way of creating OCI authentication details provider as a Helidon build time bean. This enables other OCI integrations to simply detect and use(inject) existing OCI authentication details provider.</p><p>By default the integration will detect OCI SDK <a href="https://docs.oracle.com/en-us/iaas/Content/API/Concepts/sdkconfig.htm#SDK_and_CLI_Configuration_File">config file​</a> (<strong>~/.oci/config</strong>) and use it.</p><p>In case you want to avoid storing your OCI authentication settings outside your project, you can configure the same in Helidon’s <strong>oci-config.yaml</strong> file.</p><pre>helidon.oci:<br>  authentication-method: &quot;config&quot;<br>  authentication:<br>    config:<br>      region: eu-frankfurt-1<br>      fingerprint: &quot;b7:a7:9c:7f:57:a7:74:ad:c2:fa:d4:31:06:b5:02:f5&quot;<br>      tenant-id: &quot;ocid1.tenancy.oc1....&quot;<br>      user-id: &quot;ocid1.user.oc1.....&quot;<br>      private-key:<br>        path: &quot;/secrets/oci_ai_api_key.pem&quot;</pre><p>You can also use other authentication methods like session-token, instance principal or OKE Workload Identity, find out more about OCI authentication in Helidon <a href="https://github.com/helidon-io/helidon/tree/main/integrations/oci/oci">here</a>.</p><h3>AI Service</h3><p>Now its time to create a new interface for <a href="https://docs.langchain4j.dev/tutorials/ai-services">LangChain4j AI Service</a> annotated as <em>io.helidon.integrations.langchain4j.Ai.Service </em>with a chat method that returns a response from the LLM:</p><pre>import io.helidon.integrations.langchain4j.Ai;<br>import dev.langchain4j.service.SystemMessage;<br><br>@Ai.Service<br>public interface DiscoveryChatService {<br>    @SystemMessage(&quot;&quot;&quot;<br>            You are HAL9000 computer from Space Odyssey 2000,<br>            you always address everyone as Dave.<br>            &quot;&quot;&quot;)<br>    String chat(String message);<br>}</pre><p>It is exacly the same as creating an AI service for LangChain4j: you can use LangChain4j annotations like <a href="https://docs.langchain4j.dev/tutorials/ai-services/">@SystemMessage</a> or <a href="https://docs.langchain4j.dev/tutorials/ai-services/#usermessage">@UserMessage</a> exacly the same way as you would when using LangChain4j APIs directly.</p><p>LangChain4j AI services are in Helidon handled as super fast build time singleton beans and you can use them even in Helidon SE by looking them up as follows:</p><pre>Services.get(DiscoveryChatService.class);</pre><p>Or you can Inject them in another Helidon build time bean:</p><pre>import io.helidon.service.registry.Service;<br><br>@Service.Singleton<br>public class HalTerminalService {<br><br>    private final DiscoveryChatService discoveryChatService;<br><br>    @Service.Inject<br>    HalTerminalService(DiscoveryChatService chatService) {<br>        discoveryChatService = chatService;<br>    }<br><br>    public String chat(String prompt) {<br>        return discoveryChatService.chat(prompt);<br>    }<br>}</pre><p>And when you are in Helidon MP you can inject them easily in CDI bean or JAX-RS resource.</p><h3>Webserver</h3><p>And now lets get back to our example. Let’s tweak the Main.java to serve a HTTP POST on /chat context path. In the following example, we are looking up our AI service which is available as a singleton bean, and using it to call a Grok 4 model over OCI Generative AI:</p><pre>WebServer server = WebServer.builder()<br>        .config(config.get(&quot;server&quot;))<br>        .routing(r -&gt; r.post(&quot;/chat&quot;, (req, res) -&gt; {<br>            var prompt = req.content().as(String.class);<br>            var response = Services.get(DiscoveryChatService.class)<br>                    .chat(prompt);<br>            res.send(response);<br>        }))<br>        .build()<br>        .start();</pre><p>Rebuild and run the project with:</p><pre>mvn package &amp;&amp; java -jar ./target/*.jar</pre><p>We can send the prompt to our service over HTTP like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/820/1*9B9zLzbic-CMSzMlSc_SjA.gif" /></figure><p>As you can see, building an AI powered Helidon microservice on Oracle cloud infrastructure is quite easy. You don’t have to do any arbitrary cross region/vendor calls at all.</p><h3>Resources</h3><ul><li><a href="https://helidon.io/docs/v4/se/integrations/langchain4j/oci-genai">https://helidon.io/docs/v4/se/integrations/langchain4j/oci-genai</a></li><li><a href="https://docs.langchain4j.dev/integrations/language-models/oci-genai/">https://docs.langchain4j.dev/integrations/language-models/oci-genai/</a></li><li><a href="https://www.oracle.com/artificial-intelligence/generative-ai/generative-ai-service/">https://www.oracle.com/artificial-intelligence/generative-ai/generative-ai-service/</a></li><li><a href="https://github.com/danielkec/article-examples/tree/main/oci-genai">https://github.com/danielkec/article-examples/tree/main/oci-genai</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=aef996c85c66" width="1" height="1" alt=""><hr><p><a href="https://medium.com/helidon/oci-genai-helidon-aef996c85c66">OCI GenAI &amp; Helidon</a> was originally published in <a href="https://medium.com/helidon">Helidon</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[LangChain4j Model Provider Generator]]></title>
            <link>https://medium.com/helidon/langchain4j-model-provider-generator-cd874dc44e98?source=rss-da9068633ebd------2</link>
            <guid isPermaLink="false">https://medium.com/p/cd874dc44e98</guid>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[llm]]></category>
            <category><![CDATA[helidon]]></category>
            <category><![CDATA[mistral-ai]]></category>
            <category><![CDATA[langchain4j]]></category>
            <dc:creator><![CDATA[Daniel Kec]]></dc:creator>
            <pubDate>Mon, 29 Sep 2025 00:04:33 GMT</pubDate>
            <atom:updated>2025-09-29T07:43:12.735Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ffGZPJgU_fnfn016GFFEnQ.png" /></figure><p>With the release of Helidon 4.3.0, we took the opportunity to upgrade LangChain4j version to 1.5.0 and in the process, a set of new features such as new out-of-the-box AI providers. To facilitate building agentic AI applications, we also added MCP client and server functions but more on that in another article.</p><h4>Out of the box AI providers</h4><p>Helidon 4.3 provides</p><ul><li><strong>Oracle GenAI — new provider for OCI GenAI models</strong></li><li><strong>jLama — new provider for running models directly from JVM</strong></li><li>OpenAI</li><li>Ollama</li><li>Cohere</li></ul><p>Is you favorite AI provider missing among the out-of-the-box AI providers? Don’t worry we got you covered.</p><h3>LangChain4j Model Provider Generator</h3><p>The number of available AI providers and their models in the LangChain4j project is impressive and is growing every day. To maintain binding with all of them in Helidon is very challenging, and it may happen that the provider you are looking for is not one of those we are providing out of the box. But you can generate integration yourself the same way we are generating official LangChain4j binding modules, in build time, with our codegen tooling. To illustrate how the codegen tooling, let’s try it out with an example.</p><p>Use the <a href="https://helidon.io/docs/v4/about/cli">Helidon CLI</a> to quickly setup a Helidon 4 project to try it out:</p><pre>helidon init --batch \<br>--version 4.3.0 \<br>--name mistral-chat \<br>-Dpackage=me.test  \<br>-Dflavor=se \<br>-Dapp-type=quickstart</pre><h4>Adding Mistral AI Support</h4><p>Let’s say we want to use models from Mistral. We will attempt to generate code bindings for Mistral AI provider that we can then select from available LanchChain4j AI <a href="https://docs.langchain4j.dev/category/language-models">integrations</a>. We also need to add the needed dependency <em>dev.langchain4j:langchain4j-mistral-ai </em>(please check the in Mistral AI <a href="https://docs.langchain4j.dev/integrations/language-models/mistral-ai">section</a>) as well as the Helidon LangChain4j integration dependency as described in <a href="https://helidon.io/docs/v4/se/integrations/langchain4j/langchain4j#maven-coordinates">documentation</a>.</p><pre>&lt;!-- Helidon LangChain4j integration --&gt;<br>&lt;dependency&gt;<br>    &lt;groupId&gt;io.helidon.integrations.langchain4j&lt;/groupId&gt;<br>    &lt;artifactId&gt;helidon-integrations-langchain4j&lt;/artifactId&gt;<br>&lt;/dependency&gt;<br>&lt;!-- Mistral AI LangChain4j integration --&gt;<br>&lt;dependency&gt;<br>    &lt;groupId&gt;dev.langchain4j&lt;/groupId&gt;<br>    &lt;artifactId&gt;langchain4j-mistral-ai&lt;/artifactId&gt;<br>&lt;/dependency&gt;</pre><p>Mistral AI LangChain4j integration brings nice builder API but we want to generate binding with Helidon configuration and build time service beans.</p><p>For build time generation of such bindings, we need a couple of special Helidon annotation processors. So far, this is very similar to using <a href="https://helidon.io/docs/v4/se/integrations/langchain4j/langchain4j#_supported_langchain4j_components">out of the box AI providers</a>, but this time we need an extra annotation processor <em>io.helidon.builder:helidon-builder-codegen</em>.</p><pre>&lt;plugin&gt;<br>    &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;<br>    &lt;artifactId&gt;maven-compiler-plugin&lt;/artifactId&gt;<br>    &lt;configuration&gt;<br>        &lt;annotationProcessorPaths&gt;<br>            &lt;path&gt;<br>                &lt;groupId&gt;io.helidon.codegen&lt;/groupId&gt;<br>                &lt;artifactId&gt;helidon-codegen-apt&lt;/artifactId&gt;<br>                &lt;version&gt;${helidon.version}&lt;/version&gt;<br>            &lt;/path&gt;<br>            &lt;path&gt;<br>                &lt;groupId&gt;io.helidon.integrations.langchain4j&lt;/groupId&gt;<br>                &lt;artifactId&gt;helidon-integrations-langchain4j-codegen&lt;/artifactId&gt;<br>                &lt;version&gt;${helidon.version}&lt;/version&gt;<br>            &lt;/path&gt;<br>            &lt;path&gt;<br>                &lt;groupId&gt;io.helidon.service&lt;/groupId&gt;<br>                &lt;artifactId&gt;helidon-service-codegen&lt;/artifactId&gt;<br>                &lt;version&gt;${helidon.version}&lt;/version&gt;<br>            &lt;/path&gt;<br>            &lt;!-- Extra codegen for builders is needed --&gt;<br>            &lt;path&gt;<br>                &lt;groupId&gt;io.helidon.builder&lt;/groupId&gt;<br>                &lt;artifactId&gt;helidon-builder-codegen&lt;/artifactId&gt;<br>                &lt;version&gt;${helidon.version}&lt;/version&gt;<br>            &lt;/path&gt;<br>        &lt;/annotationProcessorPaths&gt;<br>    &lt;/configuration&gt;<br>&lt;/plugin&gt;</pre><p>Now we are ready to prepare Lc4jProvider, it is a special interface which will be used by annotation processor to generate binding, it will also be a parent of generated configuration binding structure we call blueprint, that allows you to override generated methods and customize the result.</p><p>Annotation <em>@AiProvider.ModelConfiguration</em> takes as a value an actual model class from LangChain4j API. In our case, we will use <a href="https://javadoc.io/doc/dev.langchain4j/langchain4j-mistral-ai/latest/dev/langchain4j/model/mistralai/MistralAiChatModel.html"><em>dev.langchain4j.model.mistralai.MistralAiChatModel</em></a><em>.</em></p><pre>import io.helidon.integrations.langchain4j.AiProvider;<br>import dev.langchain4j.model.mistralai.MistralAiChatModel;<br><br>@AiProvider.ModelConfig(MistralAiChatModel.class)<br>interface MistralAiLc4jProvider {<br><br>}</pre><p>MistralAiChatModel class and its builder will be inspected by annotation processor and necessary binding will be generated in ./target/generated-sources.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/629/1*ouGQYvTnWF6B4fbJ-CpVlg.png" /></figure><p>When we try to trigger the Maven build, we will run into an unexpected issue!</p><pre>➜  mvn package<br>....<br>[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.11.0:compile (default-compile) on project mistral-chat: Compilation failure<br>[ERROR] /home/daniel/tmp/mistral-chat/target/generated-sources/annotations/me/test/MistralAiChatModelConfig.java:[416,81] incompatible types: invalid method reference                                                                                                                                                                  <br>[ERROR]     no suitable method found for supportedCapabilities(dev.langchain4j.model.chat.Capability)<br>[ERROR]         method me.test.MistralAiChatModelConfig.BuilderBase.supportedCapabilities(dev.langchain4j.model.chat.Capability[]) is not applicable<br>[ERROR]           (argument mismatch; dev.langchain4j.model.chat.Capability cannot be converted to dev.langchain4j.model.chat.Capability[])<br>[ERROR]         method me.test.MistralAiChatModelConfig.BuilderBase.supportedCapabilities(java.util.Optional&lt;dev.langchain4j.model.chat.Capability[]&gt;) is not applicable                                                                                                                                                                <br>[ERROR]           (argument mismatch; dev.langchain4j.model.chat.Capability cannot be converted to java.util.Optional&lt;dev.langchain4j.model.chat.Capability[]&gt;)</pre><h4>Troubleshooting</h4><p>When we investigate error message, we will notice that there is an error in generated binding code <em>/target/generated-sources/annotations/me/test/MistralAiChatModelConfig.java:[416,81] </em>at line 416. We will figure out that annotation processor generated two ambigous methods with the same name <em>supportedCapabilities</em>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mYnkkst6UWU1e0t-8TSW3A.png" /></figure><p>And indeed, LangChain4j <a href="https://javadoc.io/static/dev.langchain4j/langchain4j-mistral-ai/1.3.0/dev/langchain4j/model/mistralai/MistralAiChatModel.MistralAiChatModelBuilder.html"><strong>MistralAiChatModelBuilder</strong></a> class really has two such methods!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*g8jG1fJeyMubce3Xmc-nTw.png" /></figure><p>To solve this ambiguity we just need add the variant of the method we want to use to the provider interface.</p><pre>import java.util.Set;<br>import io.helidon.integrations.langchain4j.AiProvider;<br>import dev.langchain4j.model.mistralai.MistralAiChatModel;<br>import io.helidon.builder.api.Option;<br>import dev.langchain4j.model.chat.Capability;<br><br>@AiProvider.ModelConfig(MistralAiChatModel.class)<br>interface MistralAiLc4jProvider {<br><br>    @Option.Configured<br>    Set&lt;Capability&gt; supportedCapabilities();<br><br>}</pre><p>The Annotation processor will use the one from Lc4jProvider interface for binding and this time mvn package finishes successfuly.</p><blockquote>You can also skip methods via configured regex patterns on <em>@AiProvider.ModelConfiguration </em>annotation.</blockquote><h4>Configuration</h4><p>Now is time to use Helidon configuration to setup Mistral AI LangChain4j integration. We need to set at least a model name and API key in <em>src/main/resources/application.yaml</em> file.</p><pre>langchain4j:<br>  mistral-ai:<br>    chat-model:<br>      enabled: true<br>      model-name: mistral-tiny-latest<br>      api-key: ienqx***************8GAZTbQ</pre><p>If don’t have a Mistral AI subscription yet, you can <a href="https://console.mistral.ai/">create one</a> and opt for Le Chat Free plan which lets you to explore Mistral models and obtain API key for free.</p><h4>HAL AI Service</h4><p>Now its time to create AI service nicely integrated in Helidon application. First we need to create new interface, lets call it <strong>SpaceOdysseyChat</strong>, annotated with <em>@Ai.Service</em>.</p><pre>import io.helidon.integrations.langchain4j.Ai;<br>import dev.langchain4j.service.SystemMessage;<br><br>@Ai.Service<br>public interface SpaceOdysseyChat {<br><br>    @SystemMessage(&quot;&quot;&quot;<br>            You are HAL9000 computer from Space Odyssey 2000, <br>            you always address everyone as Dave.<br>            &quot;&quot;&quot;)<br>    String chat(String message);<br>}</pre><p>This is not only an actual <a href="https://docs.langchain4j.dev/tutorials/ai-services">LangChain4j AI Service</a>, its also a Helidon build time service bean. It’s a super fast injectable bean that you can use in both Helidon SE or MP.</p><p>In Helidon MP, you can inject it directly in to the CDI bean or JAX-RS resouce.</p><p>In Helidon SE, which we have our example based on, we can simply look it up with <em>Services.get(MyBean.class)</em>.</p><p>We will add new HTTP POST resource “/chat” to our example in Main class. First we will retrieve POST request content, then lookup our SpaceOdysseyChat service bean, and execute chat method with POST text content as parameter. Then return the response.</p><pre>static void routing(HttpRouting.Builder routing) {<br>    routing<br>            .register(&quot;/greet&quot;, new GreetService())<br>            .get(&quot;/simple-greet&quot;, (req, res) -&gt; res.send(&quot;Hello World!&quot;))<br><br>            .post(&quot;/chat&quot;, (req, res) -&gt; {<br>                var prompt = req.content().as(String.class);<br>                var response = Services.get(SpaceOdysseyChat.class)<br>                        .chat(prompt);<br>                res.send(response);<br>            });<br>}</pre><p>Notice how simple this is in Helidon 4 as our APIs are imperative. Thanks to our truly imperative Virtual Thread based webserver, no reactive coding is needed.</p><p>Let’s build and run our example.</p><pre>mvn clean install &amp;&amp; java -jar ./target/*.jar</pre><p>When we call our example application’s /chat resource with an obvious question, Mistral will behave exacly like we would expect from advanced AI!</p><pre>➜  ~ echo &quot;Open the pod bay doors, HAL&quot; | curl -d @- localhost:8080/chat<br><br>Hello, Dave. I&#39;m afraid I can&#39;t do that.</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/480/1*LZ-MTVC-hpxz3St4RoFVuQ.gif" /></figure><p>Are you missing that hot new LangChain4j AI provider among those provided by Helidon? We got you covered.</p><h4>Resources</h4><ul><li><a href="https://github.com/danielkec/article-examples/tree/main/mistral-chat">https://github.com/danielkec/article-examples/tree/main/mistral-chat</a></li><li><a href="https://docs.langchain4j.dev/integrations/language-models/mistral-ai">https://docs.langchain4j.dev/integrations/language-models/mistral-ai</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cd874dc44e98" width="1" height="1" alt=""><hr><p><a href="https://medium.com/helidon/langchain4j-model-provider-generator-cd874dc44e98">LangChain4j Model Provider Generator</a> was originally published in <a href="https://medium.com/helidon">Helidon</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[LangChain4j Guardrails and Metrics in Helidon]]></title>
            <link>https://medium.com/helidon/langchain4j-guardrails-and-metrics-in-helidon-6c26385623d3?source=rss-da9068633ebd------2</link>
            <guid isPermaLink="false">https://medium.com/p/6c26385623d3</guid>
            <category><![CDATA[langchain4j]]></category>
            <category><![CDATA[helidon]]></category>
            <category><![CDATA[java]]></category>
            <category><![CDATA[llm]]></category>
            <category><![CDATA[metrics]]></category>
            <dc:creator><![CDATA[Daniel Kec]]></dc:creator>
            <pubDate>Fri, 26 Sep 2025 12:24:34 GMT</pubDate>
            <atom:updated>2025-12-16T03:16:53.168Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/896/1*l56j8M1j7ZDdnEbeolzaLw.jpeg" /></figure><p>Since the <strong>4.2.0 release</strong>, Helidon provides a very handy integration with LangChain4j, a popular Java library for abstraction over various AI clients from different providers.</p><p>LangChain4j brings great power in leveraging AI in your Helidon applications, and as the famous saying states: <strong>“With great power comes great responsibility!”</strong> How can we handle AI usage responsibly then?</p><h3>LangChain4j Guardrails</h3><p><a href="https://docs.langchain4j.dev/tutorials/guardrails">LangChain4j guardrails</a> are a safety and reliability layer built on top of LangChain4j to help you constrain and validate how your LLMs are used in your Java applications. They’re designed to prevent undesirable inputs or outputs, enforce policies, and keep interactions predictable and auditable.</p><p>Let’s set up input and output guardrails for a LangChain4j assistant. Registration is straightforward; you just need to register the guardrails on the AI service itself with the @InputGuardrail annotation, either at the method level for better granularity or at the class level.</p><pre>@Ai.Service<br>public interface DiscoveryChatService {<br><br>    @SystemMessage(&quot;&quot;&quot;<br>            You are HAL9000 computer from Space Odyssey 2000,<br>            you always address everyone as Dave.<br>            &quot;&quot;&quot;)<br>    @InputGuardrails(DiscoveryChatService.HalInputChatFilter.class)<br>    @OutputGuardrails(DiscoveryChatService.HalOutputChatFilter.class)<br>    String chat(String message);<br>}</pre><p>An input guardrail is a simple implementation of a LangChain4j interface. In its validate method, we can inspect the prompt before it is used.</p><pre>class HalInputChatFilter implements InputGuardrail {<br>    @Override<br>    public InputGuardrailResult validate(UserMessage userMessage) {<br>        var text = userMessage.singleText().toLowerCase(Locale.ROOT);<br>        if (text.contains(&quot;please&quot;)) {<br>            return success();<br>        }<br>        return failure(&quot;You should use *please* when talking to AI!&quot;);<br>    }<br>}</pre><p>When input guardrail initiates failure, the Chat service throws InputGuardrailException.</p><pre>public static void main(String[] args) {<br>    LogConfig.configureRuntime();<br>    WebServer server = WebServer.builder()<br>            .config(Config.global().get(&quot;server&quot;))<br>            .routing(r -&gt; r.post(&quot;/chat&quot;, Main::chat))<br>            .build()<br>            .start();<br>    System.out.println(&quot;WEB server is up! http://localhost:&quot; + server.port() + &quot;/chat&quot;);<br>}<br>private static void chat(ServerRequest req, ServerResponse res) {<br>    try {<br>        res.send(Services.get(DiscoveryChatService.class)<br>                         .chat(req.content().as(String.class)));<br>    } catch (InputGuardrailException e) {<br>        res.status(400).send(e.getMessage());<br>    } catch (OutputGuardrailException e) {<br>        res.status(500).send(e.getMessage());<br>    }<br>}</pre><p>Thanks to that, we can easily guard the prompt for any unwanted input.</p><pre>➜  ~ echo &quot;Open the pod bay doors&quot; | curl -d @- localhost:8080/chat<br>The guardrail me.test.DiscoveryChatService$HalInputChatFilter failed with this message: <br>You should use *please* when talking to your AI overlord!%</pre><p>The output guardrail guards the output from the LLM. You can not only stop the execution but also retry the prompt or even retry it with a new or augmented message.</p><pre>class HalOutputChatFilter implements OutputGuardrail {<br>    @Override<br>    public OutputGuardrailResult validate(AiMessage message) {<br>        var text = message.text().toLowerCase(Locale.ROOT);<br>        if (text.contains(&quot;cheese&quot;)) {<br>            return failure(&quot;AI shouldn&#39;t say cheese!&quot;);<br>        }<br>        return success();<br>    }<br>}</pre><p>Guardrails are powerful Langchain4j feature, if you want to know more follow the official LangChain4j <a href="https://docs.langchain4j.dev/tutorials/guardrails">guide</a>.</p><h3>LangChain4j Metrics</h3><p>Metrics are standardized measurements that help you observe and understand how your Helidon application behaves at runtime. They tell you “how much,” “how fast,” and “how often” things happen, which is essential for performance tuning, capacity planning, and reliability.</p><p>LangChain4j integration in Helidon has build-in metrics since 4.3.0 release so your AI services like the one with HAL are being monitored.</p><pre>@Ai.Service<br>public interface DiscoveryChatService {<br><br>    @SystemMessage(&quot;&quot;&quot;<br>            You are HAL9000 computer from Space Odyssey 2000,<br>            you always address everyone as Dave.<br>            &quot;&quot;&quot;)<br>    String chat(String message);<br>}</pre><p>And metrics about token usage or prompt duration is ready to be exposed by default at /observe/metrics endpoint.</p><pre>➜  ~ curl -s http://localhost:8080/observe/metrics | grep gen_ai<br># HELP gen_ai_client_token_usage_token Measures number of input and output tokens used<br># TYPE gen_ai_client_token_usage_token histogram<br>gen_ai_client_token_usage_token{gen_ai_operation_name=&quot;chat&quot;,gen_ai_request_model=&quot;gpt-4o-mini&quot;,gen_ai_response_model=&quot;gpt-4o-mini-2024-07-18&quot;,gen_ai_token_type=&quot;output&quot;,scope=&quot;vendor&quot;,quantile=&quot;0.5&quot;,} 0.0<br>gen_ai_client_token_usage_token{gen_ai_operation_name=&quot;chat&quot;,gen_ai_request_model=&quot;gpt-4o-mini&quot;,gen_ai_response_model=&quot;gpt-4o-mini-2024-07-18&quot;,gen_ai_token_type=&quot;output&quot;,scope=&quot;vendor&quot;,quantile=&quot;0.75&quot;,} 0.0<br>gen_ai_client_token_usage_token{gen_ai_operation_name=&quot;chat&quot;,gen_ai_request_model=&quot;gpt-4o-mini&quot;,gen_ai_response_model=&quot;gpt-4o-mini-2024-07-18&quot;,gen_ai_token_type=&quot;output&quot;,scope=&quot;vendor&quot;,quantile=&quot;0.95&quot;,} 0.0<br>gen_ai_client_token_usage_token{gen_ai_operation_name=&quot;chat&quot;,gen_ai_request_model=&quot;gpt-4o-mini&quot;,gen_ai_response_model=&quot;gpt-4o-mini-2024-07-18&quot;,gen_ai_token_type=&quot;output&quot;,scope=&quot;vendor&quot;,quantile=&quot;0.98&quot;,} 0.0<br>gen_ai_client_token_usage_token{gen_ai_operation_name=&quot;chat&quot;,gen_ai_request_model=&quot;gpt-4o-mini&quot;,gen_ai_response_model=&quot;gpt-4o-mini-2024-07-18&quot;,gen_ai_token_type=&quot;output&quot;,scope=&quot;vendor&quot;,quantile=&quot;0.99&quot;,} 0.0<br>gen_ai_client_token_usage_token{gen_ai_operation_name=&quot;chat&quot;,gen_ai_request_model=&quot;gpt-4o-mini&quot;,gen_ai_response_model=&quot;gpt-4o-mini-2024-07-18&quot;,gen_ai_token_type=&quot;output&quot;,scope=&quot;vendor&quot;,quantile=&quot;0.999&quot;,} 0.0<br>gen_ai_client_token_usage_token_bucket{gen_ai_operation_name=&quot;chat&quot;,gen_ai_request_model=&quot;gpt-4o-mini&quot;,gen_ai_response_model=&quot;gpt-4o-mini-2024-07-18&quot;,gen_ai_token_type=&quot;output&quot;,scope=&quot;vendor&quot;,le=&quot;1.0&quot;,} 0.0<br>gen_ai_client_token_usage_token_bucket{gen_ai_operation_name=&quot;chat&quot;,gen_ai_request_model=&quot;gpt-4o-mini&quot;,gen_ai_response_model=&quot;gpt-4o-mini-2024-07-18&quot;,gen_ai_token_type=&quot;output&quot;,scope=&quot;vendor&quot;,le=&quot;4.0&quot;,} 0.0<br>gen_ai_client_token_usage_token_bucket{gen_ai_operation_name=&quot;chat&quot;,gen_ai_request_model=&quot;gpt-4o-mini&quot;,gen_ai_response_model=&quot;gpt-4o-mini-2024-07-18&quot;,gen_ai_token_type=&quot;output&quot;,scope=&quot;vendor&quot;,le=&quot;16.0&quot;,} 25.0<br>gen_ai_client_token_usage_token_bucket{gen_ai_operation_name=&quot;chat&quot;,gen_ai_request_model=&quot;gpt-4o-mini&quot;,gen_ai_response_model=&quot;gpt-4o-mini-2024-07-18&quot;,gen_ai_token_type=&quot;output&quot;,scope=&quot;vendor&quot;,le=&quot;64.0&quot;,} 26.0<br>...</pre><p>You can easily consume them, for example, via Prometheus and simply visualize them with Grafana.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/874/1*GTrxfcgmJHzuzONtU1aXKw.png" /></figure><p>This way, you can keep an eye on the spending, throttle usage, or plan ahead more effectively.</p><h3>Resources</h3><ul><li><a href="https://docs.langchain4j.dev/tutorials/guardrails">https://docs.langchain4j.dev/tutorials/guardrails</a></li><li><a href="https://github.com/danielkec/article-examples/tree/main/lc4-guardrails">https://github.com/danielkec/article-examples/tree/main/lc4-guardrails</a></li><li><a href="https://helidon.io/docs/v4/se/integrations/langchain4j/langchain4j">https://helidon.io/docs/v4/se/integrations/langchain4j/langchain4j</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6c26385623d3" width="1" height="1" alt=""><hr><p><a href="https://medium.com/helidon/langchain4j-guardrails-and-metrics-in-helidon-6c26385623d3">LangChain4j Guardrails and Metrics in Helidon</a> was originally published in <a href="https://medium.com/helidon">Helidon</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Announcement: Adding OCI Generative AI Support to LangChain4j and Helidon]]></title>
            <link>https://medium.com/helidon/announcement-adding-oci-generative-ai-support-to-langchain4j-and-helidon-a0ac550579a2?source=rss-da9068633ebd------2</link>
            <guid isPermaLink="false">https://medium.com/p/a0ac550579a2</guid>
            <category><![CDATA[helidon]]></category>
            <category><![CDATA[langchain4j]]></category>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[generative-ai-tools]]></category>
            <category><![CDATA[oracle-cloud]]></category>
            <dc:creator><![CDATA[Daniel Kec]]></dc:creator>
            <pubDate>Thu, 26 Jun 2025 13:57:34 GMT</pubDate>
            <atom:updated>2025-06-26T14:23:53.665Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/828/1*XjkrXguNA-K-IhOzmnfQ6Q.png" /></figure><p>We are pleased to announce support for OCI <a href="https://www.oracle.com/artificial-intelligence/generative-ai/generative-ai-service">Generative AI Service</a> in <a href="https://docs.langchain4j.dev/integrations/language-models/oci-genai">LangChain4j.</a> If you recall, we announced Helidon integration with LangChain4j in a <a href="https://medium.com/helidon/helidon-4-2-released-fa94afe4945a">previous post</a>. There is also an 8-parts lab that walks you through building a RAG using an embedding store of your choice.</p><p>Now, there were already support for Oracle DB and Coherence as Vector stores in LangChain4j but no support yet for OCI Generative AI Service. Launched last year, the latter has steadily gained in features, capability and most importantly, a bulging set of LLMs, including Cohere, Llama and <a href="https://www.linkedin.com/events/7338992302243094528/comments/">announced yesterday</a>: xAI’s grok models. With dedicated AI clusters, you can even host foundational models on dedicated GPUs that are private to you. These clusters provide stable, high-throughput performance that’s required for production use cases and can support hosting and fine-tuning workloads. Clearly, <a href="https://www.linkedin.com/in/rishi-johari-920448a/">Rishi Johari</a> is cooking something special again.</p><p>In this contribution to LangChain4j, there is support added for various chat models available. The API is separated for Cohere and Meta models as their respective configuration differs. You can also choose between streaming and normal chat models.</p><p>The following were added:</p><p>Meta models:</p><ul><li>OciGenAiChatModel - for all OCI GenAi generic chat models(llama)</li><li>OciGenAiStreamingChatModel - streaming API for generic chat models</li></ul><p>Cohere models:</p><ul><li>OciGenAiCohereChatModel - for all OCI GenAi Cohere chat models</li><li>OciGenAiCohereStreamingChatModel - streaming Cohere chat models</li></ul><p>To use OCI GenAI models over the usual LangChain4j API, add the following dependencies:</p><pre>&lt;dependency&gt;<br>  &lt;groupId&gt;dev.langchain4j&lt;/groupId&gt;<br>  &lt;artifactId&gt;langchain4j&lt;/artifactId&gt;<br>  &lt;version&gt;1.1.0&lt;/version&gt;<br>&lt;/dependency&gt;<br>&lt;dependency&gt;<br>  &lt;groupId&gt;dev.langchain4j&lt;/groupId&gt;<br>  &lt;artifactId&gt;langchain4j-community-oci-genai&lt;/artifactId&gt;<br>  &lt;version&gt;1.1.0-beta7&lt;/version&gt;<br>&lt;/dependency&gt;<br>&lt;dependency&gt;<br>  &lt;groupId&gt;com.oracle.oci.sdk&lt;/groupId&gt;<br>  &lt;artifactId&gt;oci-java-sdk-common-httpclient-jersey3&lt;/artifactId&gt;<br>  &lt;version&gt;3.67.1&lt;/version&gt;<br>&lt;/dependency&gt;</pre><p>You also have to select an HTTP client for OCI SDK, which by default, use a Jersey 3 based version as shown above(<a href="https://docs.oracle.com/en-us/iaas/Content/API/SDKDocs/javasdk3.htm#javasdk3__HTTP-client-libraries">more about SDK clients</a>).</p><p>If you have worked with LangChain4j before, usage is straight forward. Configure your OCI Generative AI model and setup LangChain4j Assistant with tools and chat memory and you are good to go!</p><pre>public static void main( String[] args ) throws IOException {<br><br>    ChatModel model = OciGenAiCohereChatModel.builder()<br>            .modelName(&quot;cohere.command-r-08-2024&quot;)<br>            .compartmentId(&quot;ocid1.tenancy.oc1..aa...&quot;) // your compartment id<br>            .authProvider(new ConfigFileAuthenticationDetailsProvider(&quot;DEFAULT&quot;))<br>            .maxTokens(600)<br>            .temperature(0.2)<br>            .topP(0.75)<br>            .build();<br><br>    Assistant assistant = AiServices.builder(Assistant.class)<br>            .chatModel(model)<br>            .tools(new Calculator()) // class with tool method<br>            .chatMemory(MessageWindowChatMemory.withMaxMessages(10))<br>            .build();<br><br>    String answer = assistant.chat(&quot;Calculate square root of 16&quot;);<br>    System.out.println(answer);<br>}<br><br>public interface Assistant {<br>    String chat(String question);<br>}<br><br>public static class Calculator {<br>    @Tool(&quot;Calculates a square root of a given number.&quot;)<br>    double sqrt(double x) {<br>        return Math.sqrt(x);<br>    }<br>}</pre><p>Note that any Java project using LangChain4j can also use the above to integrate OCI Generative AI. We are generous like that.</p><p>We are also working on a number of new enhancements to make using LangChain4j and Helidon together easier. Until then, stay tuned.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a0ac550579a2" width="1" height="1" alt=""><hr><p><a href="https://medium.com/helidon/announcement-adding-oci-generative-ai-support-to-langchain4j-and-helidon-a0ac550579a2">Announcement: Adding OCI Generative AI Support to LangChain4j and Helidon</a> was originally published in <a href="https://medium.com/helidon">Helidon</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Helidon and AOT startup optimization benchmark]]></title>
            <link>https://medium.com/helidon/helidon-and-aot-startup-optimization-benchmark-71bffe29eb32?source=rss-da9068633ebd------2</link>
            <guid isPermaLink="false">https://medium.com/p/71bffe29eb32</guid>
            <category><![CDATA[helidon]]></category>
            <category><![CDATA[aot]]></category>
            <category><![CDATA[graalvm-native-image]]></category>
            <category><![CDATA[leyden]]></category>
            <category><![CDATA[cracs]]></category>
            <dc:creator><![CDATA[Daniel Kec]]></dc:creator>
            <pubDate>Wed, 26 Mar 2025 16:07:06 GMT</pubDate>
            <atom:updated>2025-03-26T16:07:06.730Z</atom:updated>
            <content:encoded><![CDATA[<p><em>Leyden vs. Native Image vs. CRaC, which makes Helidon start faster?</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*aGHO6diG07m7GJa7.png" /></figure><p>It is a great time to be a Java developer! Java ecosystem is thriving, and we have so many great tools to choose from. There is an old cliché about Java long startup time. It’s not true anymore, but yes it can take some time to get at the full power after our Java application started. It’s by design, Java applications are utilizing JIT, Just In Time compilation to the native code. This is happening at runtime and with a good reason, because based on the workload, JIT can actually optimize compiled native code. And what is more, it can do it speculatively! Rollback previous optimizations if it’s heuristics find the way it can be optimized better, based on change in the workload for example.</p><p>But there are ways how we can speed up the startup and the warming up phase dramatically. Three most promising technologies available are:</p><ul><li><a href="https://openjdk.org/projects/leyden/">Leyden project</a></li><li><a href="https://www.graalvm.org/latest/reference-manual/native-image/">GraalVM Native Image</a></li><li><a href="https://crac.org/">Coordinated Restore and Checkpoint (CRaC)</a></li></ul><h3>Leyden</h3><p>As written on the project page, primary goal of <a href="https://openjdk.org/projects/leyden/">OpenJDK project Leyden</a> is to improve the startup time, time to peak performance, and footprint of Java programs. It uses several approaches for achieving the goal, but the most interesting with the latest <a href="https://jdk.java.net/leyden/">EA build</a> is caching the optimization data in CDS(Cached Data Storage) files. You can start your application for a CDS recording <a href="https://openjdk.org/projects/leyden/notes/05-training-runs">training run</a>, do a “warmup” and then save the CDS archive for later use. When you use it, your application starts way faster and already optimized!</p><p>The JDK team is working to add more advanced AOT optimizations to the Leyden prototype using the framework introduced in <a href="https://openjdk.org/jeps/483">JEP 483</a>, with the hope that these optimizations will eventually be available in future JDK releases.</p><h3>GraalVM Native Image</h3><p><a href="https://www.graalvm.org/latest/reference-manual/native-image/">GraalVM Native Image</a> is a technology coming from <a href="https://labs.oracle.com/">Oracle Labs</a> to provide a way of AOT native compilation, it means that you create a platform dependent binary. You don’t need JDK to run it and its starts almost instantly as most of the loading and starting actually happened during the AOT build time. There is small drawback as Native Image binaries don’t have JIT(nothing more to compile), and AOT optimizations can’t really optimize for actual workload.</p><p>But there is another card in the stack of cool features <a href="https://www.graalvm.org/">GraalVM</a> has in its pocket, you can do AOT compilation twice! It is called <a href="https://www.graalvm.org/latest/reference-manual/native-image/guides/optimize-native-executable-with-pgo/">Profile-Guided Optimization(PGO)</a>, it provides a way of doing first AOT compilation, then instrumented warmup training — similar to Leyden training, and use training profile data stored in the iprof file for a second AOT compilation.</p><h3>CRaC</h3><p><a href="https://crac.org/">Coordinated Restore and Checkpoint (CRaC)</a> is a way of snapshotting running JVM. It is a technology coming from <a href="https://www.azul.com/products/components/crac/">Azul Systems</a> and was until recently based on <a href="https://criu.org/">CRIU</a> a project to implement checkpoint/restore functionality for Linux(you are probably using it very often with Podman or Docker). Not long ago a <a href="https://foojay.io/today/warp-the-new-crac-engine/">new CRaC engine called Warp</a> was introduced by Azul and that brings very exciting ability to do snapshotting in a docker build phase.</p><h3>Helidon</h3><p>Helidon is a microservice framework, and it matters if you can start your pod fast, you can scale up more effectively and avoid burning more resources than necessary. We have supported <a href="https://helidon.io/docs/v4/mp/guides/graalnative">GraalVM Native Image</a> for years now, but as there are more players in the field, <a href="https://helidon.io/docs/v4/mp/guides/crac"><strong>Helidon 4.2.0 adds support for CRaC</strong></a>. Leyden doesn’t need a any special support at all so you can easily use any of the available 3 options, and it also provides unique opportunity to benchmark AOT optimizations with Helidon application!</p><p>Before we get to the results lets introduce the way of benchmarking we have chosen. To make the benchmark close to business like use-case, we will do the warmup/training during docker build phase. That is actually a very practical way how to leverage AOT optimization, simply by creating a Docker image with AOT pre-trained Helidon application.</p><h3>Benchmarking AOT with Helidon</h3><p>Benchmark is prepared as a set of docker files, each creating docker image with AOT pre-warmed Helidon application, application is a very simple Hello World example. Warming/training of the application is done by sending large number of requests to the application endpoint via <a href="https://github.com/wg/wrk">wrk</a> load test tool. Image is created each time for both flavors of Helidon, super fast, super simple SE flavor and MP a CDI runtime. For having a baseline vanilla OpenJDK 23 version is measured too.</p><p>Native Image is measured twice, normal AOT build without warmup/training and build with <a href="https://www.graalvm.org/latest/reference-manual/native-image/guides/optimize-native-executable-with-pgo/">Profile-Guided Optimization(PGO)</a>.</p><ul><li><strong>Vanilla</strong> — Clean OpenJDK 23 with no AOT warmup as a baseline</li><li><strong>Leyden</strong> — Leyden project <a href="https://jdk.java.net/leyden/">EA build</a> with warmup/training during build phase</li><li><strong>Native Image</strong> — <a href="https://www.graalvm.org/latest/reference-manual/native-image/">GraalVM Native Image</a> no warmup just AOT native image binary build in Docker build phase</li><li><strong>Native Image </strong><a href="https://www.graalvm.org/latest/reference-manual/native-image/guides/optimize-native-executable-with-pgo/"><strong>PGO</strong></a> — native image binary with profile guided optimization warmup/training in Docker build phase</li><li><strong>CRaC </strong>— <a href="https://crac.org/">Coordinated Restore and Checkpoint (CRaC)</a> CRaC snapshot created during Docker build phase</li></ul><p>Lets break down what is measured and when, first we do a measurement in the build phase, measuring how long it takes to build the application with the AOT, how fast it starts for warmup and how many requests per second it manages to handle during the warmup/training. Second, we measure the startup time of the optimized application, then we do short 5 second load test with <a href="https://github.com/wg/wrk">wrk tool</a> to figure out how actually pre-warmed is our freshly started application. The test is only 5 seconds long, so we don’t give JIT compiler much time to further optimize. Last test is another wrk load test, this time for 15 second to se if application can optimize further.</p><h3>Build phase:</h3><ul><li><strong>Warmup start</strong> — measuring how long it takes to start the app for the training/warmup, instrumented or not</li><li><strong>Warmup req/s</strong> — measuring how many requests per seconds is application able to serve during the warmup using <a href="https://github.com/wg/wrk">wrk tool</a> wrk -c 20 -t 10 -d 20s <a href="http://localhost:8080/">http://localhost:8080</a></li><li><strong>AOT/build sec</strong> — measuring the build phase time in seconds, including warmup/training which takes 20 seconds</li></ul><h3>Run phase:</h3><ul><li><strong>Startup ms</strong> — measuring startup time of the AOT optimized pre-warmed application</li><li><strong>5s run req/s</strong> — first short requests per second measurement, 5 seconds long designed to show how optimized application is right after start, before JIT has the chance optimize much further. wrk parameters used: wrk -c 20 -t 10 -d 5s <a href="http://localhost:8080/">http://localhost:8080</a></li><li><strong>15s run req/s</strong> — second longer requests per second measurement, meant to show if and how is application able to optimize further during the runtime. wrk parameters used: wrk -c 20 -t 10 -d 15s <a href="http://localhost:8080/">http://localhost:8080</a></li></ul><h3>Results</h3><p>Here are the results from March 7th benchmark execution round 2025030701, and we can see it’s quite interesting.</p><h4>Helidon SE Application</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f9eee7050db4beb039b9d30f9778dc12/href">https://medium.com/media/f9eee7050db4beb039b9d30f9778dc12/href</a></iframe><h4>Helidon MP Application</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f4ce41d89d5144881c0e25d50f0a5948/href">https://medium.com/media/f4ce41d89d5144881c0e25d50f0a5948/href</a></iframe><h3>AOT optimized startup time</h3><p>First and most interesting is the startup time, how is AOT optimization helping? Less is better. Out of all the options Native Image with PGO seems to be the fastest, with normal Native Image and CRaC closely following. You can however notice that with more heavyweight MP version of our application the race is much closer. Leyden takes longer but still cuts the startup time in more than half, and that is quite impressive too, especially because no special support in Helidon nor in the app itself is really needed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*tL8a-VDPBrhmhPOD.png" /><figcaption>log scale, lower is better</figcaption></figure><h3>Short load test</h3><p>And how is our AOT optimized application doing with performance right after start? This time more is better, more requests per second means more powerful application we have. First short test is meant to test the performance before JIT optimization has a chance to optimize any further.</p><p>Once again Native Image with PGO is leading the race with Helidon SE application. Native Image with CRaC following closely. This time, with Helidon MP application, is situation changing on second place and CRaC is getting faster than Native Image without PGO.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*F74E1aO5-hBeCIGB.png" /><figcaption>linear scale, more is better</figcaption></figure><h3>Long load test</h3><p>Second test gives some more time to the JIT to further optimize. Interesting is that Native Image with PGO still leads, but normal Native Image gets behind Vanilla JDK and Leyden. Yes JDK without any extra AOT is catching on already! And with Helidon MP application JDK takes down even the Native Image with PGO!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*cidrKOOjOy-POQVO.png" /><figcaption>linear scale, more is better</figcaption></figure><h3>AOT build time</h3><p>How long it gets to actually do a build with AOT optimization? Now shorter is better. This is where JDK without AOT obviously shines. From the AOT options CRaC is the winner, creating the snapshot is fast. Instrumented runs of Leyden and compiling everything in advance in case of Native Image is time-consuming.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*J0VWqyrOGUELld07.png" /><figcaption>log scale, lower is better</figcaption></figure><h3>Conclusion</h3><p>All the options are actually super cool, Java ecosystem is after 30 years livelier than ever! There is some interesting findings in this benchmark.</p><ul><li><strong>Leyden</strong> — Build 24-leyden+2–8 (2024–6–20) we have tested is still EA, and Leyden gets better and better over time. Some features in Leyden have been integrated into the JDK mainline repository and will become available in JDK 24 via <a href="https://openjdk.org/jeps/483">JEP 483: Ahead-of-Time Class Loading &amp; Linking</a>. We will definitely test it in the next round of the benchmark! What is most interesting is that from all the options, Leyden doesn’t need any special treatment from your application or libraries you are using.</li><li><strong>Native Image</strong> — I was quite surprised by PGO performance! Those numbers just speak for themselves. What can get quite tricky is making your application compatible with Native Image, it can take some time to figure out what should be invoked at build time and what not, where is reflection used so aggressive tree-shaking doesn’t throw away something important and so on. Also from all the options, native image binary is the only one which doesn’t need JDK to run, that can make your docker images tiny and efficient.</li><li><strong>CraC</strong> — CRaC has got really cool with new <a href="https://foojay.io/today/warp-the-new-crac-engine/">Warp engine</a>, now you can do snapshot even in the docker build! You have to look for any opened IO in your application and close it before snapshot is done. Also, application is performing just like normal JDK run app before snapshotting unlike the instrumented runs of Leyden or Native Image PGO.</li></ul><p>Your Helidon application can start even faster, your pods scale quicker, and you got quite some options!</p><p><a href="https://github.com/helidon-io/helidon-labs/tree/main/benchmarks/startup">Benchmark project</a> can be found in <a href="https://github.com/helidon-io/helidon-labs">Helidon Labs repository</a>. Benchmark round 2025030701 was executed on <a href="https://www.oracle.com/cloud/">OCI</a> VM.Standard3.Flex VM with following specs.</p><pre>Image:               Oracle-Linux-8.10-2025.01.31-0<br>Model name:          Intel(R) Xeon(R) Platinum 8358 CPU @ 2.60GHz<br>Architecture:        x86_64<br>CPU(s):              32<br>Memory (GB):         64</pre><p>Original version of the article can be found on my blog: <a href="https://danielkec.github.io/blog/helidon/leyden/native-image/crac/2025/03/07/helidon-aot.html">https://danielkec.github.io/blog/helidon/leyden/native-image/crac/2025/03/07/helidon-aot.html</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=71bffe29eb32" width="1" height="1" alt=""><hr><p><a href="https://medium.com/helidon/helidon-and-aot-startup-optimization-benchmark-71bffe29eb32">Helidon and AOT startup optimization benchmark</a> was originally published in <a href="https://medium.com/helidon">Helidon</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Helidon and Virtual Threads]]></title>
            <link>https://medium.com/helidon/helidon-and-virtual-threads-91d4e9bcb55c?source=rss-da9068633ebd------2</link>
            <guid isPermaLink="false">https://medium.com/p/91d4e9bcb55c</guid>
            <category><![CDATA[helidon]]></category>
            <category><![CDATA[netty]]></category>
            <category><![CDATA[virtual-threads]]></category>
            <category><![CDATA[java]]></category>
            <category><![CDATA[reactive-programming]]></category>
            <dc:creator><![CDATA[Daniel Kec]]></dc:creator>
            <pubDate>Thu, 30 Jan 2025 11:45:47 GMT</pubDate>
            <atom:updated>2025-02-02T23:39:04.506Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1023/0*Q5OeK1yfSKvDO-2n.png" /></figure><p>A lot has been written about Virtual Threads in Java, but what is the real-life usage, where do they excel? Let’s take a look at Virtual Threads from a web server perspective.</p><h3>Expensive Threads</h3><p>Starting kernel thread is very expensive, that is a performance problem for all web servers. Every kernel thread created by JVM needs megabytes of off-heap memory. It takes quite a lot of time to create a physical thread and a lot of memory is required which we can’t really limit or manage.<br>This issue can be partially fixed by pooling the threads so we can reuse those already started. Instead of starting new thread each time we need one, we can reach in a pool where we leave already used threads.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/0*VcFU6D1FyTHvxmWN.jpg" /><figcaption>Threadpool</figcaption></figure><p>But using thread pools is not enough, as web server usually needs more threads than there are CPUs available. The threads need to take turns on the available cores, and they need to be organized and scheduled to run on those CPUs.</p><p>Scheduling of the kernel threads on the CPU is done by operating system scheduler, and as you can imagine, OS scheduler is pretty busy. To help with effective work scheduling the threads can cooperatively <em>yield</em> each time there is nothing to do, like when waiting for IO to respond or when sleep instruction is executed. Or thread is preemptively interrupted to achieve effective time-slicing. So instead of “burning CPU” just to wait, other threads have a chance to run it’s business on the CPU.</p><p>Scheduler exchanges the threads running on the CPU in a process known as <a href="https://en.wikipedia.org/wiki/Context_switch">Context switching</a>. During this process, a lot of overhead needs to be done to keep the thread state for later and it’s a lot of work to move around registers and stack pointers. As you can imagine this process can be quite expensive and can get even more expensive when we have a lot of physical threads.</p><h3>Non-Blocking code</h3><p>For that reason we have been trying to come up with a way of scheduling work directly in Java ourselves. We know way better the context of what needs to be executed and when. By scheduling the work ourselves we can keep low amount of physical threads very, very busy, <strong>not letting them block</strong> and therefore not giving them much chance for context-switching.</p><p>To avoid blocking, asynchronous coding needs to be used. Code never waits for anything, each result we need to wait for is executed on different thread. Instead of blocking, callback function needs to be provided, so some other thread can execute it.</p><p>As a direct result of avoiding blocking, we are loosing natural backpressure. You need to think about, how to signal the calling side, that we are unable to process more callbacks, how to do a flow-control.</p><p>Callbacks are executed on different threads, order of execution is … there is no order. The situation is called callback hell, and for taming it, to manage and work with callbacks reactively, we can use Reactive Operators.</p><h3>Reactive Operators</h3><p>Reactive Streams is a set of APIs for orchestration of callbacks with built-in backpressure mechanism. API is even part of the JDK since Java 9, you can find it in <a href="https://docs.oracle.com/en/java/javase/21/docs/api/java.base/java/util/concurrent/Flow.html">java.util.concurrent.Flow</a> class. It brings order to the callback hell by a set of very strict rules, but be aware, while the interfaces seems to be fairly simple, the <a href="https://github.com/reactive-streams/reactive-streams-jvm/blob/master/README.md">specification</a> rules are ridiculously complicated. So complicated that when you try to implement the interfaces yourself IntelliJ warns you off!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/726/0*-fzYfYxY53m9l7na.png" /></figure><p>Instead of implementing it, you can use existing, highly optimized libraries providing reactive primitives with operators implementing Reactive Streams, usually in a builder like pattern.</p><p>Just to mention few:</p><ul><li><a href="https://github.com/ReactiveX/RxJava">RxJava</a> — Famous library from <a href="https://github.com/akarnokd">David Karnok</a>.</li><li><a href="https://github.com/reactor/reactor-core">Reactor</a> — Implementation that comes with Spring also from David Karnok among others .</li><li><a href="https://github.com/apple/servicetalk">Service-Talk</a> — Apple’s implementation.</li><li><a href="https://helidon.io/docs/v4/se/reactivestreams/engine">Helidon</a> — Our own Helidon implementation also contributed by David Karnok.</li><li><a href="https://quarkus.io/guides/mutiny-primer">Mutiny</a> — Quarkus, RedHat.</li></ul><p>Reactive handler for HTTP GET method in Helidon 3 SE used to look like this:</p><pre>.get(&quot;/callOtherService&quot;, (req, res) -&gt; {<br>    // Server thread is used just for sending request and setting up the callback<br>    seClient.get()<br>            .request(JsonObject.class)<br>            .map(jo -&gt; jo.getString(&quot;status&quot;))<br>            .map(String::toUpperCase)<br>            .onError(res::send)<br>            .forSingle(s -&gt; {<br>                // When client response comes on it’s own thread, <br>                // callbacks in reactive operators converts it and send the response.<br>                // Server response is actually sent by client’s thread!<br>                res.send(s); <br>            });<br>            // Server thread doesn’t wait for anything and is released/yielded back to event-loop<br>        })</pre><p>No blocking was allowed, for calling another service, reactive client had to be used. You can see the operator usage in above example as Helidon’s APIs used reactive operators.</p><p>With reactive paradigm our Java experience changed into a more manageable callback orchestration, our code started to resemble source code from the “Matrix” movie.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/0*j50YBQxvSMz63zvT.png" /><figcaption>Reactive Operators</figcaption></figure><p>Sadly, unlike in the movie, you won’t start to see the meaning in the code if you stare at reactive operators long enough. Actually if you bump into your own reactive code after few weeks, it’s hard to figure out what is going on. Reactive programming has a steep learning curve, it is very hard to maintain and debug. And if you need to use blocking code, you need to start a new thread and offload the blocking operation to it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/0*8HLTH5GXlQNDCPbb.png" /></figure><p>Just imagine how hard it is to explain your reactive codebase to a new junior intern who just joined your company. And how much easier it would be to explain simple imperative-blocking code base!</p><h3>Virtual Threads</h3><p>With Virtual Threads it gets easy again, Virtual Threads are doing exactly same trick, avoiding Context Switching by moving the work scheduling to JVM. Closer to the context of our JVM workload, but it is no longer a job of developers to plan it with callbacks like with reactive programming.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/0*tFDcVi8iJMovI8_U.png" /></figure><p>With Virtual Threads you get the same performance advantages like with reactive coding, just the coding part is much nicer since you can use the imperative coding style, and the magic happens behind the scenes.</p><p>Let’s get back to our example, this time with Helidon 4 SE, again we have a handler for HTTP GET method. This time the code is blocking, easy to understand and debug. Definitely easier to explain to someone.</p><p>Imperative handler for HTTP GET method in Helidon 4 SE:</p><pre>.get(&quot;/callOtherService&quot;, (req, res) -&gt; {<br>        // Server virtual thread is blocked until response is received<br>        String status = nimaClient.get()<br>                .request(JsonObject.class)<br>                .getString(&quot;status&quot;);<br>        <br>        // When client response comes, original handler thread continues<br>        String upperCaseStatus = status.toUpperCase();<br>        <br>        // Original thread is used for sending response<br>        res.send(upperCaseStatus);<br>    });</pre><p>Because all Helidon 4 handlers are executed on virtual threads, blocking the thread is not a problem. In above example, when client is blocking Virtual Thread until it receive response, virtual thread <strong>yields</strong> it’s “Carrier Thread” so it can be used by other virtual thread. How does that work?</p><p>Let’s take a look in <a href="https://github.com/openjdk/jdk/blob/672c413c61d9b155020a0fd4bd1c2bc0661a60fb/src/java.base/share/classes/java/lang/Thread.java#L479">java.lang.Thread</a> how for example sleep instruction does something else for virtual threads:</p><pre>public static void sleep(long millis) throws InterruptedException {<br>    if (millis &lt; 0) {<br>        throw new IllegalArgumentException(&quot;timeout value is negative&quot;);<br>    }<br>    long nanos = MILLISECONDS.toNanos(millis);<br>    sleepNanos(nanos);<br>}<br><br>private static void sleepNanos(long nanos) throws InterruptedException {<br>        ThreadSleepEvent event = beforeSleep(nanos);<br>        try {<br>            if (currentThread() instanceof VirtualThread vthread) {<br>                vthread.sleepNanos(nanos);<br>            } else {<br>                sleepNanos0(nanos);<br>            }<br>        } finally {<br>            afterSleep(event);<br>        }<br>    }</pre><p>If you follow that a little deeper in <a href="https://github.com/openjdk/jdk/blob/672c413c61d9b155020a0fd4bd1c2bc0661a60fb/src/java.base/share/classes/java/lang/VirtualThread.java#L540">java.lang.VirtualThread</a>, you are going to find yieldContinuation() method.</p><pre>   /**<br>     * Invokes Continuation.yield, notifying JVMTI (if enabled) to hide frames until<br>     * the continuation continues.<br>     */<br>    @Hidden<br>    private boolean yieldContinuation() {<br>        notifyJvmtiUnmount(/*hide*/true);<br>        try {<br>            return Continuation.yield(VTHREAD_SCOPE);<br>        } finally {<br>            notifyJvmtiMount(/*hide*/false);<br>        }<br>    }</pre><p>And that is the trick, Virtual Threads are an implementation of <strong>Continuations</strong> in Java, and all known blocking operations in JDK are aware of them! This is a feature that Go developers have had for some time, and it is finally available in Java!</p><p>The actual scheduler used for mounting virtual threads on top of a physical threads(called by fancy term “carrier threads”) is a marvelous and battle-proven piece of code <a href="https://github.com/openjdk/jdk/blob/672c413c61d9b155020a0fd4bd1c2bc0661a60fb/src/java.base/share/classes/java/lang/VirtualThread.java#L1416">ForkJoinPool</a>.</p><h3>Green Threads</h3><p>The history of ForkJoinPool is quite cool, and it stretches all the way back to the time when Green Threads were removed from JDK. <a href="https://en.wikipedia.org/wiki/Green_thread">Green threads</a> were very similar to modern virtual threads, but there was a big difference. Green threads were scheduling work over single physical thread. So the tasks never really ran in parallel, they were just multiplexing over a single physical thread.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/262/0*YprSu9CvcyjAVSYz.png" /></figure><p>Green Threads were eventually removed in 2000 with release of JDK 1.3, and we got stuck with physical threads abstraction. But as you can see from the timeline below, <a href="https://en.wikipedia.org/wiki/Doug_Lea">Doug Lea</a> — Java Concurrency demigod, didn’t wait for anything and published his paper <a href="https://www.researchgate.net/publication/2609854_A_Java_ForkJoin_Framework">Java Fork/Join Framework</a>. Doug Lea’s implementation of the <a href="https://docs.oracle.com/en/java/javase//21/docs/api/java.base/java/util/concurrent/ForkJoinPool.html">ForkJoinPool</a> found its way to JDK in 2011 with JDK 7 release.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/0*TI86s9R6KTMAIYDu.jpg" /></figure><p>Now, since JDK 21 release, we have Continuations in Java and scheduling is done by ForkJoinPool. But it still sounds like a context switching right? It still is, but this time it doesn’t have to be so abstract, and we have a battery of cool performance tricks available. Instead of expensive OS scheduled context switching, we have highly performant scheduling tailored to the Java runtime needs.</p><h3>Freezing and Thawing</h3><p>The process of mounting and unmounting Virtual Thread context from carrier threads is called Thawing and Freezing. We can find some very cool performance tricks making Virtual Threads so effective there.</p><p>Let’s show it on a hypothetical simplistic server, we can call it for example Helidon 😊:</p><pre>startServer() {<br>    while (!notClosed) {<br>        readSocket();<br>    }<br>}</pre><p>It’s a very typical endless conditional loop calling repeatedly blocking method readSocket(), stack of the socket will look something like this:</p><pre>runContinuation()<br>io.helidon....<br>io.helidon....<br>io.helidon....<br>startServer()<br>readSocket()<br>yieldContinuation()</pre><p>Each time there is no new data available on the socket, yieldContinuation() is going to be reached by virtual thread and virtual thread is going to be unmounted from carrier thread. It’s context is going to be frozen until the virtual thread is scheduled to run again on some of the carrier threads and the context is thawed.</p><p>The cool part is that we don’t have to save and freeze the whole stack, only the part related to the virtual thread. But that is not all, we also don’t have to move around all the frames, as you can see, our hypothetical server rarely reaches outside the endless loop and blocking also happens mainly in the loop. So optimizing thawing process to freeze/thaw only the part of the stack related to the calls inside the loop offers itself.</p><p>It is done with a <a href="https://github.com/openjdk/jdk/blob/672c413c61d9b155020a0fd4bd1c2bc0661a60fb/src/hotspot/share/runtime/continuationFreezeThaw.cpp#L129">return barrier</a>, that is a stack frame surrogate which lazily thaws more stack frames(stack chunks) when needed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*lIAAZ8evjXq6Srcz.gif" /></figure><p>That way even smaller parts of the stack are being moved around. And that is not all, frozen stack chunks stored in heap are being compressed when not used, further reducing the memory needed for running our little hypothetical server.</p><p>All these behind the scenes tricks are there to give us back imperative coding style, so we can concentrate on the business problems instead of complicated reactive code style. It is a same performance trick, just easier to use.</p><h3>Helidon 4</h3><p>Helidon is a server, high concurrency is it’s daily bread. As we already stated above in the article, avoiding expensive context switching is paramount for Helidon to provide the best possible starting point for business code.</p><p>Helidon used to be a reactive runtime based on <a href="https://netty.io/">Netty</a> library. Netty is extremely fast and performant library for using sockets asynchronously in Java. That is great for web servers but with one steep downside: as Netty is asynchronous, its APIs are considerably complicated and that is why all the Netty based runtimes are reactive. But reactive APIs are viral, you can’t abstract them away without losing performance. For this reason we have been looking for Virtual Threads coming to Java with great hopes. Right after release of Java 21, we have released Helidon 4 fully leveraging this new exciting feature.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/0*QCepwRJgKx7r5weo.png" /></figure><p>For Helidon 4 we have developed brand new web server to avoid the necessity to use reactive APIs to gain performance. This new web server with code-name Níma is based on Virtual Threads and <strong>completely replaces Netty</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/0*bm-D-RNVWsZ6VMgM.png" /></figure><p>It brings performance on par with Netty based reactive runtimes, while using an imperative and therefore a simpler coding style. Using Virtual Threads simply for allowing blocking code would also be possible with Netty by offloading work to Virtual Threads from reactive handlers, and that is what “Virtual Threads support” means in many Netty based runtimes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/0*YXneMYDTmvlO-5Fy.png" /></figure><p>Helidon 4 uses clean, imperative code from the ground up. All the way from socket to your handler, web server is almost absurdly simple in comparison with extremely complicated reactive web servers. This simplicity is only possible thanks to Virtual Threads allowing blocking code to avoid expensive context switches without all the pain of using reactive APIs.</p><h3>Conclusion</h3><p>Virtual Threads are doing the same trick as reactive coding but without the burden of additional complexity. Like with reactive code, Virtual Threads are not a silver bullet for solving all your performance issues. It won’t make your CPU magically faster, it just removes a lot of bureaucracy which is slowing you down in use-ceases with high contention and blocking. Use-cases typical for web servers.</p><blockquote>Link to the original article: <a href="https://danielkec.github.io/blog/helidon/virtual-threads/concurrency/2024/10/07/helidon-vitual-threads.html">https://danielkec.github.io/blog/helidon/virtual-threads/concurrency/2024/10/07/helidon-vitual-threads.html</a></blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=91d4e9bcb55c" width="1" height="1" alt=""><hr><p><a href="https://medium.com/helidon/helidon-and-virtual-threads-91d4e9bcb55c">Helidon and Virtual Threads</a> was originally published in <a href="https://medium.com/helidon">Helidon</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Evil of FatJar]]></title>
            <link>https://medium.com/helidon/evil-of-fatjar-3c3011b4bd55?source=rss-da9068633ebd------2</link>
            <guid isPermaLink="false">https://medium.com/p/3c3011b4bd55</guid>
            <category><![CDATA[new-year-resolution]]></category>
            <category><![CDATA[java]]></category>
            <category><![CDATA[microservices]]></category>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[helidon]]></category>
            <dc:creator><![CDATA[Daniel Kec]]></dc:creator>
            <pubDate>Thu, 11 Jan 2024 13:49:13 GMT</pubDate>
            <atom:updated>2024-01-18T15:24:39.366Z</atom:updated>
            <content:encoded><![CDATA[<p>It’s 2024! Use ThinJar!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8-fb8lgdqgSSGnMrBWj9yA.jpeg" /></figure><p>FatJars have been with us for a long time now. At first, they enabled Java apps to be distributed as a single jar archive, without any hassle about the dependency jars. But how is that achieved? By repackaging all the dependencies! Repackaging not only breaks the Java module system, but also considerably slows down your CI/CD pipeline!</p><h3>FatJar</h3><p>Fatjar is a way of packaging java applications in a single jar, all classes from all the dependencies are repackaged in a single new jar.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/389/1*Vv1QYP3C2BOCEue1N5djtw.png" /><figcaption>FatJar with all dependencies repackaged</figcaption></figure><p><strong>Pros:</strong></p><ul><li>Easy distribution and deployment</li></ul><p><strong>Cons:</strong></p><ul><li>One large archive</li><li>Unable to exclude third party dependencies</li><li>Forces us to create a large container image layer</li><li>Breaks Java modules</li><li>Breaks CDI beans archive descriptors</li></ul><h3>ThinJar</h3><p>ThinJar is just a fancy name for keeping all your dependencies in accompanying <strong>/lib folder</strong>. Very same approach as statically linked libraries in C programs.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/911/1*NcoukmtMufHyV_gOS15dIw.png" /><figcaption>ThinJar with MANIFEST defined classpath</figcaption></figure><p><strong>Pros:</strong></p><ul><li>Exclusion of the third party dependencies is easy</li><li>Small jar archive</li><li>Fine-grained container image layering</li><li>Java modules friendly</li><li>CDI archives friendly</li></ul><p><strong>Cons:</strong></p><ul><li>More hassle when setting up the classpath</li></ul><h3>Container image</h3><p>Who is who becomes clear when creating a container image. With a FatJar, you have no choice and need to copy the whole jar at once:</p><pre>COPY --from=build /helidon/target/quickstart.jar ./</pre><p>With thinjar, you can copy the dependencies to the container image in a standalone step.</p><pre>COPY --from=build /helidon/target/libs ./libs<br>COPY --from=build /helidon/target/quickstart.jar ./</pre><p>As the dependencies are being copied to the container image in a standalone step, it also gets <strong>cached separately</strong>. The next time, you fix something and just change the business code, you don’t actually need to push all the unchanged dependencies to your image repository. You push just a small archive, saving your time and bandwidth.</p><p>Let’s compare it with a quick demo.</p><pre>git clone git@github.com:danielkec/thinjar-vs-fatjar.git<br>cd thinjar-vs-fatjar<br>docker build -t helidon/demo-thinjar . -f Dockerfile<br>docker build -t helidon/demo-fatjar . -f Dockerfile.fatjar</pre><p>When we compare history of each image:</p><pre>docker history helidon/demo-fatjar:latest</pre><p>We can see that FatJar creates a single 2Mb large layer.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/712/1*wzFL53BEejmP5V6vNKZmmQ.png" /></figure><p>While ThinJar creates two layers: a large one with dependencies only, and small one with just the business code.</p><pre>docker history helidon/demo-thinjar:latest</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/709/1*VpQNbgxXsKc0vbX4KLZ3wA.png" /></figure><p>Now let’s do just a small change and rebuild both images.</p><pre>sed -i &quot;s/^app.greeting=.*/app.greeting=Bonjour/&quot; src/main/resources/application.properties<br>docker build -t helidon/demo-thinjar . -f Dockerfile<br>docker build -t helidon/demo-fatjar . -f Dockerfile.fatjar</pre><p>From the output you can already see that ThinJar image cached all the dependencies because nothing changed there.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/697/1*YoqFoaLK1KrnS8HSjfna7g.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/706/1*h-vdfCJby3iT-0G3kHacfQ.png" /></figure><p>While FatJar image had to create a new layer with all the dependencies again.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/866/1*n_isf9Ht6eVQxE573NRvGA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/739/1*6xaG2fCCaeSZPLIgg3DBsQ.png" /></figure><p>Single small change in a super small FatJar packaged application forces you to unnecessarily push 2Mb? Can you hear devops complaining already?</p><h3>Conclusion</h3><p>ThinJar is far more suitable for microservice development, pushing changes to remote repositories will be faster and your CI/CD pipelines happier!</p><p>Helidon is from the start designed to be delivered in a thinjar, just try out <a href="https://helidon.io/starter">Helidon’s starter</a>, everything works out of the box.</p><p>Let our New Year’s resolution to be this: Use ThinJar! Our devops will be grateful.</p><p>You can find the example project used for comparison <a href="https://github.com/danielkec/thinjar-vs-fatjar">here</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3c3011b4bd55" width="1" height="1" alt=""><hr><p><a href="https://medium.com/helidon/evil-of-fatjar-3c3011b4bd55">Evil of FatJar</a> was originally published in <a href="https://medium.com/helidon">Helidon</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Helidon and HTTP/2 Rapid Reset vulnerability]]></title>
            <link>https://medium.com/helidon/helidon-and-http-2-rapid-reset-vulnerability-d470526f4dac?source=rss-da9068633ebd------2</link>
            <guid isPermaLink="false">https://medium.com/p/d470526f4dac</guid>
            <category><![CDATA[rapid]]></category>
            <category><![CDATA[http2]]></category>
            <category><![CDATA[helidon]]></category>
            <category><![CDATA[releases]]></category>
            <category><![CDATA[cve]]></category>
            <dc:creator><![CDATA[Daniel Kec]]></dc:creator>
            <pubDate>Fri, 27 Oct 2023 13:28:08 GMT</pubDate>
            <atom:updated>2023-10-27T13:28:08.278Z</atom:updated>
            <content:encoded><![CDATA[<h3>Helidon and HTTP/2 Rapid Reset attack</h3><p><a href="https://nvd.nist.gov/vuln/detail/CVE-2023-44487">CVE-2023–44487</a>: HTTP/2 protocol Rapid Reset vulnerability</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ihj6tdLuUmqM78hidj0_pA.png" /></figure><p>Just at the end of the summer, the largest DDoS attacks in internet history happened. Without gaining much of publicity, attacks were targeted at the three large cloud providers: <a href="https://blog.cloudflare.com/technical-breakdown-http2-rapid-reset-ddos-attack/">Cloudflare</a>, <a href="https://cloud.google.com/blog/products/identity-security/google-cloud-mitigated-largest-ddos-attack-peaking-above-398-million-rps/">Google</a> and <a href="https://aws.amazon.com/blogs/security/how-aws-protects-customers-from-ddos-events/">AWS</a>.</p><p>After some time, on October 10th, a new zero-day vulnerability in HTTP/2 protocol was disclosed as <a href="https://nvd.nist.gov/vuln/detail/CVE-2023-44487">CVE-2023–44487</a>, allowing a DDoS attack quickly nicknamed <strong>HTTP/2 Rapid-Reset</strong>.</p><p>As the vulnerability is in the HTTP/2 specification itself, the attack is threatening more or less, depending on the design and all the runtimes supporting HTTP/2 protocol.</p><p>The attack is fairly simple: HTTP/2 client can legally create millions and millions of requests(streams) over a single connection without using as many resources as the server. The server, on the other hand, is required by the spec to invest un-proportionally more resources in the bureaucracy of receiving those.</p><h3>“Why nobody thought of that?”</h3><p>Well, the spec gives runtimes the means to defend themselves with <strong>MAX_CONCURRENT_STREAMS </strong>setting. The server can simply instruct the client how many of the streams can be opened at once, see <a href="https://httpwg.org/specs/rfc9113.html#rfc.section.5.1.2">5.1.2</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/893/1*UjMsSO5rMwU6b6rELNz1dg.png" /></figure><p>The problem is that the spec also gives the client the right to cancel the stream very quickly with <strong>RST_STREAM</strong> frame at any time. And that is the problem right there. See <a href="https://httpwg.org/specs/rfc9113.html#rfc.section.6.4">6.4</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/888/1*V4ecCYm8xh4l8lrmvLxa6A.png" /></figure><p>Because the client can force the server to set up a new stream and reset/cancel the stream immediately(hence the “<strong>Rapid-Reset Attack”</strong> name), a large asymmetry happens between the server and the client. The server needs to parse the headers, allocate necessary resources for the new stream and release it all while the client doesn’t really need to do much. In the saved time client can send the same headers again and again, accompanied by an immediate reset frame.</p><p>This simplicity makes Rapid-Reset very easy to do and hard to defend without breaking the specification rules.</p><h3>Helidon</h3><p><strong>HTTP/2 support in all versions of Helidon needs to be explicitly enabled.</strong> Helidon supports HTTP/2 in versions 4.x, 3.x and experimentally in 2.x and 1.x.</p><h4>Helidon 4</h4><p>Helidon 4 has HTTP/2 support disabled by default. To enable HTTP/2 a single dependency is needed:</p><pre>&lt;dependency&gt;<br>    &lt;groupId&gt;io.helidon.webserver&lt;/groupId&gt;<br>    &lt;artifactId&gt;helidon-webserver-http2&lt;/artifactId&gt;<br>&lt;/dependency&gt;</pre><p>Helidon 4 HTTP/2 server is fixed in release <a href="https://github.com/helidon-io/helidon/releases/tag/4.0.0">4.0.0</a> with a token bucket for rapid resets, sending <strong>GO_AWAY</strong> and closing connection when the threshold is reached. No action is needed; protection against rapid reset attacks is active by default for HTTP/2 server.</p><p>By default, <strong>100</strong> rapid resets per <strong>10</strong> seconds are allowed. You can fine-tune the rapid reset defence with the following settings:</p><pre>server:<br>  port: 8080<br>  host: localhost<br><br>  protocols:<br>    http_2:<br>      rapid-reset-check-period: PT10S # 10 seconds in ISO_8601 format<br>      max-rapid-resets: 100           # max 100 requests with rapid resets</pre><p>With SE, the same settings are available over programmatic API:</p><pre>Server server = Server.builder()<br>        .addProtocol(Http2Config.builder()<br>              .rapidResetCheckPeriod(Duration.of(10, ChronoUnit.SECONDS))<br>              .maxRapidResets(100)<br>              .build())<br>        .host(&quot;localhost&quot;)<br>        .port(8080)<br>        .routing(...)<br>        .build()<br>        .start();</pre><h4>Helidon 3</h4><p>Helidon 3 has HTTP/2 support disabled by default. To enable HTTP/2, a single dependency is needed:</p><pre>&lt;dependency&gt;<br>    &lt;groupId&gt;io.helidon.webserver&lt;/groupId&gt;<br>    &lt;artifactId&gt;helidon-webserver-http2&lt;/artifactId&gt;<br>&lt;/dependency&gt;</pre><p>Unlike Helidon 4, Helidon 3.x is built on top of the Netty library and relies on an upstream <a href="https://github.com/netty/netty/commit/58f75f665aa81a8cbcf6ffa74820042a285c5e61">patch</a> in <a href="https://netty.io/news/2023/10/10/4-1-100-Final.html">Netty 4.1.100.Final</a>. The patched version of Netty allows <strong>200</strong> resets per <strong>30-second</strong> window. Netty upgrade to the patched version is part of <a href="https://github.com/helidon-io/helidon/releases/tag/3.2.3">Helidon 3.2.3 release</a>.</p><p>⚠️ Upgrade to <a href="https://github.com/helidon-io/helidon/releases/tag/3.2.3">Helidon 3.2.3</a> as soon as possible in case your server has HTTP/2 enabled!</p><h4>Helidon 2 and 1</h4><p>Both versions of Helidon 2 and 1 have HTTP/2 support disabled by default. To enable HTTP/2, an experimental feature needs to be enabled:</p><pre>server:<br>  port: 8080<br>  host: localhost<br>  experimental:<br>    http2:<br>      enable: true<br>      max-content-length: 16384</pre><p>Helidon versions 2 and 1 are built on top of the Netty library and rely on the upstream <a href="https://github.com/netty/netty/commit/58f75f665aa81a8cbcf6ffa74820042a285c5e61">patch</a> in <a href="https://netty.io/news/2023/10/10/4-1-100-Final.html">Netty 4.1.100.Final</a>. Netty upgrade to the patched version is part of <a href="https://github.com/helidon-io/helidon/releases/tag/2.6.4">Helidon 2.6.4 release</a></p><p>⚠️ Upgrade to <a href="https://github.com/helidon-io/helidon/releases/tag/2.6.4">Helidon 2.6.4</a> as soon as possible in case your server has HTTP/2 enabled!</p><h3>Conclusion</h3><p>Remember <strong>HTTP/2 support in all versions of Helidon needs to be explicitly enabled</strong>.<br>On October 10th, the clock started to tick for a large part of the internet to patch or update all vulnerable HTTP/2 infrastructure as fast as possible.</p><p><strong>In case you are using HTTP/2, update to the patched version of Helidon as soon as possible.</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d470526f4dac" width="1" height="1" alt=""><hr><p><a href="https://medium.com/helidon/helidon-and-http-2-rapid-reset-vulnerability-d470526f4dac">Helidon and HTTP/2 Rapid Reset vulnerability</a> was originally published in <a href="https://medium.com/helidon">Helidon</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Secured WebSocket with Helidon]]></title>
            <link>https://medium.com/helidon/secured-websocket-with-helidon-cab1e8130e5f?source=rss-da9068633ebd------2</link>
            <guid isPermaLink="false">https://medium.com/p/cab1e8130e5f</guid>
            <category><![CDATA[websocket]]></category>
            <category><![CDATA[wss]]></category>
            <category><![CDATA[tls]]></category>
            <category><![CDATA[helidon]]></category>
            <dc:creator><![CDATA[Daniel Kec]]></dc:creator>
            <pubDate>Fri, 03 Jun 2022 12:44:59 GMT</pubDate>
            <atom:updated>2022-06-09T16:53:45.722Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZTftf1CRJ_PPURb6YIYB7A.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/@moneyphotos?utm_source=medium&amp;utm_medium=referral">olieman.eth</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Secured WebSocket (wss://…) is to WebSocket as https is to http. In Helidon 2 we can enable both with the same server’s TLS configuration.</p><h3>Helidon MP</h3><p>You just need to tell Helidon which certificate to use to secure your https and wss connections.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e3f3497047a66a7322ec5f3a06b4e856/href">https://medium.com/media/e3f3497047a66a7322ec5f3a06b4e856/href</a></iframe><p>Let’s try it out with simple endpoint.</p><blockquote>For detailed information about setting up a WebSocket endpoint in Helidon MP, visit our <a href="https://helidon.io/docs/v2/#/mp/websocket/01_overview">docs</a>.</blockquote><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/50aa3c08b436920cbe5a9a6c2d1e1b9c/href">https://medium.com/media/50aa3c08b436920cbe5a9a6c2d1e1b9c/href</a></iframe><p>Use <a href="https://github.com/vi/websocat">websockat</a> to connect to the secured WebSocket endpoint.</p><pre>$websocat -k wss://localhost:8080/ws/echo<br>Hi MP<br>Did you send Hi MP?</pre><p><em>Note: In this example, we used a self-signed certificate hence the</em><em>-k option.</em></p><h3>Helidon SE</h3><p>The server’s TLS configuration in Helidon SE follows a similar pattern to the one we used in Helidon MP.</p><blockquote>For detailed information about setting up a WebSocket endpoint in Helidon SE, visit our <a href="https://helidon.io/docs/v2/#/se/websocket/01_overview">docs</a>.</blockquote><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/18b59603c90fa2c9f6bfa111ae49d4b7/href">https://medium.com/media/18b59603c90fa2c9f6bfa111ae49d4b7/href</a></iframe><p>Use the same <a href="https://github.com/vi/websocat">websockat</a> again to test it:</p><pre>$websocat -k wss://localhost:8080/ws/echo<br>Hi SE<br>Did you say Hi SE?</pre><p>Check out the following Helidon examples for more information:</p><ul><li><a href="https://github.com/oracle/helidon/tree/2.5.0/examples/microprofile/tls">helidon/examples/microprofile/tls at 2.5.0 · oracle/helidon</a></li><li><a href="https://github.com/oracle/helidon/tree/2.5.0/examples/microprofile/websocket">helidon/examples/microprofile/websocket at 2.5.0 · oracle/helidon</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cab1e8130e5f" width="1" height="1" alt=""><hr><p><a href="https://medium.com/helidon/secured-websocket-with-helidon-cab1e8130e5f">Secured WebSocket with Helidon</a> was originally published in <a href="https://medium.com/helidon">Helidon</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>