ServiceMix 4
  1. ServiceMix 4
  2. SMX4-417

calling <setHeader> with <groovy> expression can delete message and headers

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 4.0.0
    • Fix Version/s: 4.3.0
    • Component/s: None
    • Labels:
      None
    • Environment:

      OSX 10.6.1, Java(TM) SE Runtime Environment (build 1.6.0_15-b03-219)

      Description

      I've got a route that takes an HTTP form post, does some transformations, and sends an email. One of the transforms I'd like to do is to set a header value based on the result of a Groovy expression. I found that setting a header with <groovy>...</groovy> clears out the entire exchange. Setting a header using <constant>...</constant> works fine.

      Here's a route that I'm using to diagnose this problem:

      <camelContext xmlns="http://activemq.apache.org/camel/schema/spring">
      <route>
      <from uri="jetty:http://0.0.0.0:8103/" />
      <to uri="log:from jetty?showAll=true" />
      <to uri="seda:transform" />
      </route>
      <route>
      <from uri="timer:mytimer?period=30000"/>
      <setHeader headerName="application">
      <constant>TEST</constant>
      </setHeader>
      <to uri="log:from timer?showAll=true" />
      <to uri="seda:transform"/>
      </route>
      <route>
      <from uri="seda:transform" />
      <setHeader headerName="fromGroovy">
      <groovy>"my header is $

      {in.headers.application}

      "</groovy>
      </setHeader>
      <to uri="log:after set header?showAll=true" />
      </route>
      </camelContext>

      Messages that originate from the timer look fine:

      12:31:49,332 | INFO | mer?period=30000 | from timer | rg.apache.camel.processor.Logger 88 | Exchange[Id:ID-iago.local/53297-1257192385112/0-16, Properties:

      {org.apache.camel.timer.name=mytimer, org.apache.camel.timer.firedTime=Mon Nov 02 12:31:49 PST 2009, org.apache.camel.timer.period=30000}

      , Headers:

      {application=TEST, firedTime=Mon Nov 02 12:31:49 PST 2009}

      , BodyType:null, Body:null, Out: null]
      12:31:49,335 | INFO | ansform thread:3 | after set header | rg.apache.camel.processor.Logger 88 | Exchange[Id:ID-iago.local/53297-1257192385112/0-17, Properties:

      {org.apache.camel.timer.name=mytimer, org.apache.camel.timer.firedTime=Mon Nov 02 12:31:49 PST 2009, org.apache.camel.timer.period=30000}

      , Headers:

      {application=TEST, fromGroovy=my header is TEST, firedTime=Mon Nov 02 12:31:49 PST 2009}

      , BodyType:null, Body:null, Out: null]

      Messages that originate in response to a request to http://localhost:8103/?application=TEST appear to be lost after the header is set with the <groovy> tag:

      12:32:03,607 | INFO | 34102763@qtp13-1 | from jetty | rg.apache.camel.processor.Logger 88 | Exchange[Id:ID-iago.local/53297-1257192385112/0-18, Properties:{}, Headers:

      {application=TEST, Host=localhost:8103, org.apache.camel.component.http.query=application=TEST, User-Agent=curl/7.19.0 (i386-apple-darwin9.7.0) libcurl/7.19.0 zlib/1.2.3, http.requestMethod=GET, Accept=*/*}

      , BodyType:org.apache.camel.converter.stream.StreamCacheConverter.InputStreamCache, Body:, Out: null]
      12:32:03,611 | INFO | ansform thread:3 | after set header | rg.apache.camel.processor.Logger 88 | Exchange[Id:ID-iago.local/53297-1257192385112/0-19, Properties:{}, Headers:{}, BodyType:null, Body:null, Out: null]

      The message after the <setHeader><groovy> is completely blank. I've tried building the route with the Java DSL but it does the same thing. Anything added after the <setHeader><groovy>... element is added to the message, but all previous contents were lost.

      1. SMX4-417.tar.gz
        2 kB
        Paul Mietz Egli

        Issue Links

          Activity

          Hide
          Paul Mietz Egli added a comment -

          OSGi module that reproduces this issue.

          Show
          Paul Mietz Egli added a comment - OSGi module that reproduces this issue.
          Hide
          Paul Mietz Egli added a comment -

          Steps to reproduce:

          1. Unpack apache-servicemix-4.0.0.tar.gz.
          2. Start ServiceMix and run "features/install camel-jetty" and "features/install camel-groovy".
          3. Build the attached project and copy the JAR file to $SERVICEMIX_HOME/deploy
          4. Tail the servicemix.log file to see the timer-initiated messages going by.
          5. Trigger a message from jetty using "curl http://localhost:8103/?application=TEST".

          Observation: message headers are lost for jetty but retained for timer.

          Show
          Paul Mietz Egli added a comment - Steps to reproduce: 1. Unpack apache-servicemix-4.0.0.tar.gz. 2. Start ServiceMix and run "features/install camel-jetty" and "features/install camel-groovy". 3. Build the attached project and copy the JAR file to $SERVICEMIX_HOME/deploy 4. Tail the servicemix.log file to see the timer-initiated messages going by. 5. Trigger a message from jetty using "curl http://localhost:8103/?application=TEST ". Observation: message headers are lost for jetty but retained for timer.
          Hide
          Paul Mietz Egli added a comment -

          workaround is to create a processor bean using Groovy instead:

          <route>
          <from uri="seda:transform" />
          <process ref="setToHeaderProcessor"/>
          <to uri="log:after set header?showAll=true" />
          </route>

          <lang:groovy id="setToHeaderProcessor">
          <lang:inline-script>
          <![CDATA[
          import org.apache.camel.*
          class SetToHeaderProcessor implements Processor {
          void process(Exchange exchange) {
          exchange.in.setHeader('application', "my header is $

          {exchange.in.headers.application}

          ")
          }
          }
          ]]>
          </lang:inline-script>
          </lang:groovy>

          (requires org.apache.camel.camel-core in the Required-Bundles section of the manifest)

          Show
          Paul Mietz Egli added a comment - workaround is to create a processor bean using Groovy instead: <route> <from uri="seda:transform" /> <process ref="setToHeaderProcessor"/> <to uri="log:after set header?showAll=true" /> </route> <lang:groovy id="setToHeaderProcessor"> <lang:inline-script> <![CDATA[ import org.apache.camel.* class SetToHeaderProcessor implements Processor { void process(Exchange exchange) { exchange.in.setHeader('application', "my header is $ {exchange.in.headers.application} ") } } ]]> </lang:inline-script> </lang:groovy> (requires org.apache.camel.camel-core in the Required-Bundles section of the manifest)
          Hide
          Peter Lundberg added a comment -

          I found a similar issue using just camel 2.0.0. The below snippet shows relevant parts of the route and the after logging is completely empty of body and header

          .to("log:before?showAll=true")
          .setHeader("test.foo").groovy("'$request.one.two $request.three'")
          .to("log:after?showAll=true")

          Show
          Peter Lundberg added a comment - I found a similar issue using just camel 2.0.0. The below snippet shows relevant parts of the route and the after logging is completely empty of body and header .to("log:before?showAll=true") .setHeader("test.foo").groovy("'$request.one.two $request.three'") .to("log:after?showAll=true")
          Hide
          Claus Ibsen added a comment -

          Just added an unit test to camel where I cannot reproduce the issue.

          Its based on 2.1 though
          http://svn.apache.org/viewvc?rev=884641&view=rev

          Show
          Claus Ibsen added a comment - Just added an unit test to camel where I cannot reproduce the issue. Its based on 2.1 though http://svn.apache.org/viewvc?rev=884641&view=rev
          Hide
          andrej koelewijn added a comment -

          This is still an issue in 2.3.0-fuse-01-00:

          The following route:

          from("jetty:http://localhost:8008/svc1?matchOnUriPrefix=true")
          .to("log:svc1.0?showAll=true")
          .setHeader("bsn",groovy("'abc123'"))
          .to("log:svc1.1?showAll=true")

          The second log has no headers or message. If you replace groovy by constant message and headers have values.

          Show
          andrej koelewijn added a comment - This is still an issue in 2.3.0-fuse-01-00: The following route: from("jetty: http://localhost:8008/svc1?matchOnUriPrefix=true ") .to("log:svc1.0?showAll=true") .setHeader("bsn",groovy("'abc123'")) .to("log:svc1.1?showAll=true") The second log has no headers or message. If you replace groovy by constant message and headers have values.
          Hide
          Claus Ibsen added a comment - - edited

          You should use setOutHeader as a work around.

          setHeader only sets the IN header, but the groovy script will populate a response as well, and hence the Exchange has both IN and OUT, but the out will be empty. Will look into it to make this work out of the box.

          Show
          Claus Ibsen added a comment - - edited You should use setOutHeader as a work around. setHeader only sets the IN header, but the groovy script will populate a response as well, and hence the Exchange has both IN and OUT, but the out will be empty. Will look into it to make this work out of the box.
          Hide
          Claus Ibsen added a comment -

          Okay its fixed now in Camel. And will be part of Apache Camel 2.4.0 release.

          Btw the setOutHeader workaround doesn't work either.

          Show
          Claus Ibsen added a comment - Okay its fixed now in Camel. And will be part of Apache Camel 2.4.0 release. Btw the setOutHeader workaround doesn't work either.
          Hide
          Claus Ibsen added a comment -

          Apache Camel 2.4.0 will be part of SMX 4.4.0

          Show
          Claus Ibsen added a comment - Apache Camel 2.4.0 will be part of SMX 4.4.0

            People

            • Assignee:
              Claus Ibsen
              Reporter:
              Paul Mietz Egli
            • Votes:
              1 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Development