You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by titexe <ti...@yahoo.Fr> on 2009/12/16 18:27:45 UTC
camel : xpath & text()
hello,
my xpath query does not work, when I put the text value () to finish:
/request/header/source/text()
body of my message :
<?xml version="1.0" encoding="UTF-8"?>
<request>
<header>
<source><![CDATA[ALLAH]]></source>
</header>
</request>
my route :
<route>
<from uri="activemq:queue:IN1"/>
<split>
<xpath>/request/header/source/text()</ xpath>
<t uri="activemq:queue:XML"/>
</ Split>
<t uri="activemq:queue:RESULT"/>
</ route>
any idea?
thanks in advance,
titexe
--
View this message in context: http://old.nabble.com/camel-%3A-xpath---text%28%29-tp26815065p26815065.html
Sent from the Camel - Users mailing list archive at Nabble.com.
Re: camel : xpath & text()
Posted by titexe <ti...@yahoo.Fr>.
you're right, it works:)
Thank you very much Claus.
titexe
Claus Ibsen-2 wrote:
>
> On Thu, Dec 17, 2009 at 9:34 AM, titexe <ti...@yahoo.fr> wrote:
>>
>> thank you for your answers,
>>
>> I am in testing phase, the solutions you have proposed
>>
>> Claus excuse me, I have to put your code (in which file camel.xml or
>> activemq.xml) and in each part?
>>
>
> No just proves the point that Stephen was wrong that you you CAN set
> the resultType when using xpath with XML.
>
> Such as:
> <xpath resultType="java.lang.String">foo/bar/text()</xpath>
>
>
>
>> thank you
>>
>>
>>
>> Claus Ibsen-2 wrote:
>>>
>>> On Thu, Dec 17, 2009 at 3:25 AM, Stephen Gargan <st...@gmail.com>
>>> wrote:
>>>> I'm guessing that you expected to receive the 'ALLAH' string at your
>>>> endpoint and were receiving a DeferredCDATASectionImpl object instead
>>>> is
>>>> this correct? The unit test below illustrates what is happening (it
>>>> uses
>>>> the
>>>> java DSL with the first of the 3 routes being pretty much the same as
>>>> what
>>>> your spring xml route is defining).
>>>>
>>>> The test 'testFailsDueToTypeConversion' shows that what you actually
>>>> receive
>>>> from the xpath split is a instance of DeferredCDATASectionImpl. I'm
>>>> guessing
>>>> you expected this to be a String and were trying to use value() to make
>>>> it
>>>> so. There are a couple of ways to do this as the rest of the test
>>>> shows.
>>>>
>>>> First and easiest is to use a result type in your xpath expression,
>>>> e.g.
>>>> xpath("/request/header/source/text()", String.class), this will
>>>> correctly
>>>> extract the data from the DeferredCDATASectionImpl object.
>>>> Unfortunately,
>>>> you cannot currently specify a result type in an XML route, though It
>>>> would
>>>> be an easy thing to add so maybe you should open a Jira ticket.
>>>>
>>>
>>> Yes you can specify that in Spring XML. There is an attribute for that.
>>>
>>> <xs:complexType name="xPathExpression">
>>> <xs:simpleContent>
>>> <xs:extension base="tns:namespaceAwareExpression">
>>> <xs:attribute name="resultType" type="xs:string"/>
>>> </xs:extension>
>>> </xs:simpleContent>
>>> </xs:complexType>
>>>
>>>> Secondly you could use an intermediate bean to grab the data from the
>>>> DeferredCDATASectionImpl and pass it on e.g. 'testWithBeanConversion.'
>>>>
>>>> Third and probably the best would be to add an explicit type converter
>>>> for
>>>> it. The test 'testWithRegisteredConverter' shows how using the
>>>> CDataTypeConverter bean below. There is excellent documentation on Type
>>>> converters at the Camel website
>>>> http://camel.apache.org/type-converter.html
>>>>
>>>> Hope this helps,
>>>>
>>>> ste
>>>>
>>>> public class CDataXPathTest extends ContextTestSupport
>>>> {
>>>> @Override
>>>> protected RouteBuilder createRouteBuilder() throws Exception
>>>> {
>>>> return new RouteBuilder()
>>>> {
>>>> @Override
>>>> public void configure() throws Exception
>>>> {
>>>>
>>>>
>>>> from("direct:xpath-no-conversion").split().xpath("/request/header/source/text()").to("mock:test");
>>>>
>>>> from("direct:xpath-with-result-type").split().xpath("/request/header/source/text()",
>>>> String.class).to("mock:test");
>>>>
>>>> from("direct:xpath-with-bean-converter").split().xpath("/request/header/source/text()").bean(new
>>>> MySourceProcessor()).to("mock:test");
>>>> }
>>>> };
>>>> }
>>>>
>>>> public void testFailsDueToTypeConversion() throws Exception
>>>> {
>>>> MockEndpoint mock = getMockEndpoint("mock:test");
>>>> mock.expectedMessageCount(1);
>>>>
>>>> String xml =
>>>> "<request><header><source><![CDATA[ALLAH]]></source></header></request>";
>>>> sendBody("direct:xpath-no-conversion", xml);
>>>>
>>>> mock.await();
>>>> mock.assertIsSatisfied();
>>>>
>>>> Object receieved =
>>>> ExchangeHelper.getMandatoryInBody(mock.getReceivedExchanges().get(0));
>>>> assertIsInstanceOf(DeferredCDATASectionImpl.class, receieved);
>>>> }
>>>>
>>>>
>>>> public void testWithResultTypeConversion() throws Exception
>>>> {
>>>> MockEndpoint mock = getMockEndpoint("mock:test");
>>>> mock.expectedBodiesReceived("ALLAH");
>>>>
>>>> String xml =
>>>> "<request><header><source><![CDATA[ALLAH]]></source></header></request>";
>>>> sendBody("direct:xpath-with-result-type", xml);
>>>>
>>>> mock.await();
>>>> mock.assertIsSatisfied();
>>>> }
>>>>
>>>> public void testWithBeanConversion() throws Exception
>>>> {
>>>> MockEndpoint mock = getMockEndpoint("mock:test");
>>>> mock.expectedBodiesReceived("ALLAH");
>>>>
>>>> String xml =
>>>> "<request><header><source><![CDATA[ALLAH]]></source></header></request>";
>>>> sendBody("direct:xpath-with-bean-converter", xml);
>>>>
>>>> mock.await();
>>>> mock.assertIsSatisfied();
>>>> }
>>>>
>>>> public void testWithRegisteredConverter() throws Exception
>>>> {
>>>>
>>>> context.getTypeConverterRegistry().addTypeConverter(String.class,
>>>> DeferredCDATASectionImpl.class, new CDataTypeConverter());
>>>> MockEndpoint mock = getMockEndpoint("mock:test");
>>>> mock.expectedBodiesReceived("ALLAH");
>>>>
>>>> String xml =
>>>> "<request><header><source><![CDATA[ALLAH]]></source></header></request>";
>>>> sendBody("direct:xpath-no-conversion", xml);
>>>>
>>>> mock.await();
>>>> mock.assertIsSatisfied();
>>>> }
>>>>
>>>> public static class MySourceProcessor
>>>> {
>>>> public String handleCdata(DeferredCDATASectionImpl payload)
>>>> {
>>>> return payload.getData();
>>>> }
>>>> }
>>>>
>>>> public static class CDataTypeConverter implements TypeConverter
>>>> {
>>>> public <T> T convertTo(Class<T> type, Object value) {
>>>> DeferredCDATASectionImpl cdata =
>>>> (DeferredCDATASectionImpl)value;
>>>> return (T) cdata.getData();
>>>> }
>>>>
>>>> public <T> T convertTo(Class<T> type, Exchange exchange, Object
>>>> value) {
>>>> return convertTo(type, value);
>>>> }
>>>>
>>>> public <T> T mandatoryConvertTo(Class<T> type, Object value) {
>>>> return convertTo(type, value);
>>>> }
>>>>
>>>> public <T> T mandatoryConvertTo(Class<T> type, Exchange
>>>> exchange,
>>>> Object value) {
>>>> return convertTo(type, value);
>>>> }
>>>> }
>>>> }
>>>>
>>>> On Wed, Dec 16, 2009 at 9:27 AM, titexe <ti...@yahoo.fr> wrote:
>>>>
>>>>>
>>>>> hello,
>>>>>
>>>>> my xpath query does not work, when I put the text value () to finish:
>>>>>
>>>>> /request/header/source/text()
>>>>>
>>>>> body of my message :
>>>>>
>>>>> <?xml version="1.0" encoding="UTF-8"?>
>>>>> <request>
>>>>> <header>
>>>>> <source><![CDATA[ALLAH]]></source>
>>>>> </header>
>>>>> </request>
>>>>>
>>>>>
>>>>> my route :
>>>>>
>>>>> <route>
>>>>> <from uri="activemq:queue:IN1"/>
>>>>> <split>
>>>>> <xpath>/request/header/source/text()</ xpath>
>>>>>
>>>>> <t uri="activemq:queue:XML"/>
>>>>> </ Split>
>>>>> <t uri="activemq:queue:RESULT"/>
>>>>> </ route>
>>>>>
>>>>> any idea?
>>>>>
>>>>> thanks in advance,
>>>>>
>>>>> titexe
>>>>> --
>>>>> View this message in context:
>>>>> http://old.nabble.com/camel-%3A-xpath---text%28%29-tp26815065p26815065.html
>>>>> Sent from the Camel - Users mailing list archive at Nabble.com.
>>>>>
>>>>>
>>>>
>>>
>>>
>>>
>>> --
>>> Claus Ibsen
>>> Apache Camel Committer
>>>
>>> Author of Camel in Action: http://www.manning.com/ibsen/
>>> Open Source Integration: http://fusesource.com
>>> Blog: http://davsclaus.blogspot.com/
>>> Twitter: http://twitter.com/davsclaus
>>>
>>>
>>
>> --
>> View this message in context:
>> http://old.nabble.com/camel-%3A-xpath---text%28%29-tp26815065p26824799.html
>> Sent from the Camel - Users mailing list archive at Nabble.com.
>>
>>
>
>
>
> --
> Claus Ibsen
> Apache Camel Committer
>
> Author of Camel in Action: http://www.manning.com/ibsen/
> Open Source Integration: http://fusesource.com
> Blog: http://davsclaus.blogspot.com/
> Twitter: http://twitter.com/davsclaus
>
>
--
View this message in context: http://old.nabble.com/camel-%3A-xpath---text%28%29-tp26815065p26825824.html
Sent from the Camel - Users mailing list archive at Nabble.com.
Re: camel : xpath & text()
Posted by Claus Ibsen <cl...@gmail.com>.
On Thu, Dec 17, 2009 at 9:34 AM, titexe <ti...@yahoo.fr> wrote:
>
> thank you for your answers,
>
> I am in testing phase, the solutions you have proposed
>
> Claus excuse me, I have to put your code (in which file camel.xml or
> activemq.xml) and in each part?
>
No just proves the point that Stephen was wrong that you you CAN set
the resultType when using xpath with XML.
Such as:
<xpath resultType="java.lang.String">foo/bar/text()</xpath>
> thank you
>
>
>
> Claus Ibsen-2 wrote:
>>
>> On Thu, Dec 17, 2009 at 3:25 AM, Stephen Gargan <st...@gmail.com>
>> wrote:
>>> I'm guessing that you expected to receive the 'ALLAH' string at your
>>> endpoint and were receiving a DeferredCDATASectionImpl object instead is
>>> this correct? The unit test below illustrates what is happening (it uses
>>> the
>>> java DSL with the first of the 3 routes being pretty much the same as
>>> what
>>> your spring xml route is defining).
>>>
>>> The test 'testFailsDueToTypeConversion' shows that what you actually
>>> receive
>>> from the xpath split is a instance of DeferredCDATASectionImpl. I'm
>>> guessing
>>> you expected this to be a String and were trying to use value() to make
>>> it
>>> so. There are a couple of ways to do this as the rest of the test shows.
>>>
>>> First and easiest is to use a result type in your xpath expression, e.g.
>>> xpath("/request/header/source/text()", String.class), this will correctly
>>> extract the data from the DeferredCDATASectionImpl object. Unfortunately,
>>> you cannot currently specify a result type in an XML route, though It
>>> would
>>> be an easy thing to add so maybe you should open a Jira ticket.
>>>
>>
>> Yes you can specify that in Spring XML. There is an attribute for that.
>>
>> <xs:complexType name="xPathExpression">
>> <xs:simpleContent>
>> <xs:extension base="tns:namespaceAwareExpression">
>> <xs:attribute name="resultType" type="xs:string"/>
>> </xs:extension>
>> </xs:simpleContent>
>> </xs:complexType>
>>
>>> Secondly you could use an intermediate bean to grab the data from the
>>> DeferredCDATASectionImpl and pass it on e.g. 'testWithBeanConversion.'
>>>
>>> Third and probably the best would be to add an explicit type converter
>>> for
>>> it. The test 'testWithRegisteredConverter' shows how using the
>>> CDataTypeConverter bean below. There is excellent documentation on Type
>>> converters at the Camel website
>>> http://camel.apache.org/type-converter.html
>>>
>>> Hope this helps,
>>>
>>> ste
>>>
>>> public class CDataXPathTest extends ContextTestSupport
>>> {
>>> @Override
>>> protected RouteBuilder createRouteBuilder() throws Exception
>>> {
>>> return new RouteBuilder()
>>> {
>>> @Override
>>> public void configure() throws Exception
>>> {
>>>
>>>
>>> from("direct:xpath-no-conversion").split().xpath("/request/header/source/text()").to("mock:test");
>>>
>>> from("direct:xpath-with-result-type").split().xpath("/request/header/source/text()",
>>> String.class).to("mock:test");
>>>
>>> from("direct:xpath-with-bean-converter").split().xpath("/request/header/source/text()").bean(new
>>> MySourceProcessor()).to("mock:test");
>>> }
>>> };
>>> }
>>>
>>> public void testFailsDueToTypeConversion() throws Exception
>>> {
>>> MockEndpoint mock = getMockEndpoint("mock:test");
>>> mock.expectedMessageCount(1);
>>>
>>> String xml =
>>> "<request><header><source><![CDATA[ALLAH]]></source></header></request>";
>>> sendBody("direct:xpath-no-conversion", xml);
>>>
>>> mock.await();
>>> mock.assertIsSatisfied();
>>>
>>> Object receieved =
>>> ExchangeHelper.getMandatoryInBody(mock.getReceivedExchanges().get(0));
>>> assertIsInstanceOf(DeferredCDATASectionImpl.class, receieved);
>>> }
>>>
>>>
>>> public void testWithResultTypeConversion() throws Exception
>>> {
>>> MockEndpoint mock = getMockEndpoint("mock:test");
>>> mock.expectedBodiesReceived("ALLAH");
>>>
>>> String xml =
>>> "<request><header><source><![CDATA[ALLAH]]></source></header></request>";
>>> sendBody("direct:xpath-with-result-type", xml);
>>>
>>> mock.await();
>>> mock.assertIsSatisfied();
>>> }
>>>
>>> public void testWithBeanConversion() throws Exception
>>> {
>>> MockEndpoint mock = getMockEndpoint("mock:test");
>>> mock.expectedBodiesReceived("ALLAH");
>>>
>>> String xml =
>>> "<request><header><source><![CDATA[ALLAH]]></source></header></request>";
>>> sendBody("direct:xpath-with-bean-converter", xml);
>>>
>>> mock.await();
>>> mock.assertIsSatisfied();
>>> }
>>>
>>> public void testWithRegisteredConverter() throws Exception
>>> {
>>> context.getTypeConverterRegistry().addTypeConverter(String.class,
>>> DeferredCDATASectionImpl.class, new CDataTypeConverter());
>>> MockEndpoint mock = getMockEndpoint("mock:test");
>>> mock.expectedBodiesReceived("ALLAH");
>>>
>>> String xml =
>>> "<request><header><source><![CDATA[ALLAH]]></source></header></request>";
>>> sendBody("direct:xpath-no-conversion", xml);
>>>
>>> mock.await();
>>> mock.assertIsSatisfied();
>>> }
>>>
>>> public static class MySourceProcessor
>>> {
>>> public String handleCdata(DeferredCDATASectionImpl payload)
>>> {
>>> return payload.getData();
>>> }
>>> }
>>>
>>> public static class CDataTypeConverter implements TypeConverter
>>> {
>>> public <T> T convertTo(Class<T> type, Object value) {
>>> DeferredCDATASectionImpl cdata =
>>> (DeferredCDATASectionImpl)value;
>>> return (T) cdata.getData();
>>> }
>>>
>>> public <T> T convertTo(Class<T> type, Exchange exchange, Object
>>> value) {
>>> return convertTo(type, value);
>>> }
>>>
>>> public <T> T mandatoryConvertTo(Class<T> type, Object value) {
>>> return convertTo(type, value);
>>> }
>>>
>>> public <T> T mandatoryConvertTo(Class<T> type, Exchange exchange,
>>> Object value) {
>>> return convertTo(type, value);
>>> }
>>> }
>>> }
>>>
>>> On Wed, Dec 16, 2009 at 9:27 AM, titexe <ti...@yahoo.fr> wrote:
>>>
>>>>
>>>> hello,
>>>>
>>>> my xpath query does not work, when I put the text value () to finish:
>>>>
>>>> /request/header/source/text()
>>>>
>>>> body of my message :
>>>>
>>>> <?xml version="1.0" encoding="UTF-8"?>
>>>> <request>
>>>> <header>
>>>> <source><![CDATA[ALLAH]]></source>
>>>> </header>
>>>> </request>
>>>>
>>>>
>>>> my route :
>>>>
>>>> <route>
>>>> <from uri="activemq:queue:IN1"/>
>>>> <split>
>>>> <xpath>/request/header/source/text()</ xpath>
>>>>
>>>> <t uri="activemq:queue:XML"/>
>>>> </ Split>
>>>> <t uri="activemq:queue:RESULT"/>
>>>> </ route>
>>>>
>>>> any idea?
>>>>
>>>> thanks in advance,
>>>>
>>>> titexe
>>>> --
>>>> View this message in context:
>>>> http://old.nabble.com/camel-%3A-xpath---text%28%29-tp26815065p26815065.html
>>>> Sent from the Camel - Users mailing list archive at Nabble.com.
>>>>
>>>>
>>>
>>
>>
>>
>> --
>> Claus Ibsen
>> Apache Camel Committer
>>
>> Author of Camel in Action: http://www.manning.com/ibsen/
>> Open Source Integration: http://fusesource.com
>> Blog: http://davsclaus.blogspot.com/
>> Twitter: http://twitter.com/davsclaus
>>
>>
>
> --
> View this message in context: http://old.nabble.com/camel-%3A-xpath---text%28%29-tp26815065p26824799.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>
>
--
Claus Ibsen
Apache Camel Committer
Author of Camel in Action: http://www.manning.com/ibsen/
Open Source Integration: http://fusesource.com
Blog: http://davsclaus.blogspot.com/
Twitter: http://twitter.com/davsclaus
Re: how to implement the instrumentation of from-endpoint?(Should camel to support the route level interceptor)
Posted by ext2 <xu...@tongtech.com>.
Thanks a lot.
It's just what I needed;
---------------------------------------------------------------------------
on 2010/10/22 12:38 Willem Jiang [mailto:willem.jiang@gmail.com] wrote
Re: how to implement the instrumentation of from-endpoint?(Should camel to
support the route level interceptor)
There is an InterceptFrom DSL[1] that can meet you requirement.
[1]http://camel.apache.org/intercept.html#Intercept-InterceptFrom
On 10/22/10 12:01 PM, ext2 wrote:
>
>
> Hi:
> Camel support interceptors for processor, but recently I encounter a
> requirement, it ask for a custom instrumentation strategy of from
endpoint;
> for example , we need the statistics of how much times the message is
> successfully processed in a given time, and how much message is failed;
>
> I think we could have three choice to achieve such purpose.
> 1) Do instrument things, in the from-endpoint.
> it's bad, because it need to change the code of camel's
> consumer
>
> 2) Extend a policy processor to wrapper the whole route, and do
> measurement
> It seems the solution is too heavy. But the solution does
> works, and now I am using this solution in my work;
>
> 3) Support a route level interceptor (just like the processor's
> interceptor, but it will wrapper the whole route).
> It seems the solution is more lightweight than the policy-processor.
> How about to add such the support in camel?
>
> Thanks any suggestion
>
>
>
>
>
>
--
Willem
----------------------------------
Open Source Integration: http://www.fusesource.com
Blog: http://willemjiang.blogspot.com (English)
http://jnn.javaeye.com (Chinese)
Twitter: http://twitter.com/willemjiang
Re: how to implement the instrumentation of from-endpoint?(Should
camel to support the route level interceptor)
Posted by Willem Jiang <wi...@gmail.com>.
There is an InterceptFrom DSL[1] that can meet you requirement.
[1]http://camel.apache.org/intercept.html#Intercept-InterceptFrom
On 10/22/10 12:01 PM, ext2 wrote:
>
>
> Hi:
> Camel support interceptors for processor, but recently I encounter a
> requirement, it ask for a custom instrumentation strategy of from endpoint;
> for example , we need the statistics of how much times the message is
> successfully processed in a given time, and how much message is failed;
>
> I think we could have three choice to achieve such purpose.
> 1) Do instrument things, in the from-endpoint.
> it's bad, because it need to change the code of camel's
> consumer
>
> 2) Extend a policy processor to wrapper the whole route, and do
> measurement
> It seems the solution is too heavy. But the solution does
> works, and now I am using this solution in my work;
>
> 3) Support a route level interceptor (just like the processor's
> interceptor, but it will wrapper the whole route).
> It seems the solution is more lightweight than the policy-processor.
> How about to add such the support in camel?
>
> Thanks any suggestion
>
>
>
>
>
>
--
Willem
----------------------------------
Open Source Integration: http://www.fusesource.com
Blog: http://willemjiang.blogspot.com (English)
http://jnn.javaeye.com (Chinese)
Twitter: http://twitter.com/willemjiang
Re: Could camel support configurable interceptor strategy in spring?
Posted by Claus Ibsen <cl...@gmail.com>.
On Fri, Oct 22, 2010 at 9:19 AM, ext2 <xu...@tongtech.com> wrote:
> Hi, Clause:
>
> Thanks a lot;
> I am sorry for my poor knowledge about Orader.
> I have just reviewed the source code of camel-core, camel-spring,camel-xml.
> But I haven't found the source code to control the wrapper-sequence of
> interceptor strategy by Ordered;
>
> Do you means my interceptor-strategy can implement the Ordered interface ,
> then the camel could sequence to load these strategies by the order?
>
> For example if I write two interceptor-strategy(A , B), if A's order is 0,
> and B's order is 1. the camel will always wrapper the processor as
> {A{B{Processor}}.
>
Yeah something like that AFAIR.
>
> ============================================================================
> On Fri, Oct 22, 2010 Claus Ibsen [mailto:claus.ibsen@gmail.com] wrote:
> Re: Could camel support configurable interceptor strategy in spring?
>
> On Fri, Oct 22, 2010 at 7:39 AM, ext2 <xu...@tongtech.com> wrote:
>> Thanks a lot. I see;
>>
>> Camel could look up all the configured interceptor-strategies in spring
>> application context. But unfortunately, it seems we couldn't control the
>> wrap order of interceptor-strategies;
>>
>
> Can you try implement the org.apache.camel.util.Ordered interface from
> Camel and that way control the order.
>
>
>>
> ============================================================================
>> On 2010/10/22 12:29 Willem Jiang Wrote
>> Re: Could camel support configurable interceptor strategy in spring?
>>
>> You can just add the InterceptorStrategies into the application,
>> CamelContextFactoryBean will pick up these interceptorStrategies and set
>> them into the camelContext.
>>
>> You can find the code in the afterPropertiesSet() method of
>> AbstractCamelContextFactoryBean[1].
>>
>>
> [1]https://svn.apache.org/repos/asf/camel/trunk/components/camel-core-xml/sr
>> c/main/java/org/apache/camel/core/xml/AbstractCamelContextFactoryBean.java
>>
>> On 10/22/10 12:15 PM, ext2 wrote:
>>> Hi:
>>> Camel's Context support a low level
>>> API(CamelContext.addInterceptStrategy), which we could use it to add our
>>> custom interceptor-strategy in Java DSL program;
>>> But while using Spring DSL, it seems there is no such a
>>> configuration we can use to configure the custom interceptor-strategy;
>>> How about to add such a support?
>>>
>>> It may looks like as following:
>>> <beans>
>>> <bean id="interceptorStrategyList"
>>> class="org.apache.camel.InterceptorStrategyList ">
>>> <camel:context>
>>> ...
>>> </camel:context>
>>> </beans>
>>> The bean "interceptorStrategyList" support a method to return a
> list
>>> of custom interceptor strategy; And camel-spring could find the bean and
>>> register the interceptors into camelContext;
>>>
>>> Thanks any suggestion
>>>
>>>
>>>
>>
>>
>> --
>> Willem
>> ----------------------------------
>> Open Source Integration: http://www.fusesource.com
>> Blog: http://willemjiang.blogspot.com (English)
>> http://jnn.javaeye.com (Chinese)
>> Twitter: http://twitter.com/willemjiang
>>
>>
>>
>
>
>
> --
> Claus Ibsen
> Apache Camel Committer
>
> Author of Camel in Action: http://www.manning.com/ibsen/
> Open Source Integration: http://fusesource.com
> Blog: http://davsclaus.blogspot.com/
> Twitter: http://twitter.com/davsclaus
>
>
>
--
Claus Ibsen
Apache Camel Committer
Author of Camel in Action: http://www.manning.com/ibsen/
Open Source Integration: http://fusesource.com
Blog: http://davsclaus.blogspot.com/
Twitter: http://twitter.com/davsclaus
Re: Could camel support configurable interceptor strategy in spring?
Posted by ext2 <xu...@tongtech.com>.
Hi, Clause:
Thanks a lot;
I am sorry for my poor knowledge about Orader.
I have just reviewed the source code of camel-core, camel-spring,camel-xml.
But I haven't found the source code to control the wrapper-sequence of
interceptor strategy by Ordered;
Do you means my interceptor-strategy can implement the Ordered interface ,
then the camel could sequence to load these strategies by the order?
For example if I write two interceptor-strategy(A , B), if A's order is 0,
and B's order is 1. the camel will always wrapper the processor as
{A{B{Processor}}.
============================================================================
On Fri, Oct 22, 2010 Claus Ibsen [mailto:claus.ibsen@gmail.com] wrote:
Re: Could camel support configurable interceptor strategy in spring?
On Fri, Oct 22, 2010 at 7:39 AM, ext2 <xu...@tongtech.com> wrote:
> Thanks a lot. I see;
>
> Camel could look up all the configured interceptor-strategies in spring
> application context. But unfortunately, it seems we couldn't control the
> wrap order of interceptor-strategies;
>
Can you try implement the org.apache.camel.util.Ordered interface from
Camel and that way control the order.
>
============================================================================
> On 2010/10/22 12:29 Willem Jiang Wrote
> Re: Could camel support configurable interceptor strategy in spring?
>
> You can just add the InterceptorStrategies into the application,
> CamelContextFactoryBean will pick up these interceptorStrategies and set
> them into the camelContext.
>
> You can find the code in the afterPropertiesSet() method of
> AbstractCamelContextFactoryBean[1].
>
>
[1]https://svn.apache.org/repos/asf/camel/trunk/components/camel-core-xml/sr
> c/main/java/org/apache/camel/core/xml/AbstractCamelContextFactoryBean.java
>
> On 10/22/10 12:15 PM, ext2 wrote:
>> Hi:
>> Camel's Context support a low level
>> API(CamelContext.addInterceptStrategy), which we could use it to add our
>> custom interceptor-strategy in Java DSL program;
>> But while using Spring DSL, it seems there is no such a
>> configuration we can use to configure the custom interceptor-strategy;
>> How about to add such a support?
>>
>> It may looks like as following:
>> <beans>
>> <bean id="interceptorStrategyList"
>> class="org.apache.camel.InterceptorStrategyList ">
>> <camel:context>
>> ...
>> </camel:context>
>> </beans>
>> The bean "interceptorStrategyList" support a method to return a
list
>> of custom interceptor strategy; And camel-spring could find the bean and
>> register the interceptors into camelContext;
>>
>> Thanks any suggestion
>>
>>
>>
>
>
> --
> Willem
> ----------------------------------
> Open Source Integration: http://www.fusesource.com
> Blog: http://willemjiang.blogspot.com (English)
> http://jnn.javaeye.com (Chinese)
> Twitter: http://twitter.com/willemjiang
>
>
>
--
Claus Ibsen
Apache Camel Committer
Author of Camel in Action: http://www.manning.com/ibsen/
Open Source Integration: http://fusesource.com
Blog: http://davsclaus.blogspot.com/
Twitter: http://twitter.com/davsclaus
Re: : Could camel support configurable interceptor strategy in spring?
Posted by Claus Ibsen <cl...@gmail.com>.
On Fri, Oct 22, 2010 at 7:39 AM, ext2 <xu...@tongtech.com> wrote:
> Thanks a lot. I see;
>
> Camel could look up all the configured interceptor-strategies in spring
> application context. But unfortunately, it seems we couldn't control the
> wrap order of interceptor-strategies;
>
Can you try implement the org.apache.camel.util.Ordered interface from
Camel and that way control the order.
> ============================================================================
> On 2010/10/22 12:29 Willem Jiang Wrote
> Re: Could camel support configurable interceptor strategy in spring?
>
> You can just add the InterceptorStrategies into the application,
> CamelContextFactoryBean will pick up these interceptorStrategies and set
> them into the camelContext.
>
> You can find the code in the afterPropertiesSet() method of
> AbstractCamelContextFactoryBean[1].
>
> [1]https://svn.apache.org/repos/asf/camel/trunk/components/camel-core-xml/sr
> c/main/java/org/apache/camel/core/xml/AbstractCamelContextFactoryBean.java
>
> On 10/22/10 12:15 PM, ext2 wrote:
>> Hi:
>> Camel's Context support a low level
>> API(CamelContext.addInterceptStrategy), which we could use it to add our
>> custom interceptor-strategy in Java DSL program;
>> But while using Spring DSL, it seems there is no such a
>> configuration we can use to configure the custom interceptor-strategy;
>> How about to add such a support?
>>
>> It may looks like as following:
>> <beans>
>> <bean id="interceptorStrategyList"
>> class="org.apache.camel.InterceptorStrategyList ">
>> <camel:context>
>> ...
>> </camel:context>
>> </beans>
>> The bean "interceptorStrategyList" support a method to return a list
>> of custom interceptor strategy; And camel-spring could find the bean and
>> register the interceptors into camelContext;
>>
>> Thanks any suggestion
>>
>>
>>
>
>
> --
> Willem
> ----------------------------------
> Open Source Integration: http://www.fusesource.com
> Blog: http://willemjiang.blogspot.com (English)
> http://jnn.javaeye.com (Chinese)
> Twitter: http://twitter.com/willemjiang
>
>
>
--
Claus Ibsen
Apache Camel Committer
Author of Camel in Action: http://www.manning.com/ibsen/
Open Source Integration: http://fusesource.com
Blog: http://davsclaus.blogspot.com/
Twitter: http://twitter.com/davsclaus
: Could camel support configurable interceptor strategy in spring?
Posted by ext2 <xu...@tongtech.com>.
Thanks a lot. I see;
Camel could look up all the configured interceptor-strategies in spring
application context. But unfortunately, it seems we couldn't control the
wrap order of interceptor-strategies;
============================================================================
On 2010/10/22 12:29 Willem Jiang Wrote
Re: Could camel support configurable interceptor strategy in spring?
You can just add the InterceptorStrategies into the application,
CamelContextFactoryBean will pick up these interceptorStrategies and set
them into the camelContext.
You can find the code in the afterPropertiesSet() method of
AbstractCamelContextFactoryBean[1].
[1]https://svn.apache.org/repos/asf/camel/trunk/components/camel-core-xml/sr
c/main/java/org/apache/camel/core/xml/AbstractCamelContextFactoryBean.java
On 10/22/10 12:15 PM, ext2 wrote:
> Hi:
> Camel's Context support a low level
> API(CamelContext.addInterceptStrategy), which we could use it to add our
> custom interceptor-strategy in Java DSL program;
> But while using Spring DSL, it seems there is no such a
> configuration we can use to configure the custom interceptor-strategy;
> How about to add such a support?
>
> It may looks like as following:
> <beans>
> <bean id="interceptorStrategyList"
> class="org.apache.camel.InterceptorStrategyList ">
> <camel:context>
> ...
> </camel:context>
> </beans>
> The bean "interceptorStrategyList" support a method to return a list
> of custom interceptor strategy; And camel-spring could find the bean and
> register the interceptors into camelContext;
>
> Thanks any suggestion
>
>
>
--
Willem
----------------------------------
Open Source Integration: http://www.fusesource.com
Blog: http://willemjiang.blogspot.com (English)
http://jnn.javaeye.com (Chinese)
Twitter: http://twitter.com/willemjiang
Re: Could camel support configurable interceptor strategy in spring?
Posted by Willem Jiang <wi...@gmail.com>.
You can just add the InterceptorStrategies into the application,
CamelContextFactoryBean will pick up these interceptorStrategies and set
them into the camelContext.
You can find the code in the afterPropertiesSet() method of
AbstractCamelContextFactoryBean[1].
[1]https://svn.apache.org/repos/asf/camel/trunk/components/camel-core-xml/src/main/java/org/apache/camel/core/xml/AbstractCamelContextFactoryBean.java
On 10/22/10 12:15 PM, ext2 wrote:
> Hi:
> Camel's Context support a low level
> API(CamelContext.addInterceptStrategy), which we could use it to add our
> custom interceptor-strategy in Java DSL program;
> But while using Spring DSL, it seems there is no such a
> configuration we can use to configure the custom interceptor-strategy;
> How about to add such a support?
>
> It may looks like as following:
> <beans>
> <bean id="interceptorStrategyList"
> class="org.apache.camel.InterceptorStrategyList ">
> <camel:context>
> ...
> </camel:context>
> </beans>
> The bean "interceptorStrategyList" support a method to return a list
> of custom interceptor strategy; And camel-spring could find the bean and
> register the interceptors into camelContext;
>
> Thanks any suggestion
>
>
>
--
Willem
----------------------------------
Open Source Integration: http://www.fusesource.com
Blog: http://willemjiang.blogspot.com (English)
http://jnn.javaeye.com (Chinese)
Twitter: http://twitter.com/willemjiang
Re: Could camel support configurable interceptor strategy in spring?
Posted by Claus Ibsen <cl...@gmail.com>.
Hi
See this page
http://camel.apache.org/advanced-configuration-of-camelcontext-using-spring.html
On Fri, Oct 22, 2010 at 6:15 AM, ext2 <xu...@tongtech.com> wrote:
> Hi:
> Camel's Context support a low level
> API(CamelContext.addInterceptStrategy), which we could use it to add our
> custom interceptor-strategy in Java DSL program;
> But while using Spring DSL, it seems there is no such a
> configuration we can use to configure the custom interceptor-strategy;
> How about to add such a support?
>
> It may looks like as following:
> <beans>
> <bean id="interceptorStrategyList"
> class="org.apache.camel.InterceptorStrategyList ">
> <camel:context>
> ...
> </camel:context>
> </beans>
> The bean "interceptorStrategyList" support a method to return a list
> of custom interceptor strategy; And camel-spring could find the bean and
> register the interceptors into camelContext;
>
> Thanks any suggestion
>
>
>
--
Claus Ibsen
Apache Camel Committer
Author of Camel in Action: http://www.manning.com/ibsen/
Open Source Integration: http://fusesource.com
Blog: http://davsclaus.blogspot.com/
Twitter: http://twitter.com/davsclaus
Could camel support configurable interceptor strategy in spring?
Posted by ext2 <xu...@tongtech.com>.
Hi:
Camel's Context support a low level
API(CamelContext.addInterceptStrategy), which we could use it to add our
custom interceptor-strategy in Java DSL program;
But while using Spring DSL, it seems there is no such a
configuration we can use to configure the custom interceptor-strategy;
How about to add such a support?
It may looks like as following:
<beans>
<bean id="interceptorStrategyList"
class="org.apache.camel.InterceptorStrategyList ">
<camel:context>
...
</camel:context>
</beans>
The bean "interceptorStrategyList" support a method to return a list
of custom interceptor strategy; And camel-spring could find the bean and
register the interceptors into camelContext;
Thanks any suggestion
Re: how to implement the instrumentation of from-endpoint?(Should
camel to support the route level interceptor)
Posted by Claus Ibsen <cl...@gmail.com>.
See also
http://camel.apache.org/eventnotifier-to-log-details-about-all-sent-exchanges.html
On Fri, Oct 22, 2010 at 6:01 AM, ext2 <xu...@tongtech.com> wrote:
>
>
> Hi:
> Camel support interceptors for processor, but recently I encounter a
> requirement, it ask for a custom instrumentation strategy of from endpoint;
> for example , we need the statistics of how much times the message is
> successfully processed in a given time, and how much message is failed;
>
> I think we could have three choice to achieve such purpose.
> 1) Do instrument things, in the from-endpoint.
> it's bad, because it need to change the code of camel's
> consumer
>
> 2) Extend a policy processor to wrapper the whole route, and do
> measurement
> It seems the solution is too heavy. But the solution does
> works, and now I am using this solution in my work;
>
> 3) Support a route level interceptor (just like the processor's
> interceptor, but it will wrapper the whole route).
> It seems the solution is more lightweight than the policy-processor.
> How about to add such the support in camel?
>
> Thanks any suggestion
>
>
>
>
>
>
--
Claus Ibsen
Apache Camel Committer
Author of Camel in Action: http://www.manning.com/ibsen/
Open Source Integration: http://fusesource.com
Blog: http://davsclaus.blogspot.com/
Twitter: http://twitter.com/davsclaus
how to implement the instrumentation of from-endpoint?(Should camel to support the route level interceptor)
Posted by ext2 <xu...@tongtech.com>.
Hi:
Camel support interceptors for processor, but recently I encounter a
requirement, it ask for a custom instrumentation strategy of from endpoint;
for example , we need the statistics of how much times the message is
successfully processed in a given time, and how much message is failed;
I think we could have three choice to achieve such purpose.
1) Do instrument things, in the from-endpoint.
it's bad, because it need to change the code of camel's
consumer
2) Extend a policy processor to wrapper the whole route, and do
measurement
It seems the solution is too heavy. But the solution does
works, and now I am using this solution in my work;
3) Support a route level interceptor (just like the processor's
interceptor, but it will wrapper the whole route).
It seems the solution is more lightweight than the policy-processor.
How about to add such the support in camel?
Thanks any suggestion
Re: camel : xpath & text()
Posted by titexe <ti...@yahoo.Fr>.
because I checked the file camel-spring.xsd, and I found the code very well
<xs:complexType name="xPathExpression">
<xs:simpleContent>
<xs:extension base="tns:namespaceAwareExpression">
<xs:attribute name="resultType" type="xs:string"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
Camel Version : 2.1 and activemq 5.3
titexe wrote:
>
> thank you for your answers,
>
> I am in testing phase, the solutions you have proposed
>
> Claus excuse me, I have to put your code (in which file camel.xml or
> activemq.xml) and in each part?
>
> thank you
>
>
>
> Claus Ibsen-2 wrote:
>>
>> On Thu, Dec 17, 2009 at 3:25 AM, Stephen Gargan <st...@gmail.com>
>> wrote:
>>> I'm guessing that you expected to receive the 'ALLAH' string at your
>>> endpoint and were receiving a DeferredCDATASectionImpl object instead is
>>> this correct? The unit test below illustrates what is happening (it uses
>>> the
>>> java DSL with the first of the 3 routes being pretty much the same as
>>> what
>>> your spring xml route is defining).
>>>
>>> The test 'testFailsDueToTypeConversion' shows that what you actually
>>> receive
>>> from the xpath split is a instance of DeferredCDATASectionImpl. I'm
>>> guessing
>>> you expected this to be a String and were trying to use value() to make
>>> it
>>> so. There are a couple of ways to do this as the rest of the test shows.
>>>
>>> First and easiest is to use a result type in your xpath expression, e.g.
>>> xpath("/request/header/source/text()", String.class), this will
>>> correctly
>>> extract the data from the DeferredCDATASectionImpl object.
>>> Unfortunately,
>>> you cannot currently specify a result type in an XML route, though It
>>> would
>>> be an easy thing to add so maybe you should open a Jira ticket.
>>>
>>
>> Yes you can specify that in Spring XML. There is an attribute for that.
>>
>> <xs:complexType name="xPathExpression">
>> <xs:simpleContent>
>> <xs:extension base="tns:namespaceAwareExpression">
>> <xs:attribute name="resultType" type="xs:string"/>
>> </xs:extension>
>> </xs:simpleContent>
>> </xs:complexType>
>>
>>> Secondly you could use an intermediate bean to grab the data from the
>>> DeferredCDATASectionImpl and pass it on e.g. 'testWithBeanConversion.'
>>>
>>> Third and probably the best would be to add an explicit type converter
>>> for
>>> it. The test 'testWithRegisteredConverter' shows how using the
>>> CDataTypeConverter bean below. There is excellent documentation on Type
>>> converters at the Camel website
>>> http://camel.apache.org/type-converter.html
>>>
>>> Hope this helps,
>>>
>>> ste
>>>
>>> public class CDataXPathTest extends ContextTestSupport
>>> {
>>> @Override
>>> protected RouteBuilder createRouteBuilder() throws Exception
>>> {
>>> return new RouteBuilder()
>>> {
>>> @Override
>>> public void configure() throws Exception
>>> {
>>>
>>>
>>> from("direct:xpath-no-conversion").split().xpath("/request/header/source/text()").to("mock:test");
>>>
>>> from("direct:xpath-with-result-type").split().xpath("/request/header/source/text()",
>>> String.class).to("mock:test");
>>>
>>> from("direct:xpath-with-bean-converter").split().xpath("/request/header/source/text()").bean(new
>>> MySourceProcessor()).to("mock:test");
>>> }
>>> };
>>> }
>>>
>>> public void testFailsDueToTypeConversion() throws Exception
>>> {
>>> MockEndpoint mock = getMockEndpoint("mock:test");
>>> mock.expectedMessageCount(1);
>>>
>>> String xml =
>>> "<request><header><source><![CDATA[ALLAH]]></source></header></request>";
>>> sendBody("direct:xpath-no-conversion", xml);
>>>
>>> mock.await();
>>> mock.assertIsSatisfied();
>>>
>>> Object receieved =
>>> ExchangeHelper.getMandatoryInBody(mock.getReceivedExchanges().get(0));
>>> assertIsInstanceOf(DeferredCDATASectionImpl.class, receieved);
>>> }
>>>
>>>
>>> public void testWithResultTypeConversion() throws Exception
>>> {
>>> MockEndpoint mock = getMockEndpoint("mock:test");
>>> mock.expectedBodiesReceived("ALLAH");
>>>
>>> String xml =
>>> "<request><header><source><![CDATA[ALLAH]]></source></header></request>";
>>> sendBody("direct:xpath-with-result-type", xml);
>>>
>>> mock.await();
>>> mock.assertIsSatisfied();
>>> }
>>>
>>> public void testWithBeanConversion() throws Exception
>>> {
>>> MockEndpoint mock = getMockEndpoint("mock:test");
>>> mock.expectedBodiesReceived("ALLAH");
>>>
>>> String xml =
>>> "<request><header><source><![CDATA[ALLAH]]></source></header></request>";
>>> sendBody("direct:xpath-with-bean-converter", xml);
>>>
>>> mock.await();
>>> mock.assertIsSatisfied();
>>> }
>>>
>>> public void testWithRegisteredConverter() throws Exception
>>> {
>>> context.getTypeConverterRegistry().addTypeConverter(String.class,
>>> DeferredCDATASectionImpl.class, new CDataTypeConverter());
>>> MockEndpoint mock = getMockEndpoint("mock:test");
>>> mock.expectedBodiesReceived("ALLAH");
>>>
>>> String xml =
>>> "<request><header><source><![CDATA[ALLAH]]></source></header></request>";
>>> sendBody("direct:xpath-no-conversion", xml);
>>>
>>> mock.await();
>>> mock.assertIsSatisfied();
>>> }
>>>
>>> public static class MySourceProcessor
>>> {
>>> public String handleCdata(DeferredCDATASectionImpl payload)
>>> {
>>> return payload.getData();
>>> }
>>> }
>>>
>>> public static class CDataTypeConverter implements TypeConverter
>>> {
>>> public <T> T convertTo(Class<T> type, Object value) {
>>> DeferredCDATASectionImpl cdata =
>>> (DeferredCDATASectionImpl)value;
>>> return (T) cdata.getData();
>>> }
>>>
>>> public <T> T convertTo(Class<T> type, Exchange exchange, Object
>>> value) {
>>> return convertTo(type, value);
>>> }
>>>
>>> public <T> T mandatoryConvertTo(Class<T> type, Object value) {
>>> return convertTo(type, value);
>>> }
>>>
>>> public <T> T mandatoryConvertTo(Class<T> type, Exchange exchange,
>>> Object value) {
>>> return convertTo(type, value);
>>> }
>>> }
>>> }
>>>
>>> On Wed, Dec 16, 2009 at 9:27 AM, titexe <ti...@yahoo.fr> wrote:
>>>
>>>>
>>>> hello,
>>>>
>>>> my xpath query does not work, when I put the text value () to finish:
>>>>
>>>> /request/header/source/text()
>>>>
>>>> body of my message :
>>>>
>>>> <?xml version="1.0" encoding="UTF-8"?>
>>>> <request>
>>>> <header>
>>>> <source><![CDATA[ALLAH]]></source>
>>>> </header>
>>>> </request>
>>>>
>>>>
>>>> my route :
>>>>
>>>> <route>
>>>> <from uri="activemq:queue:IN1"/>
>>>> <split>
>>>> <xpath>/request/header/source/text()</ xpath>
>>>>
>>>> <t uri="activemq:queue:XML"/>
>>>> </ Split>
>>>> <t uri="activemq:queue:RESULT"/>
>>>> </ route>
>>>>
>>>> any idea?
>>>>
>>>> thanks in advance,
>>>>
>>>> titexe
>>>> --
>>>> View this message in context:
>>>> http://old.nabble.com/camel-%3A-xpath---text%28%29-tp26815065p26815065.html
>>>> Sent from the Camel - Users mailing list archive at Nabble.com.
>>>>
>>>>
>>>
>>
>>
>>
>> --
>> Claus Ibsen
>> Apache Camel Committer
>>
>> Author of Camel in Action: http://www.manning.com/ibsen/
>> Open Source Integration: http://fusesource.com
>> Blog: http://davsclaus.blogspot.com/
>> Twitter: http://twitter.com/davsclaus
>>
>>
>
>
--
View this message in context: http://old.nabble.com/camel-%3A-xpath---text%28%29-tp26815065p26825022.html
Sent from the Camel - Users mailing list archive at Nabble.com.
Re: camel : xpath & text()
Posted by titexe <ti...@yahoo.Fr>.
thank you for your answers,
I am in testing phase, the solutions you have proposed
Claus excuse me, I have to put your code (in which file camel.xml or
activemq.xml) and in each part?
thank you
Claus Ibsen-2 wrote:
>
> On Thu, Dec 17, 2009 at 3:25 AM, Stephen Gargan <st...@gmail.com>
> wrote:
>> I'm guessing that you expected to receive the 'ALLAH' string at your
>> endpoint and were receiving a DeferredCDATASectionImpl object instead is
>> this correct? The unit test below illustrates what is happening (it uses
>> the
>> java DSL with the first of the 3 routes being pretty much the same as
>> what
>> your spring xml route is defining).
>>
>> The test 'testFailsDueToTypeConversion' shows that what you actually
>> receive
>> from the xpath split is a instance of DeferredCDATASectionImpl. I'm
>> guessing
>> you expected this to be a String and were trying to use value() to make
>> it
>> so. There are a couple of ways to do this as the rest of the test shows.
>>
>> First and easiest is to use a result type in your xpath expression, e.g.
>> xpath("/request/header/source/text()", String.class), this will correctly
>> extract the data from the DeferredCDATASectionImpl object. Unfortunately,
>> you cannot currently specify a result type in an XML route, though It
>> would
>> be an easy thing to add so maybe you should open a Jira ticket.
>>
>
> Yes you can specify that in Spring XML. There is an attribute for that.
>
> <xs:complexType name="xPathExpression">
> <xs:simpleContent>
> <xs:extension base="tns:namespaceAwareExpression">
> <xs:attribute name="resultType" type="xs:string"/>
> </xs:extension>
> </xs:simpleContent>
> </xs:complexType>
>
>> Secondly you could use an intermediate bean to grab the data from the
>> DeferredCDATASectionImpl and pass it on e.g. 'testWithBeanConversion.'
>>
>> Third and probably the best would be to add an explicit type converter
>> for
>> it. The test 'testWithRegisteredConverter' shows how using the
>> CDataTypeConverter bean below. There is excellent documentation on Type
>> converters at the Camel website
>> http://camel.apache.org/type-converter.html
>>
>> Hope this helps,
>>
>> ste
>>
>> public class CDataXPathTest extends ContextTestSupport
>> {
>> @Override
>> protected RouteBuilder createRouteBuilder() throws Exception
>> {
>> return new RouteBuilder()
>> {
>> @Override
>> public void configure() throws Exception
>> {
>>
>>
>> from("direct:xpath-no-conversion").split().xpath("/request/header/source/text()").to("mock:test");
>>
>> from("direct:xpath-with-result-type").split().xpath("/request/header/source/text()",
>> String.class).to("mock:test");
>>
>> from("direct:xpath-with-bean-converter").split().xpath("/request/header/source/text()").bean(new
>> MySourceProcessor()).to("mock:test");
>> }
>> };
>> }
>>
>> public void testFailsDueToTypeConversion() throws Exception
>> {
>> MockEndpoint mock = getMockEndpoint("mock:test");
>> mock.expectedMessageCount(1);
>>
>> String xml =
>> "<request><header><source><![CDATA[ALLAH]]></source></header></request>";
>> sendBody("direct:xpath-no-conversion", xml);
>>
>> mock.await();
>> mock.assertIsSatisfied();
>>
>> Object receieved =
>> ExchangeHelper.getMandatoryInBody(mock.getReceivedExchanges().get(0));
>> assertIsInstanceOf(DeferredCDATASectionImpl.class, receieved);
>> }
>>
>>
>> public void testWithResultTypeConversion() throws Exception
>> {
>> MockEndpoint mock = getMockEndpoint("mock:test");
>> mock.expectedBodiesReceived("ALLAH");
>>
>> String xml =
>> "<request><header><source><![CDATA[ALLAH]]></source></header></request>";
>> sendBody("direct:xpath-with-result-type", xml);
>>
>> mock.await();
>> mock.assertIsSatisfied();
>> }
>>
>> public void testWithBeanConversion() throws Exception
>> {
>> MockEndpoint mock = getMockEndpoint("mock:test");
>> mock.expectedBodiesReceived("ALLAH");
>>
>> String xml =
>> "<request><header><source><![CDATA[ALLAH]]></source></header></request>";
>> sendBody("direct:xpath-with-bean-converter", xml);
>>
>> mock.await();
>> mock.assertIsSatisfied();
>> }
>>
>> public void testWithRegisteredConverter() throws Exception
>> {
>> context.getTypeConverterRegistry().addTypeConverter(String.class,
>> DeferredCDATASectionImpl.class, new CDataTypeConverter());
>> MockEndpoint mock = getMockEndpoint("mock:test");
>> mock.expectedBodiesReceived("ALLAH");
>>
>> String xml =
>> "<request><header><source><![CDATA[ALLAH]]></source></header></request>";
>> sendBody("direct:xpath-no-conversion", xml);
>>
>> mock.await();
>> mock.assertIsSatisfied();
>> }
>>
>> public static class MySourceProcessor
>> {
>> public String handleCdata(DeferredCDATASectionImpl payload)
>> {
>> return payload.getData();
>> }
>> }
>>
>> public static class CDataTypeConverter implements TypeConverter
>> {
>> public <T> T convertTo(Class<T> type, Object value) {
>> DeferredCDATASectionImpl cdata =
>> (DeferredCDATASectionImpl)value;
>> return (T) cdata.getData();
>> }
>>
>> public <T> T convertTo(Class<T> type, Exchange exchange, Object
>> value) {
>> return convertTo(type, value);
>> }
>>
>> public <T> T mandatoryConvertTo(Class<T> type, Object value) {
>> return convertTo(type, value);
>> }
>>
>> public <T> T mandatoryConvertTo(Class<T> type, Exchange exchange,
>> Object value) {
>> return convertTo(type, value);
>> }
>> }
>> }
>>
>> On Wed, Dec 16, 2009 at 9:27 AM, titexe <ti...@yahoo.fr> wrote:
>>
>>>
>>> hello,
>>>
>>> my xpath query does not work, when I put the text value () to finish:
>>>
>>> /request/header/source/text()
>>>
>>> body of my message :
>>>
>>> <?xml version="1.0" encoding="UTF-8"?>
>>> <request>
>>> <header>
>>> <source><![CDATA[ALLAH]]></source>
>>> </header>
>>> </request>
>>>
>>>
>>> my route :
>>>
>>> <route>
>>> <from uri="activemq:queue:IN1"/>
>>> <split>
>>> <xpath>/request/header/source/text()</ xpath>
>>>
>>> <t uri="activemq:queue:XML"/>
>>> </ Split>
>>> <t uri="activemq:queue:RESULT"/>
>>> </ route>
>>>
>>> any idea?
>>>
>>> thanks in advance,
>>>
>>> titexe
>>> --
>>> View this message in context:
>>> http://old.nabble.com/camel-%3A-xpath---text%28%29-tp26815065p26815065.html
>>> Sent from the Camel - Users mailing list archive at Nabble.com.
>>>
>>>
>>
>
>
>
> --
> Claus Ibsen
> Apache Camel Committer
>
> Author of Camel in Action: http://www.manning.com/ibsen/
> Open Source Integration: http://fusesource.com
> Blog: http://davsclaus.blogspot.com/
> Twitter: http://twitter.com/davsclaus
>
>
--
View this message in context: http://old.nabble.com/camel-%3A-xpath---text%28%29-tp26815065p26824799.html
Sent from the Camel - Users mailing list archive at Nabble.com.
Re: camel : xpath & text()
Posted by Claus Ibsen <cl...@gmail.com>.
On Thu, Dec 17, 2009 at 3:25 AM, Stephen Gargan <st...@gmail.com> wrote:
> I'm guessing that you expected to receive the 'ALLAH' string at your
> endpoint and were receiving a DeferredCDATASectionImpl object instead is
> this correct? The unit test below illustrates what is happening (it uses the
> java DSL with the first of the 3 routes being pretty much the same as what
> your spring xml route is defining).
>
> The test 'testFailsDueToTypeConversion' shows that what you actually receive
> from the xpath split is a instance of DeferredCDATASectionImpl. I'm guessing
> you expected this to be a String and were trying to use value() to make it
> so. There are a couple of ways to do this as the rest of the test shows.
>
> First and easiest is to use a result type in your xpath expression, e.g.
> xpath("/request/header/source/text()", String.class), this will correctly
> extract the data from the DeferredCDATASectionImpl object. Unfortunately,
> you cannot currently specify a result type in an XML route, though It would
> be an easy thing to add so maybe you should open a Jira ticket.
>
Yes you can specify that in Spring XML. There is an attribute for that.
<xs:complexType name="xPathExpression">
<xs:simpleContent>
<xs:extension base="tns:namespaceAwareExpression">
<xs:attribute name="resultType" type="xs:string"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
> Secondly you could use an intermediate bean to grab the data from the
> DeferredCDATASectionImpl and pass it on e.g. 'testWithBeanConversion.'
>
> Third and probably the best would be to add an explicit type converter for
> it. The test 'testWithRegisteredConverter' shows how using the
> CDataTypeConverter bean below. There is excellent documentation on Type
> converters at the Camel website http://camel.apache.org/type-converter.html
>
> Hope this helps,
>
> ste
>
> public class CDataXPathTest extends ContextTestSupport
> {
> @Override
> protected RouteBuilder createRouteBuilder() throws Exception
> {
> return new RouteBuilder()
> {
> @Override
> public void configure() throws Exception
> {
>
>
> from("direct:xpath-no-conversion").split().xpath("/request/header/source/text()").to("mock:test");
>
> from("direct:xpath-with-result-type").split().xpath("/request/header/source/text()",
> String.class).to("mock:test");
>
> from("direct:xpath-with-bean-converter").split().xpath("/request/header/source/text()").bean(new
> MySourceProcessor()).to("mock:test");
> }
> };
> }
>
> public void testFailsDueToTypeConversion() throws Exception
> {
> MockEndpoint mock = getMockEndpoint("mock:test");
> mock.expectedMessageCount(1);
>
> String xml =
> "<request><header><source><![CDATA[ALLAH]]></source></header></request>";
> sendBody("direct:xpath-no-conversion", xml);
>
> mock.await();
> mock.assertIsSatisfied();
>
> Object receieved =
> ExchangeHelper.getMandatoryInBody(mock.getReceivedExchanges().get(0));
> assertIsInstanceOf(DeferredCDATASectionImpl.class, receieved);
> }
>
>
> public void testWithResultTypeConversion() throws Exception
> {
> MockEndpoint mock = getMockEndpoint("mock:test");
> mock.expectedBodiesReceived("ALLAH");
>
> String xml =
> "<request><header><source><![CDATA[ALLAH]]></source></header></request>";
> sendBody("direct:xpath-with-result-type", xml);
>
> mock.await();
> mock.assertIsSatisfied();
> }
>
> public void testWithBeanConversion() throws Exception
> {
> MockEndpoint mock = getMockEndpoint("mock:test");
> mock.expectedBodiesReceived("ALLAH");
>
> String xml =
> "<request><header><source><![CDATA[ALLAH]]></source></header></request>";
> sendBody("direct:xpath-with-bean-converter", xml);
>
> mock.await();
> mock.assertIsSatisfied();
> }
>
> public void testWithRegisteredConverter() throws Exception
> {
> context.getTypeConverterRegistry().addTypeConverter(String.class,
> DeferredCDATASectionImpl.class, new CDataTypeConverter());
> MockEndpoint mock = getMockEndpoint("mock:test");
> mock.expectedBodiesReceived("ALLAH");
>
> String xml =
> "<request><header><source><![CDATA[ALLAH]]></source></header></request>";
> sendBody("direct:xpath-no-conversion", xml);
>
> mock.await();
> mock.assertIsSatisfied();
> }
>
> public static class MySourceProcessor
> {
> public String handleCdata(DeferredCDATASectionImpl payload)
> {
> return payload.getData();
> }
> }
>
> public static class CDataTypeConverter implements TypeConverter
> {
> public <T> T convertTo(Class<T> type, Object value) {
> DeferredCDATASectionImpl cdata =
> (DeferredCDATASectionImpl)value;
> return (T) cdata.getData();
> }
>
> public <T> T convertTo(Class<T> type, Exchange exchange, Object
> value) {
> return convertTo(type, value);
> }
>
> public <T> T mandatoryConvertTo(Class<T> type, Object value) {
> return convertTo(type, value);
> }
>
> public <T> T mandatoryConvertTo(Class<T> type, Exchange exchange,
> Object value) {
> return convertTo(type, value);
> }
> }
> }
>
> On Wed, Dec 16, 2009 at 9:27 AM, titexe <ti...@yahoo.fr> wrote:
>
>>
>> hello,
>>
>> my xpath query does not work, when I put the text value () to finish:
>>
>> /request/header/source/text()
>>
>> body of my message :
>>
>> <?xml version="1.0" encoding="UTF-8"?>
>> <request>
>> <header>
>> <source><![CDATA[ALLAH]]></source>
>> </header>
>> </request>
>>
>>
>> my route :
>>
>> <route>
>> <from uri="activemq:queue:IN1"/>
>> <split>
>> <xpath>/request/header/source/text()</ xpath>
>>
>> <t uri="activemq:queue:XML"/>
>> </ Split>
>> <t uri="activemq:queue:RESULT"/>
>> </ route>
>>
>> any idea?
>>
>> thanks in advance,
>>
>> titexe
>> --
>> View this message in context:
>> http://old.nabble.com/camel-%3A-xpath---text%28%29-tp26815065p26815065.html
>> Sent from the Camel - Users mailing list archive at Nabble.com.
>>
>>
>
--
Claus Ibsen
Apache Camel Committer
Author of Camel in Action: http://www.manning.com/ibsen/
Open Source Integration: http://fusesource.com
Blog: http://davsclaus.blogspot.com/
Twitter: http://twitter.com/davsclaus
Re: camel : xpath & text()
Posted by Stephen Gargan <st...@gmail.com>.
I'm guessing that you expected to receive the 'ALLAH' string at your
endpoint and were receiving a DeferredCDATASectionImpl object instead is
this correct? The unit test below illustrates what is happening (it uses the
java DSL with the first of the 3 routes being pretty much the same as what
your spring xml route is defining).
The test 'testFailsDueToTypeConversion' shows that what you actually receive
from the xpath split is a instance of DeferredCDATASectionImpl. I'm guessing
you expected this to be a String and were trying to use value() to make it
so. There are a couple of ways to do this as the rest of the test shows.
First and easiest is to use a result type in your xpath expression, e.g.
xpath("/request/header/source/text()", String.class), this will correctly
extract the data from the DeferredCDATASectionImpl object. Unfortunately,
you cannot currently specify a result type in an XML route, though It would
be an easy thing to add so maybe you should open a Jira ticket.
Secondly you could use an intermediate bean to grab the data from the
DeferredCDATASectionImpl and pass it on e.g. 'testWithBeanConversion.'
Third and probably the best would be to add an explicit type converter for
it. The test 'testWithRegisteredConverter' shows how using the
CDataTypeConverter bean below. There is excellent documentation on Type
converters at the Camel website http://camel.apache.org/type-converter.html
Hope this helps,
ste
public class CDataXPathTest extends ContextTestSupport
{
@Override
protected RouteBuilder createRouteBuilder() throws Exception
{
return new RouteBuilder()
{
@Override
public void configure() throws Exception
{
from("direct:xpath-no-conversion").split().xpath("/request/header/source/text()").to("mock:test");
from("direct:xpath-with-result-type").split().xpath("/request/header/source/text()",
String.class).to("mock:test");
from("direct:xpath-with-bean-converter").split().xpath("/request/header/source/text()").bean(new
MySourceProcessor()).to("mock:test");
}
};
}
public void testFailsDueToTypeConversion() throws Exception
{
MockEndpoint mock = getMockEndpoint("mock:test");
mock.expectedMessageCount(1);
String xml =
"<request><header><source><![CDATA[ALLAH]]></source></header></request>";
sendBody("direct:xpath-no-conversion", xml);
mock.await();
mock.assertIsSatisfied();
Object receieved =
ExchangeHelper.getMandatoryInBody(mock.getReceivedExchanges().get(0));
assertIsInstanceOf(DeferredCDATASectionImpl.class, receieved);
}
public void testWithResultTypeConversion() throws Exception
{
MockEndpoint mock = getMockEndpoint("mock:test");
mock.expectedBodiesReceived("ALLAH");
String xml =
"<request><header><source><![CDATA[ALLAH]]></source></header></request>";
sendBody("direct:xpath-with-result-type", xml);
mock.await();
mock.assertIsSatisfied();
}
public void testWithBeanConversion() throws Exception
{
MockEndpoint mock = getMockEndpoint("mock:test");
mock.expectedBodiesReceived("ALLAH");
String xml =
"<request><header><source><![CDATA[ALLAH]]></source></header></request>";
sendBody("direct:xpath-with-bean-converter", xml);
mock.await();
mock.assertIsSatisfied();
}
public void testWithRegisteredConverter() throws Exception
{
context.getTypeConverterRegistry().addTypeConverter(String.class,
DeferredCDATASectionImpl.class, new CDataTypeConverter());
MockEndpoint mock = getMockEndpoint("mock:test");
mock.expectedBodiesReceived("ALLAH");
String xml =
"<request><header><source><![CDATA[ALLAH]]></source></header></request>";
sendBody("direct:xpath-no-conversion", xml);
mock.await();
mock.assertIsSatisfied();
}
public static class MySourceProcessor
{
public String handleCdata(DeferredCDATASectionImpl payload)
{
return payload.getData();
}
}
public static class CDataTypeConverter implements TypeConverter
{
public <T> T convertTo(Class<T> type, Object value) {
DeferredCDATASectionImpl cdata =
(DeferredCDATASectionImpl)value;
return (T) cdata.getData();
}
public <T> T convertTo(Class<T> type, Exchange exchange, Object
value) {
return convertTo(type, value);
}
public <T> T mandatoryConvertTo(Class<T> type, Object value) {
return convertTo(type, value);
}
public <T> T mandatoryConvertTo(Class<T> type, Exchange exchange,
Object value) {
return convertTo(type, value);
}
}
}
On Wed, Dec 16, 2009 at 9:27 AM, titexe <ti...@yahoo.fr> wrote:
>
> hello,
>
> my xpath query does not work, when I put the text value () to finish:
>
> /request/header/source/text()
>
> body of my message :
>
> <?xml version="1.0" encoding="UTF-8"?>
> <request>
> <header>
> <source><![CDATA[ALLAH]]></source>
> </header>
> </request>
>
>
> my route :
>
> <route>
> <from uri="activemq:queue:IN1"/>
> <split>
> <xpath>/request/header/source/text()</ xpath>
>
> <t uri="activemq:queue:XML"/>
> </ Split>
> <t uri="activemq:queue:RESULT"/>
> </ route>
>
> any idea?
>
> thanks in advance,
>
> titexe
> --
> View this message in context:
> http://old.nabble.com/camel-%3A-xpath---text%28%29-tp26815065p26815065.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>
>