You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@camel.apache.org by "Yasser Zamani (Jira)" <ji...@apache.org> on 2020/06/17 06:25:00 UTC
[jira] [Created] (CAMEL-15200) Processor setBody ends up in
bodyType: null
Yasser Zamani created CAMEL-15200:
-------------------------------------
Summary: Processor setBody ends up in bodyType: null
Key: CAMEL-15200
URL: https://issues.apache.org/jira/browse/CAMEL-15200
Project: Camel
Issue Type: Bug
Components: came-core
Affects Versions: 3.3.0
Environment: Java 11
Camel 3.3.0
Reporter: Yasser Zamani
Fix For: 3.x
h1. Issue
*NOTE:* I will try to come back with a fixing PR ASAP.
The processor
{code:java}
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);
}
}
{code}
with the route
{code:java}
.doCatch(Exception.class)
.process(new ToError())
.to("log:error")
{code}
ends up in
{noformat}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
}]{noformat}
where ??BodyType: null?? causes consequent problems e.g. the route
{code:java}
.end()
.transform().body().marshal().json(JsonLibrary.Gson).endRest();
{code}
returns a {{ResponseEntity}} with no body.
h1. Reason
It took one day to find the villain :) The reason was that Java instance initialization via setters inside `{{}}`s :(
--
This message was sent by Atlassian Jira
(v8.3.4#803005)