Facing problems while using Set Header camel Processor

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Facing problems while using Set Header camel Processor

sailaja p
Hi All,

I am facing some difficulty when deploying a Camel Spring XML configuration with Message Translator pattern and Set Header Processor into Service mix 3.4.0.1.

I have defined a route with JMS Endpoint(TestMF)-> Set Header Processor (Xpath) -> JMS Endpoint (TestMF1) -> Message Translator (Header) -> Convert Body To (String) -> JMS Endpoint (TestMF2).

Below is my Camel configuration file and the input xml.

Camel Configuration

<beans xmlns="http://www.springframework.org/schema/beans"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd http://activemq.apache.org/camel/schema/spring http://activemq.apache.org/camel/schema/spring/camel-spring-1.5.0.xsd">
        <camelContext id="camelroute"
                xmlns="http://activemq.apache.org/camel/schema/spring">
                <route xmlns="http://activemq.apache.org/camel/schema/spring"
                        id="null_1">
                        <from uri="jms:queue:TestMF" id="JMS_0" />
                        <setHeader headerName="TestHeader" id="SetHeader_0">
                                <xpath>//Input</xpath>
                        </setHeader>
                        <to uri="jms:queue:TestMF1" id="JMS_1" />
                        <transform id="MessageTranslator_0">
                                <description>A special filter to translate one data format into another</description>
                                <header>TestHeader</header>
                        </transform>
                        <convertBodyTo type="java.lang.String" id="ConvertBodyTo_0">
                                <description>To convert using the default content type to a particular type</description>
                        </convertBodyTo>
                        <to uri="jms:queue:TestMF2" id="JMS_2" />
                </route>
        </camelContext>
</beans>

Input File is

<Sample>
<Input>Test</Input>
</Sample>

I am sending the above input xml to the JMS Endpoint (Q1). I was expecting that the Set Header Process adds a Header to the message and it assigns XPath Expression output as a Header value (TestHeader="Test"). But I didnt observe the header in the message received at JMS Endpoint (Q2). But the Message Translator is processing the message succesfully based on the header that is set by the Set Header Processor. I have two questions regarding this.

1. Why I didnt see the Header in the JMS Endpoint (Q2)?
2. Can I assign the node value to a header? Like assigning the following value to the header.

<Sample>
<Input><Value>Test</Value></Input>  ------> apply Xpath, /Sample/Input   ------->  assign this "<Value>1234</Value>" to a Header
</Sample>

Thanks in advance,
sailaja.
Reply | Threaded
Open this post in threaded view
|

Re: Facing problems while using Set Header camel Processor

Claus Ibsen-2
Hi

The JMS spec only allows a limited set of types and key names for JMS
properties (aka headers).
So its likely the result of the xpath expression is not a valid type
and thus its dropped.

You can use the Tracer to see how the message is routed and what it
contains at the different points in the route graph.
http://camel.apache.org/tracer.html

You can try changing the xpath to a constant instead that should be a valid type
<setHeader ...>
   <constant>1234</constant>
</setHeader>

You can force the xpath to return it as a valid JMS type, such as a
string by setting the resultType="java.lang.String" on the xpath.
See more here:
http://camel.apache.org/xpath.html




On Wed, Apr 29, 2009 at 7:04 AM, sailaja p <[hidden email]> wrote:

>
> Hi All,
>
> I am facing some difficulty when deploying a Camel Spring XML configuration
> with Message Translator pattern and Set Header Processor into Service mix
> 3.4.0.1.
>
> I have defined a route with JMS Endpoint(TestMF)-> Set Header Processor
> (Xpath) -> JMS Endpoint (TestMF1) -> Message Translator (Header) -> Convert
> Body To (String) -> JMS Endpoint (TestMF2).
>
> Below is my Camel configuration file and the input xml.
>
> Camel Configuration
>
> <beans xmlns="http://www.springframework.org/schema/beans"
>        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>        xsi:schemaLocation=" http://www.springframework.org/schema/beans
> http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
> http://activemq.apache.org/camel/schema/spring
> http://activemq.apache.org/camel/schema/spring/camel-spring-1.5.0.xsd">
>        <camelContext id="camelroute"
>                xmlns="http://activemq.apache.org/camel/schema/spring">
>                <route xmlns="http://activemq.apache.org/camel/schema/spring"
>                        id="null_1">
>                        <from uri="jms:queue:TestMF" id="JMS_0" />
>                        <setHeader headerName="TestHeader" id="SetHeader_0">
>                                <xpath>//Input</xpath>
>                        </setHeader>
>                        <to uri="jms:queue:TestMF1" id="JMS_1" />
>                        <transform id="MessageTranslator_0">
>                                <description>A special filter to translate one data format into
> another</description>
>                                <header>TestHeader</header>
>                        </transform>
>                        <convertBodyTo type="java.lang.String" id="ConvertBodyTo_0">
>                                <description>To convert using the default content type to a particular
> type</description>
>                        </convertBodyTo>
>                        <to uri="jms:queue:TestMF2" id="JMS_2" />
>                </route>
>        </camelContext>
> </beans>
>
> Input File is
>
> <Sample>
> <Input>Test</Input>
> </Sample>
>
> I am sending the above input xml to the JMS Endpoint (Q1). I was expecting
> that the Set Header Process adds a Header to the message and it assigns
> XPath Expression output as a Header value (TestHeader="Test"). But I didnt
> observe the header in the message received at JMS Endpoint (Q2). But the
> Message Translator is processing the message succesfully based on the header
> that is set by the Set Header Processor. I have two questions regarding
> this.
>
> 1. Why I didnt see the Header in the JMS Endpoint (Q2)?
> 2. Can I assign the node value to a header? Like assigning the following
> value to the header.
>
> <Sample>
> <Input><Value>Test</Value></Input>  ------> apply Xpath, /Sample/Input
> ------->  assign this "<Value>1234</Value>" to a Header
> </Sample>
>
> Thanks in advance,
> sailaja.
> --
> View this message in context: http://www.nabble.com/Facing-problems-while-using-Set-Header-camel-Processor-tp23290594p23290594.html
> Sent from the Camel - Development (activemq) mailing list archive at Nabble.com.
>
>



