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/19 14:49:00 UTC
[jira] [Updated] (CAMEL-15200) Processor setBody ends up in
bodyType: null
[ https://issues.apache.org/jira/browse/CAMEL-15200?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Yasser Zamani updated CAMEL-15200:
----------------------------------
Description:
h1. Issue
*NOTE:* I will try to come back with a fixing PR ASAP.
The processor
{code:java}
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);
}
}
{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 :(
was:
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 :(
> 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
> Priority: Minor
> Fix For: 3.x
>
>
> h1. Issue
> *NOTE:* I will try to come back with a fixing PR ASAP.
>
> The processor
> {code:java}
> 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);
> }
> }
> {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)