A problem that I have seen a in apache camel is that people sometimes set a header to the old body and then set the body to the call for the system that we will get data from

Pattern with header

This pattern will send data, and maybe very secret data, to a system that don’t allowed to get them. The will be a overload of data to send to the system that we will encrich data from.

from("direct:pattern1")
  .setHeader("oldBody").body()
  .to(http("localhost:8081/getperson"));
  • CON: Leak data and send more data than we need to the third system.
  • PRO: You can set the body to the call to ever you need. This needs for example SOAP services.

Pattern with enrich

A better way is to use enrich in apache camel, that create a new exchange.

from("direct:pattern2")
  .enrich(http("localhost:8081/getperson"), (AggregationStrategy) (oldExchange, newExchange) -> {
      oldExchange.getMessage().setHeader("new", newExchange);
      return oldExchange;
  });
  • CON: Can’t set body to use in the call.
  • PRO: Don’t leak data.

The problem with enrich from a soap service is that we can set the body and headers in the exhange to make the call.

But we can make a change so we can set the body for the call, example if we need to call a SOAP or another service that need a body.

from("direct:pattern3")
          .log("pattern3")
          .enrich("direct:enrich", (AggregationStrategy) (oldExchange, newExchange) -> {
                  oldExchange.getMessage().setHeader("newBody", newExchange);
                  return oldExchange;
              });

from("direct:enrich")
          .routeId("Enrich")
          .setBody().constant("soapmessage")
          .to(http("localhost:8081/getperson"));
  • PRO: Can set body to use in the call. Don’t leak data.

The best pattern for enrich with systems that need a body in the call!