Tag Archives: Apache Camel - Page 2

Apache Camel: Get properties from within a Processor

Getting properties from within a Processor needs interaction with the exchange object. This can be accomplished by the following code:

public static class MyProccessor implements Processor {

    public void process(Exchange exchange) throws Exception {
        String prop = exchange
                         .getContext()
                              .resolvePropertyPlaceholders("{{my.property}}");
    }
}

Tested on Apache Camel K Runtime 1.16.0, Apache Camel 3.19.0, Minikube v1.29.0 and WSL2 Ubuntu 20.04.4 LTS

Camel-K and IntelliJ syntax highlighting

Apache Camel-K integrations does not use a pom or Gradle script for dependencies which leads to poor syntax highlighting in IDEA IntelliJ. To fix that shortcoming (pretty sure the guys at JetBrains will fix this in the future) we can add a project wide dependency of io.quarkus.camel.core from Maven Central
1. Open “Project Structure…” (File menu)
2. Choose “Libraries”
3. Click the plus sign and choose “From Maven…”
4. Search for: “camel-core” and pick the version of io.quarkus.camel.core you want

5. Tick the “Download to” and choose preferred location
6. After all downloads are done your project should have the correct syntax highlighting for you Camel-K project

Tested om Windows 10, IntelliJ 2023.1.2 and io.quarkus.camel.core 0.13.3

Camel: Access incoming headers

In HTTP requests (and other requests or messages) you usually get a payload and a bunch of headers. In Camel you can find the payload in the “body” variable like this:

public class MyRoute extends RouteBuilder {

    @Override
    public void configure() throws Exception {
           from("timer:mytimer?repeatCount=1")
                  .to("https://www.google.com")
                  .log("${body}");
    }
}

So, how do you access the headers? There is another variable for this called “in” and it can be used like this:

public class MyRoute extends RouteBuilder {

    @Override
    public void configure() throws Exception {
           from("timer:mytimer?repeatCount=1")
                  .to("https://www.google.com")
                  .log("${in.headers}") // Log all incoming  headers
                  .log("${in.headers.Content-Type}"); // Log a specific header
    }
}

Tested on Ubuntu 20.04.4 LTS, Apache Camel 3.20, Minikube v1.29.0 (Camel-K) and Java 1.8.0_352