--
Claus Ibsen
Apache Camel Committer

Open Source Integration: http://fusesource.com
Blog: http://davsclaus.blogspot.com/
Twitter: http://twitter.com/davsclaus
Apache Camel Reference Card:
http://refcardz.dzone.com/refcardz/enterprise-integration
Reply | Threaded
Open this post in threaded view
|

Re: Facing problems while using Set Header camel Processor

RomKal
In reply to this post by sailaja p
Hello Sailaja,

There is another question - do you send your test message as InOnly or
InOut? In JMS world if you set JMSReplyTo property to some value Camel
will work as InOut flow, so sending the message to Q1
("jms:queue:TestMF1") will cause Camel to wait for the response and
will override all headers of your message with JMS properties of the
response.

If you want to preserve some value anyway you can set it as a property
instead of a header in Camel.

Roman

2009/4/29 sailaja p <[hidden email]>:

>
> Hi All,
>
> I am facing some difficulty when deploying a Camel Spring XML configuration
> with Message Translator pattern and Set Header Processor into Service mix
> 3.4.0.1.
>
> I have defined a route with JMS Endpoint(TestMF)-> Set Header Processor
> (Xpath) -> JMS Endpoint (TestMF1) -> Message Translator (Header) -> Convert
> Body To (String) -> JMS Endpoint (TestMF2).
>
> Below is my Camel configuration file and the input xml.
>
> Camel Configuration
>
> <beans xmlns="http://www.springframework.org/schema/beans"
>        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>        xsi:schemaLocation=" http://www.springframework.org/schema/beans
> http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
> http://activemq.apache.org/camel/schema/spring
> http://activemq.apache.org/camel/schema/spring/camel-spring-1.5.0.xsd">
>        <camelContext id="camelroute"
>                xmlns="http://activemq.apache.org/camel/schema/spring">
>                <route xmlns="http://activemq.apache.org/camel/schema/spring"
>                        id="null_1">
>                        <from uri="jms:queue:TestMF" id="JMS_0" />
>                        <setHeader headerName="TestHeader" id="SetHeader_0">
>                                <xpath>//Input</xpath>
>                        </setHeader>
>                        <to uri="jms:queue:TestMF1" id="JMS_1" />
>                        <transform id="MessageTranslator_0">
>                                <description>A special filter to translate one data format into
> another</description>
>                                <header>TestHeader</header>
>                        </transform>
>                        <convertBodyTo type="java.lang.String" id="ConvertBodyTo_0">
>                                <description>To convert using the default content type to a particular
> type</description>
>                        </convertBodyTo>
>                        <to uri="jms:queue:TestMF2" id="JMS_2" />
>                </route>
>        </camelContext>
> </beans>
>
> Input File is
>
> <Sample>
> <Input>Test</Input>
> </Sample>
>
> I am sending the above input xml to the JMS Endpoint (Q1). I was expecting
> that the Set Header Process adds a Header to the message and it assigns
> XPath Expression output as a Header value (TestHeader="Test"). But I didnt
> observe the header in the message received at JMS Endpoint (Q2). But the
> Message Translator is processing the message succesfully based on the header
> that is set by the Set Header Processor. I have two questions regarding
> this.
>
> 1. Why I didnt see the Header in the JMS Endpoint (Q2)?
> 2. Can I assign the node value to a header? Like assigning the following
> value to the header.
>
> <Sample>
> <Input><Value>Test</Value></Input>  ------> apply Xpath, /Sample/Input
> ------->  assign this "<Value>1234</Value>" to a Header
> </Sample>