You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@camel.apache.org by "Claus Ibsen (Jira)" <ji...@apache.org> on 2019/10/07 08:43:00 UTC
[jira] [Resolved] (CAMEL-13122) Potential bug in
BeanExpression/HttpMessage
[ https://issues.apache.org/jira/browse/CAMEL-13122?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Claus Ibsen resolved CAMEL-13122.
---------------------------------
Fix Version/s: (was: 3.x)
3.0.0
Assignee: Claus Ibsen
Resolution: Fixed
Fixed by CAMEL-10425
> Potential bug in BeanExpression/HttpMessage
> -------------------------------------------
>
> Key: CAMEL-13122
> URL: https://issues.apache.org/jira/browse/CAMEL-13122
> Project: Camel
> Issue Type: Bug
> Components: camel-servlet
> Affects Versions: 2.23.1
> Reporter: Micael Kirouac
> Assignee: Claus Ibsen
> Priority: Minor
> Fix For: 3.0.0
>
> Attachments: Camel13122Test.java
>
>
> I think I found a potential bug when using a bean to set a property if a message is coming through http. I wanted to check here before opening a bug in case I am missing something. It is very similar to the following bug which has already been fixed: [https://stackoverflow.com/questions/40293128/camel-rest-service-throws-exception-when-returning-null/40317432#40317432].
>
> The difference is that instead of returning null, an exception is thrown from the bean method. When that happen, I see the same behavior as described in the stackoverflow post above. I included an example on how to reproduce at the end of this email. Here is what I think happens:
>
> Problem starts in BeanExpression:
> 1. The exchange is copied, BeanExpression: line 194: Exchange resultExchange = ExchangeHelper.createCopy(exchange, true)
> 2. The out body is then retrieved from the exchange, BeanExpression: line 201: result = resultExchange.getOut().getBody();
> 3. Since out() is null, the in() message is copied to the out(), this makes a copy of the HttpMessage, which is copied along with the original ServletRequest (which contains a closed stream) DefaultExchange.class line 317.
> 4. To copy the message from in to out, the method newInstance() from HttpMessage class is called. HttpMessage line 85
> 5. At this point, the new instance of HttpMessage tries to read the stream from the original message which is already closed, IOException.
>
> Example just below, I would be expecting the EXCEPTION_CAUGHT to be the RuntimeException I throw but instead it's a RuntimeBeanExpressionException effectively wrapping a IOException.
>
> {code:java}
> public void configureTestException() {
> restDefinitionV1 = restDefinitionV1
> .get("/throwException")
> .route()
> .onException(Exception.class)
> .process(exchange -> {System.out.println("Caught exception of type: " + exchange.getProperty(Exchange.EXCEPTION_CAUGHT).getClass());} )
> .handled(true)
> .end()
> .setProperty("test").method(new TestBean(), "throwException")
> .endRest();
> }
>
> public static class TestBean {
> public void throwException() {
> throw new RuntimeException("Excepting this exception to be handled by onException");
> }
> }
> {code}
>
> I will try to provide an actual unit test shortly.
--
This message was sent by Atlassian Jira
(v8.3.4#803005)