This is useful for WildFly because we can leverage the existing Undertow HTTP engine and enable Camel to configure HTTP Handlers into it. This gives us the capability to produce and consume HTTP messages.
Standalone Camel Undertow Vs WildFly Camel Undertow
There are some minor differences between configuring Camel Undertow for standalone Camel Vs WildFly Camel in relation to consumer endpoints.
Standalone Camel Undertow lets you do:
This configuration starts an embedded Undertow server on localhost bound to port 7766.
For WildFly Camel, this would not be allowed. Since WildFly is already running an Undertow HTTP engine, it makes sense to reuse this, rather than create a new Undertow instance. This has advantages such as being able to take advantage of WildFly’s native security mechanisms, graceful shutdown etc.
Therefore, we are restricted to consuming from the port that has been configured within the WildFly socket-binding configuration (usually 8080).
An Undertow HTTP consumer would look like:
When the Camel application is deployed, you should see a message output to the console logs like:
Now you can open a web browser and navigate to http://127.0.0.1:8080/hello?name=James. You should see a response output as ‘Hello James’.
The producer acts as an HTTP client to make requests to a specified HTTP endpoint. Here’s an example that creates your own IP address lookup service by outputting the response from ipinfo.io.
Browse to http://127.0.0.1:8080/whatsmyip and you should see your IP address.
Undertow with the Camel REST DSL
The Undertow component can also be used with the Camel REST DSL. It’s useful to combine this with the camel-swagger-java dependency for endpoint documentation.
You can then use a HTTP client such as cURL to send requests using each of the HTTP verbs that the above example can handle:
To see the swagger markup you can browse to http://localhost:8080/camel/rest/api-doc.
Hopefully this has been a good introduction to the Camel Undertow component on the WildFly Camel Subsystem. Doubtless, it’ll continue to evolve and improve.
I’d like to see more Camel components use Undertow as their HTTP engine, as it’d enabled them to better integrate with WildFly. Stay tuned for progress in this area.