In my project we are using Apache Camel via Java DSL
This is how a typical route looks:
from("direct:MyPizzaRestaurant")
.routeId("PizzaRoute")
.log(LoggingLevel.INFO, LOG, LOG_IN_MESSAGE)
.bean(veryImportandAndUniqueManagementService, "addTomatoesAndCheeseAndThenPutInTheOven(${in.headers.pizzaContextKey},${in.headers.httpHeaders[pizzaOrderIz]},${in.headers.httpHeaders[restaurantId]},${in.headers.httpHeaders[orderChannel]},${in.headers.customerId},${in.headers.httpHeaders[pizzaType]},${in.headers.httpHeaders[promo]})")
.end();
Now what bothers me is the line length. It is uncomfortable to read and maintain, different code analyzing tools like SonarCube are raising warnings about that. I want to ask how would you wrap this line and what option would you recommend to fit this code into the 120 symbols width?
For example you could do this:
from("direct:MyPizzaRestaurant")
.routeId("PizzaRoute")
.log(LoggingLevel.INFO, LOG, LOG_IN_MESSAGE)
.bean(veryImportandAndUniqueManagementService,
"addTomatoesAndCheeseAndThenPutInTheOven(
"${in.headers.pizzaContextKey}," +
"${in.headers.httpHeaders[pizzaOrderIz]}," +
"${in.headers.httpHeaders[restaurantId]}," +
"${in.headers.httpHeaders[orderChannel]}," +
"${in.headers.customerId}," +
"${in.headers.httpHeaders[pizzaType]}," +
"${in.headers.httpHeaders[promo]})")
.end();
The drawback of this is when you are using Apache Camel Plugin for IntelliJ, it allows you to quickly go inside the method implementation by Clicking on with with Ctrl. But it only works when string parameter containing method and input params is a single line string. So in the example above you will lose the ability to quickly travel to the specified method but gain readability. Is there a way to somehow combine both?
Why not use Camel parameter binding instead ?
Alternatively you could also define a second method to 'unwrap' Camel raw message:
This way, the client code become much simpler: