Uploaded image for project: 'Camel'
  1. Camel
  2. CAMEL-16507

Camel-sql: Body for empty ResultSet no longer null when using outputType selectOne

Attach filesAttach ScreenshotVotersWatch issueWatchersCreate sub-taskLinkCloneUpdate Comment AuthorReplace String in CommentUpdate Comment VisibilityDelete Comments
    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • 3.9.0
    • 3.10.0
    • camel-sql
    • None
    • Unknown
    • Regression

    Description

      After upgrading from Camel 3.8.0 to 3.9.0 we noticed a change in behavior of camel-sql for empty ResultSets when using outputType selectOne.

      In Camel 3.8.0 and older versions the out body was null, in Camel 3.9.0 the out body is an empty string. This causes simple statements accessing the body as a map to fail.

      This test

      public class CamelSqlEmptyResultTest extends CamelTestSupport {
      
          @Override
          protected RouteBuilder createRouteBuilder() {
              return new RouteBuilder() {
                  public void configure() {
                      from("seda:in")
                          .to("sql:select * from Persons where PersonID=1?outputType=selectOne")
                          .setHeader("PersonID", simple("${body[PersonID]}"))
                          .to("mock:out");
                  }
              };
          }
      
          @Override
          protected void bindToRegistry(Registry registry) throws Exception {
              EmbeddedDatabase db = new EmbeddedDatabaseBuilder().setType(EmbeddedDatabaseType.H2).generateUniqueName(true)
                      .build();
              new JdbcTemplate(db).execute("CREATE TABLE Persons (PersonID int, LastName varchar(255))");
              registry.bind("dataSource", db);
          }
      
          @Test
          public void test() throws Exception {
              MockEndpoint out = getMockEndpoint("mock:out");
              out.expectedMessageCount(1);
      
              template.sendBody("seda:in", "");
      
              out.assertIsSatisfied(3_000);
          }
      }
      

      passes in Camel 3.8.0, but fails with:

      org.apache.camel.language.bean.RuntimeBeanExpressionException: Failed to invoke method: [PersonID] on java.lang.String due to: java.lang.IndexOutOfBoundsException: Key: PersonID not found in bean:  of type: java.lang.String using OGNL path [[PersonID]]
             at org.apache.camel.language.bean.BeanExpression.evaluate(BeanExpression.java:208)
             at org.apache.camel.language.bean.BeanExpression.evaluate(BeanExpression.java:214)
             at org.apache.camel.language.simple.SimpleExpressionBuilder$28.evaluate(SimpleExpressionBuilder.java:757)
             at org.apache.camel.support.ExpressionAdapter.evaluate(ExpressionAdapter.java:35)
             at org.apache.camel.processor.SetHeaderProcessor.process(SetHeaderProcessor.java:48)
             at org.apache.camel.processor.errorhandler.RedeliveryErrorHandler$SimpleTask.run(RedeliveryErrorHandler.java:439)
             at org.apache.camel.impl.engine.DefaultReactiveExecutor$Worker.schedule(DefaultReactiveExecutor.java:181)
             at org.apache.camel.impl.engine.DefaultReactiveExecutor.scheduleMain(DefaultReactiveExecutor.java:62)
             at org.apache.camel.processor.Pipeline.process(Pipeline.java:167)
             at org.apache.camel.impl.engine.CamelInternalProcessor.process(CamelInternalProcessor.java:388)
             at org.apache.camel.component.seda.SedaConsumer.sendToConsumers(SedaConsumer.java:269)
             at org.apache.camel.component.seda.SedaConsumer.doRun(SedaConsumer.java:187)
             at org.apache.camel.component.seda.SedaConsumer.run(SedaConsumer.java:130)
             at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
             at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
             at java.base/java.lang.Thread.run(Thread.java:834)
      Caused by: java.lang.IndexOutOfBoundsException: Key: PersonID not found in bean:  of type: java.lang.String using OGNL path [[PersonID]]
             at org.apache.camel.language.bean.BeanExpression.lookupResult(BeanExpression.java:540)
             at org.apache.camel.language.bean.BeanExpression.invokeOgnlMethod(BeanExpression.java:468)
             at org.apache.camel.language.bean.BeanExpression.evaluate(BeanExpression.java:199)
      

      in Camel 3.9.0.

      I have uploaded a project to https://github.com/PascalSchumacher/CamelSqlEmptyResult which makes it easy to reproduce this issue (just by changing the camel version in the POM).
       

       

      Attachments

        Issue Links

        Activity

          This comment will be Viewable by All Users Viewable by All Users
          Cancel

          People

            davsclaus Claus Ibsen
            pascalschumacher Pascal Schumacher
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Slack

                Issue deployment