6 Replies Latest reply on Jan 28, 2011 6:52 AM by davsclaus

    http component-setheader-previousexchange

    feor58_gfericsan

      hi,

      i would like to build a route that periodically take a http message with "timestamp" parameter where the parameter is in the body of the previous message. (The first message haven't "timestamp" parameter.) I think the following theoretical schema:

       

      from timer

         choose

            when previousexchange is not null

               setheader("timestamp")

                  simple(previousexchange.getin.getbody)xpath(/timestamp)

            otherwise

               removeheader("timestamp")

            http uri

      ... processing...

       

      I would like to define the route with Spring DSL (xml).

       

      Could anyone help me?

       

      Thanks

        • 1. Re: http component-setheader-previousexchange
          davsclaus

          Use a bean or processor to store the previous timestamp, so you have it handy when the next exchange arrives.

           

          Then all logic for handling that is in the bean / processor and you dont clutter your DSL.

           

           

          from http

             process(new TimestampProcessor())

             to http

          • 2. Re: http component-setheader-previousexchange
            davsclaus

            And mind that the processor / bean is statefull (keep the previous timestamp around) so you may want to synchronize access to it if that really matters.

            • 3. Re: http component-setheader-previousexchange
              feor58_gfericsan

              Very useful info, thanks. But i am newbie so i don't understand exactly.  Would you describe in a bit more  detailed? Where is the from timer components?

              And is it impossible without Java code?

              Thanks.

              • 4. Re: http component-setheader-previousexchange
                davsclaus

                Yes its impossible without Java code, or in other words much harder.

                 

                You need to store the previous timestamp in memory somewhere. They easy part is just to use java code for it like a java bean.

                 

                For example something like this

                 

                public class TimestampProcessor implements Processor {
                
                private long previous;
                
                public void process(Exchange exchange) throws Exception {
                      long now = System.currentTimeInMillis();
                     if (previous == null) {
                           // this is the first time, do something here
                     } else {
                          // we have the previous timestamp do something else
                     }
                     // update timestamp
                     previous = now;
                }
                

                 

                • 5. Re: http component-setheader-previousexchange
                  feor58_gfericsan

                  hi Claus,

                  thanks for your help but my problem is a bit other. I have to include the timestamp parameter from the previous exchange's body into my current http request, then to process the current response. (When my reuqest don't have timestamp parameter then the response the full file, and when my request have timestamp parameter then only the changes are in the result since previous timestamp.)

                   

                  from(timer).

                  to(http://x/y.xml?timestamp=???) (The content of y.xml change continually.)

                  ...

                   

                  The http response (y,xml)

                   

                   

                   

                  In the first request must not be timestamp parameter.

                   

                  I think i can't to resolve this situation with your previous tip.

                  • 6. Re: http component-setheader-previousexchange
                    davsclaus

                    See the recipient list EIP pattern where you can define a dynamic endpoint uri to invoke in a route.

                     

                    http://camel.apache.org/recipient-list.html