Search code examples
javarestapache-camelspring-camelapache-camel-3

How to retrieve query parameter value while using Apache Camel?


I have a REST endpoint http://localhost:8080/replaymessages/{messageids} wherein messageids will have comma (,) separated values - say 123,456,789 and so on. How to retrieve these values while using Apache Camel?


Solution

  • You can use bean to invoke a static method like org.apache.commons.lang.StringUtils.split to split the path param stored in the header:

    rest()
        .get("/replaymessages/{messageids}")
        .to("direct:processMessageIds");
    
    from("direct:processMessageIds")
        .bean(StringUtils.class, "split(${header.messageids}, ',' , -1)")
        .log(LoggingLevel.INFO, "id[0] == ${body[0]}");