6 Replies Latest reply on Jan 30, 2009 2:58 AM by davsclaus

    Sql component is reseting my Headers

    jklemm

      Hi,

       

      When I use the code below:

       

      .process(new EmptySQLParams()) // Set an empty list to body

      .setHeader("header_var", constant("string test!"))

       

      .process(

        new Processor() {

          public void process(Exchange exchange) throws Exception {

            // Here print "string test!"

            System.out.println( "header_var: " + exchange.getIn().getHeader("header_var", String.class) );

          }

        }

      )

       

      .to( "sql: select * from customer")

       

      .process(

        new Processor() {

          public void process(Exchange exchange) throws Exception {

            // Here print "null" .... not "string test!"

            System.out.println( "header_var: " + exchange.getIn().getHeader("header_var", String.class) );

          }

        }

      )

       

      Is this behavior by design or is it a bug ?

       

      So, Is there another way to store my variables besides using headers to do it ?

       

      Thanks,

        • 1. Re: Sql component is reseting my Headers
          davsclaus

          Hi

           

          The sql component might have a flaw there if it clears the headers.

           

          You can try to store it as a property on the Exchange directly and see if its kept.

           

          exchange.setProperty("foo", "bar");

           

          Feel free to create a bug report, about the clearning header at:

          http://camel.apache.org/support.html

          there is a link to JIRA on the page above.

          • 2. Re: Sql component is reseting my Headers
            davsclaus

            I created the bug reported and fixed it in the next Camel

            https://issues.apache.org/activemq/browse/CAMEL-1292

            • 3. Re: Sql component is reseting my Headers
              jklemm

              Hi,

               

              I will test setProperty....

               

              Thanks again.

              • 4. Re: Sql component is reseting my Headers
                jklemm

                Hi davsclaus,

                 

                I tested the setProperty() method and it works.

                 

                But, I have another question...

                 

                How do I use the choice syntax with a property ?

                 

                I have tried 2 syntaxes and they failed...

                 

                .choice()

                  .when().property("variable").equals(1)

                 

                .choice()

                  .when(property("variable").equals(1))

                 

                So, only passing the data of a property to Header works..

                 

                .setHeader("variable", getProperty("var"));

                 

                .choice()

                  .when(header("variable").isEqualTo(1))

                 

                Is there a way to do it with the property() method of DSL ?

                 

                Thanks,

                • 5. Re: Sql component is reseting my Headers
                  davsclaus

                  Hi

                   

                  Yeah the Java DSL and the compiler can get a bit spooked when you have some combinations.

                   

                  When you get to a bad point you kind on have java.lang.Object and its standard methods such as equal.

                   

                  That is why

                  choice()

                  .when().property("variable").equals(1)

                   

                  Does not work as it uses Object equals and not how its intentded.

                   

                  We have currently a discussion on the camel dev about use of header/properties. We tend to agree that properties has kinda been negleted a bit and is not promoted enough in the documentation and samples.

                   

                  Properties should be used for storing key/values that should preserve for the entire lifetime of the Exchange.

                   

                  That said the Java DSL should of course offer good builder method for using .properties as well.

                   

                  So what is missing is a better property expression directly in the DSL.

                   

                  You can probably (I have laptop at the couch in front of the TV so I cant do much coding)

                   

                  import the class ExpressionBuilder (or use static import of the method below)

                   

                  And use ExpressionBuilder.propertyExpression("variable") in the DSL

                   

                  .choice()

                  .when(ExpressionBuilder.propertyExpression("variable")).isEqualTo(1)

                   

                  I will check up on this tomorrow so we can have first class support for properties out-of-the-box in the Java and Spring DSL.

                  • 6. Re: Sql component is reseting my Headers
                    davsclaus

                    I have created a ticket at Apache for this, to add some samples and make sure we have first class support for properties in all the DSL's

                     

                    https://issues.apache.org/activemq/browse/CAMEL-1299