Details
Description
Issue
NOTE: I will try to come back with a fixing PR ASAP.
The processor
package com.company.processors; import com.company.api.model.Error; import org.apache.camel.Exchange; import org.apache.camel.Processor; public class ToError implements Processor { @Override public void process(Exchange exchange) { Throwable responseException = exchange.getProperty(Exchange.EXCEPTION_CAUGHT, Throwable.class); Error response = new Error() {{ setMessage(responseException.getMessage()); setDetails(responseException.getCause().getMessage()); }}; exchange.getIn().setBody(response); } }
with the route
.doCatch(Exception.class) .process(new ToError()) .to("log:error")
ends up in
2020-06-17 10:39:03.299 INFO 2928 --- [ult-workqueue-2] error : Exchange[ExchangePattern: InOut, BodyType: null, Body: class Error { message: Connection reset details: null }]
where BodyType: null causes consequent problems e.g. the route
.end() .transform().body().marshal().json(JsonLibrary.Gson).endRest();
returns a ResponseEntity with no body.
Reason
It took one day to find the villain The reason was that Java instance initialization via setters inside `{{}}`s
Workaround
Replacing
Error response = new Error() {{
setMessage(responseException.getMessage());
setDetails(responseException.getCause().getMessage());
}};
with
Error response = new Error();
response.setMessage(responseException.getMessage());
response.setDetails(responseException.getCause().getMessage());
fixes issue.