DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Related

  • Why Your "Stateless" Services Are Lying to You
  • Database Connection Pooling at Scale: PgBouncer + Multi-Tenant Postgres (10K Concurrent Connections)
  • DeepSeek’s mHC: Manifold-Constrained Hyper-Connections, Explained for Practical Use
  • How to Identify the Underlying Causes of Connection Timeout Errors for MongoDB With Java

Trending

  • OpenAPI From Code With Spring and Java: A Recipe for Your CI
  • Beyond Partitioning and Z-Order: A Deep Dive into Liquid Clustering for Unity Catalog Managed Tables
  • No More Cheap Claude: 4 First Principles of Token Economics in 2026
  • Building a DevOps-Ready Internal Developer Platform: A Hands-On Guide to Golden Paths, Self-Service, and Automated Delivery Pipelines

Using Camel-Undertow Component for Supporting an http2 Connection

In this article, and integration developers gives some help on how to configure http2 protocol support for the camel-undertow component.

By 
Chandra Shekhar Pandey user avatar
Chandra Shekhar Pandey
·
Jan. 29, 18 · Tutorial
Likes (4)
Comment
Save
Tweet
Share
7.9K Views

Join the DZone community and get the full member experience.

Join For Free

This article will help you to configure http2 protocol support for the camel-undertow component.

  • Camel's undertow component uses an embedded undertow web-container of version undertow-core:jar:1.4.21. This version also supports the http2 connection.
  • I have used the Camel version 2.21.0-SNAPSHOT from upstream: https://github.com/apache/camel.
  • Also, the version to test applications using the camel-undertow component is 7.53.1. This curl version supports tje -http2 flag for sending an http2 request.
  • I have also used to test application from a Linux terminal. However, this article is not about http2 insights.
  • For http2 details, I found articles [1] and [2] helpful.

1. The project structure is depicted below.

[csp@dhcppc1 undertow-camel-testing]$ tree
.
├── pom.xml
├── README.md
└── src
    └── main
        └── resources
            └── META-INF
                └── spring
                    └── camel-context.xml

2. In pom.xml, we would have to set up the following dependencies.

<dependency>
    <groupId>org.apache.camel</groupId>
    <artifactId>camel-core</artifactId>
    <version>${camel.version}</version>
</dependency>
<dependency>
    <groupId>org.apache.camel</groupId>
    <artifactId>camel-spring</artifactId>
    <version>${camel.version}</version>
</dependency>
<dependency>
    <groupId>org.apache.camel</groupId>
    <artifactId>camel-undertow</artifactId>
    <version>${camel.version}</version>
</dependency>
<dependency>
    <groupId>org.apache.camel</groupId>
    <artifactId>camel-http-common</artifactId>
    <version>${camel.version}</version>
</dependency>

3. With the version of Camel we're using:

<properties>
    <camel.version>2.21.0-SNAPSHOT</camel.version>
</properties>

4. Now, one can use a Spring-based dsl and configure the camel-undertow component as I have below. Let's say we named this file, camel-context.xml.

<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd">
<camelContext id="cbr-example-context" xmlns="http://camel.apache.org/schema/spring">
<route id="cbr-route" trace="true">
<from id="_from1" uri="undertow:http://localhost:7766/foo/bar"/>
<setBody id="_setBody1">
<constant&gt;Sending Response&lt;/constant>
</setBody>
<log id="_log5" message="Headers ${in.headers}"/>
<log id="_log5" message="Done processing ${body}"/>
</route>
</camelContext>
<bean class="org.apache.camel.component.undertow.UndertowComponent" id="undertow">
<property name="hostOptions" ref="undertowHostOptions"/>
</bean>
<bean
class="org.apache.camel.component.undertow.UndertowHostOptions" id="undertowHostOptions">
<property name="http2Enabled" value="true"/>
</bean>
</beans>

5. Point to the note above http2Enabled and make sure it is set to true. For the UndertowHostOptions class, by default it is set to false. This UndertowHostOptions class is then referred to UndertowComponent, which is then used in the camel route.
6. We can use camel-maven-plugin in pom.xml then we can run this using maven command: 

mvn camel:run 

<plugin>
<groupId&>org.apache.camel</groupId>
<artifactId>camel-maven-plugin</artifactId>
<version>${camel.version}</version>
<configuration>
<fileApplicationContextUri>src/main/resources/META-INF/spring/camel-context.xml</fileApplicationContextUri>
</configuration>
</plugin>

7. Once successfully run, this should expose an HTTP service at http://localhost:7766/foo/bar.
8. We can test this using curl and nghttp commands from the Linux terminal. I used Fedora 26 where the curl command with http2 support was available. For RHEL7, I used the nghttp utility to test the http2 connection.
9. Using the curl command:

[csp@dhcppc1 undertow-camel-testing]$ curl -v --http2 http://localhost:7766/foo/bar
* Trying ::1...
* TCP_NODELAY set
* connect to ::1 port 7766 failed: Connection refused
* Trying 127.0.0.1...
* TCP_NODELAY set
* Connected to localhost (127.0.0.1) port 7766 (#0)
> GET /foo/bar HTTP/1.1
> Host: localhost:7766
> User-Agent: curl/7.53.1
> Accept: */*
> Connection: Upgrade, HTTP2-Settings
> Upgrade: h2c
> HTTP2-Settings: AAMAAABkAARAAAAAAAIAAAAA
> 
< HTTP/1.1 101 Switching Protocols
< Connection: Upgrade
< Upgrade: h2c
< Date: Sun, 10 Dec 2017 08:43:58 GMT
* Received 101
* Using HTTP2, server supports multi-use
* Connection state changed (HTTP/2 confirmed)
* Copying HTTP/2 data in stream buffer to connection buffer after upgrade: len=0
* Connection state changed (MAX_CONCURRENT_STREAMS updated)!
< HTTP/2 200 
< accept: */*
< http2-settings: AAMAAABkAARAAAAAAAIAAAAA
< breadcrumbid: ID-dhcppc1-1512886066149-0-25
< content-length: 16
< user-agent: curl/7.53.1
< date: Sun, 10 Dec 2017 08:43:58 GMT
< 
* Connection #0 to host localhost left intact
Sending Response

10. Using the nghttp command:

cpandey@cpandey camel-undertow]$ nghttp -v http://localhost:7766/foo/bar
[ERROR] Could not connect to the address ::1
Trying next address 127.0.0.1
[  0.000] Connected
[  0.000] send SETTINGS frame <length=12, flags=0x00, stream_id=0>
          (niv=2)
          [SETTINGS_MAX_CONCURRENT_STREAMS(0x03):100]
          [SETTINGS_INITIAL_WINDOW_SIZE(0x04):65535]
[  0.000] send PRIORITY frame <length=5, flags=0x00, stream_id=3>
          (dep_stream_id=0, weight=201, exclusive=0)
[  0.000] send PRIORITY frame <length=5, flags=0x00, stream_id=5>
          (dep_stream_id=0, weight=101, exclusive=0)
[  0.000] send PRIORITY frame <length=5, flags=0x00, stream_id=7>
          (dep_stream_id=0, weight=1, exclusive=0)
[  0.000] send PRIORITY frame <length=5, flags=0x00, stream_id=9>
          (dep_stream_id=7, weight=1, exclusive=0)
[  0.000] send PRIORITY frame <length=5, flags=0x00, stream_id=11>
          (dep_stream_id=3, weight=1, exclusive=0)
[  0.000] send HEADERS frame <length=45, flags=0x25, stream_id=13>
          ; END_STREAM | END_HEADERS | PRIORITY
          (padlen=0, dep_stream_id=11, weight=16, exclusive=0)
          ; Open new stream
          :method: GET
          :path: /foo/bar
          :scheme: http
          :authority: localhost:7766
          accept: */*
          accept-encoding: gzip, deflate
          user-agent: nghttp2/1.21.1
[  0.001] recv SETTINGS frame <length=18, flags=0x00, stream_id=0>
          [SETTINGS_HEADER_TABLE_SIZE(0x01):4096]
          [SETTINGS_MAX_FRAME_SIZE(0x05):16384]
          [SETTINGS_INITIAL_WINDOW_SIZE(0x04):65535]
[  0.001] send SETTINGS frame <length=0, flags=0x01, stream_id=0>
          ; ACK
          (niv=0)
[  0.001] recv SETTINGS frame <length=0, flags=0x01, stream_id=0>
          ; ACK
          (niv=0)
[  0.003] recv (stream_id=13) :status: 200
[  0.003] recv (stream_id=13) accept: */*
[  0.003] recv (stream_id=13) accept-encoding: gzip, deflate
[  0.003] recv (stream_id=13) breadcrumbid: ID-cpandey-pnq-csb-1512577017865-0-3
[  0.003] recv (stream_id=13, sensitive) content-length: 16
[  0.003] recv (stream_id=13) user-agent: nghttp2/1.21.1
[  0.003] recv (stream_id=13, sensitive) date: Wed, 06 Dec 2017 17:11:51 GMT
[  0.003] recv HEADERS frame <length=88, flags=0x04, stream_id=13>
          ; END_HEADERS
          (padlen=0)
          ; First response header
Sending Response[  0.003] recv DATA frame <length=16, flags=0x01, stream_id=13>
          ; END_STREAM
[  0.003] send GOAWAY frame <length=8, flags=0x00, stream_id=0>
          (last_stream_id=0, error_code=NO_ERROR(0x00), opaque_data(0)=[])

Resources: 

1. http://undertow.io/blog/2015/04/27/An-in-depth-overview-of-HTTP2.html
2. https://developers.google.com/web/fundamentals/performance/http2/

Connection (dance)

Published at DZone with permission of Chandra Shekhar Pandey. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • Why Your "Stateless" Services Are Lying to You
  • Database Connection Pooling at Scale: PgBouncer + Multi-Tenant Postgres (10K Concurrent Connections)
  • DeepSeek’s mHC: Manifold-Constrained Hyper-Connections, Explained for Practical Use
  • How to Identify the Underlying Causes of Connection Timeout Errors for MongoDB With Java

Partner Resources

×

Comments

The likes didn't load as expected. Please refresh the page and try again.

  • RSS
  • X
  • Facebook

ABOUT US

  • About DZone
  • Support and feedback
  • Community research

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 215
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

  • RSS
  • X
  • Facebook