Re: Help to understand xpath expression in camel routebuilder
Have you created a mapping file for your custom class? You need to provide JiBX with a mapping file so it knows how to do the marshalling. In the article, they've defined one for their classes in InsuranceSMDZone/jibx/InsuranceMapping.xml On Wed, Dec 16, 2009 at 1:43 PM, Kenneth H phecda...@gmail.com wrote: janstey wrote: In JBI applications, each SU has its own classloader so I *think* if you make sure that your custom classes are available on the Camel SU's classpath and the JMS SU's classpath all will be well. You were right. After moving the relevant classes to the classpath directory, the exception is gone. However, it would be to easy if things just worked, so Servicmix throws a new exception. This time it's JiBX, annoying: javax.jms.JMSException: Error sending JBI exchange at org.apache.servicemix.jms.endpoints.AbstractConsumerEndpoint.onMessage(AbstractConsumerEndpoint.java:575) at org.apache.servicemix.jms.endpoints.JmsConsumerEndpoint$1.onMessage(JmsConsumerEndpoint.java:505) at org.springframework.jms.listener.AbstractMessageListenerContainer.doInvokeListener(AbstractMessageListenerContainer.java:518) at org.springframework.jms.listener.AbstractMessageListenerContainer.invokeListener(AbstractMessageListenerContainer.java:479) at org.springframework.jms.listener.AbstractMessageListenerContainer.doExecuteListener(AbstractMessageListenerContainer.java:451) at org.springframework.jms.listener.AbstractPollingMessageListenerContainer.doReceiveAndExecute(AbstractPollingMessageListenerContainer.java:323) at org.springframework.jms.listener.AbstractPollingMessageListenerContainer.receiveAndExecute(AbstractPollingMessageListenerContainer.java:261) at org.springframework.jms.listener.DefaultMessageListenerContainer$AsyncMessageListenerInvoker.invokeListener(DefaultMessageListenerContainer.java:982) at org.springframework.jms.listener.DefaultMessageListenerContainer$AsyncMessageListenerInvoker.executeOngoingLoop(DefaultMessageListenerContainer.java:974) at org.springframework.jms.listener.DefaultMessageListenerContainer$AsyncMessageListenerInvoker.run(DefaultMessageListenerContainer.java:876) at java.lang.Thread.run(Thread.java:619) Caused by: org.jibx.runtime.JiBXException: Error marshalling XML to Object at terror.util.JiBXUtil.marshalDocument(JiBXUtil.java:51) at terror.util.TerrorJMSMarshaler.populateMessage(TerrorJMSMarshaler.java:19) at org.apache.servicemix.jms.endpoints.DefaultConsumerMarshaler.createExchange(DefaultConsumerMarshaler.java:99) at org.apache.servicemix.jms.endpoints.AbstractConsumerEndpoint.onMessage(AbstractConsumerEndpoint.java:544) ... 10 more The function that throws the exceptions is this: public static Source marshalDocument(Object src, String encoding) throws JiBXException { Source result = null; try { ByteArrayOutputStream bOut = new ByteArrayOutputStream(); IMarshallingContext ctx = BindingDirectory.getFactory(src.getClass()) .createMarshallingContext(); ctx.marshalDocument(src, UTF-8, null, bOut); result = new StreamSource(new ByteArrayInputStream(bOut.toByteArray())); } catch (Exception e) { throw new JiBXException(Error marshalling XML to Object,e); } return result; } I don't know where the problems is. The exceptiopns doesn't give much information. Kind regards, Kenneth -- View this message in context: http://old.nabble.com/Help-to-understand-xpath-expression-in-camel-routebuilder-tp26779963p26814820.html Sent from the Camel - Users mailing list archive at Nabble.com. -- Cheers, Jon Camel in Action: http://manning.com/ibsen Blog: http://janstey.blogspot.com
Re: Help to understand xpath expression in camel routebuilder
This is the consumer which the messages is sent to: jms:consumer service=fork:terrorReceiver endpoint=jmsEndpoint targetService=fork:terrorDSLRouter destinationName=terror.in connectionFactory=#connectionFactory marshaler=#TerrorJMSMarshaler/ The TerrorJMSMarshaler is: public class TerrorJMSMarshaler extends DefaultConsumerMarshaler { protected void populateMessage(Message message, NormalizedMessage normalizedMessage) throws Exception { if (message instanceof ObjectMessage) { ObjectMessage objectMessage = (ObjectMessage) message; Object payload = objectMessage.getObject(); Source source = JiBXUtil.marshalDocument(payload, UTF-8); if(payload instanceof TerrorResponse) { TerrorResponse terrorResponse = (TerrorResponse) payload; normalizedMessage.setProperty(org.apache.servicemix.eip.splitter.corrid, terrorResponse.getRequestID()); normalizedMessage.setProperty(org.apache.servicemix.eip.splitter.index, new Integer(1)); normalizedMessage.setProperty(org.apache.servicemix.eip.splitter.count, new Integer(2)); } normalizedMessage.setContent(source); } else { throw new UnsupportedOperationException(JMS message is not a ObjectMessage); } } } The message is NOT of type TerrorResponse, so it should not jump into the statement. But from here the JiBXUtil (where the exception is thrown) is used. Still I can't see where the error is. -- View this message in context: http://old.nabble.com/Help-to-understand-xpath-expression-in-camel-routebuilder-tp26779963p26815131.html Sent from the Camel - Users mailing list archive at Nabble.com.
Re: Help to understand xpath expression in camel routebuilder
janstey wrote: Have you created a mapping file for your custom class? You need to provide JiBX with a mapping file so it knows how to do the marshalling. In the article, they've defined one for their classes in InsuranceSMDZone/jibx/InsuranceMapping.xml You got me there, I haven't included this file. Do you know on which classpath to put it? I'll put in the same folder as the other two JiBX classes as a first try. -- View this message in context: http://old.nabble.com/Help-to-understand-xpath-expression-in-camel-routebuilder-tp26779963p26815230.html Sent from the Camel - Users mailing list archive at Nabble.com.
Re: Help to understand xpath expression in camel routebuilder
Have you created a mapping file for your custom class? You need to provide JiBX with a mapping file so it knows how to do the marshalling. In the article, they've defined one for their classes in InsuranceSMDZone/jibx/InsuranceMapping.xml You got me there, I haven't included this file. Do you know on which classpath to put it? I'll put in the same folder as the other two JiBX classes as a first try. That's strange. I can't find anywhere where the InsuranceMapping.xml is referenced, so I don't know where to put it?! My project is a Maven project and the orginal project is build with Ant, so I cannot just create the same folder as him and put it there. -- View this message in context: http://old.nabble.com/Help-to-understand-xpath-expression-in-camel-routebuilder-tp26779963p26815501.html Sent from the Camel - Users mailing list archive at Nabble.com.
Re: Help to understand xpath expression in camel routebuilder
- sorry for all the posts Jon... If you look at the original Ant build file, you see: target name=deploy-insurance description=Deploy the insurance example echo message=Creating insurance service units / antcall target=gn:create-serviceunit /antcall antcall target=gn:create-serviceunit /antcall The question is now: how do I do the same thing in Maven? -- View this message in context: http://old.nabble.com/Help-to-understand-xpath-expression-in-camel-routebuilder-tp26779963p26815612.html Sent from the Camel - Users mailing list archive at Nabble.com.
Re: Help to understand xpath expression in camel routebuilder
- sorry for all the posts Jon... If you look at the original Ant build file, you see (. infront of param is to make sure the whole post is shown): target name=deploy-insurance description=Deploy the insurance example echo message=Creating insurance service units / antcall target=gn:create-serviceunit .param name=servicemix-conf value=servicemix/insurance-jms-su / .param name=service-dest-file value=insurance-jms-su.zip / .param name=jibx-mapping value=jibx/InsuranceMapping.xml / .param name=include-classes value=esb/dzone/servicemix/model/* / .param name=include-resource-dir value=servicemix/insurance-jms-su/resources / /antcall antcall target=gn:create-serviceunit .param name=servicemix-conf value=servicemix/insurance-file-su / .param name=service-dest-file value=insurance-file-su.zip / .param name=include-classes value=esb/dzone/servicemix/model/* / .param name=jibx-mapping value=jibx/InsuranceMapping.xml / .param name=include-resource-dir value=servicemix/insurance-file-su/resources / /antcall The question is now: how do I do the same thing in my Maven project? -- View this message in context: http://old.nabble.com/Help-to-understand-xpath-expression-in-camel-routebuilder-tp26779963p26815668.html Sent from the Camel - Users mailing list archive at Nabble.com.
Re: Help to understand xpath expression in camel routebuilder
janstey wrote: Hmm... JBI deployment question eh... not really sure how to help you off the top of my head to be honest! Maybe try us...@servicemix.apache.org? I'll try there and maybe also some Maven-folks :) -- View this message in context: http://old.nabble.com/Help-to-understand-xpath-expression-in-camel-routebuilder-tp26779963p26816636.html Sent from the Camel - Users mailing list archive at Nabble.com.
Re: Help to understand xpath expression in camel routebuilder
Hi Jon, Your answer definitely helped. I have a couple of more questions though: 1. Where can I read about the .namespace() function syntax? I still don't get why ins is used in both functions. I tried w3schools but didn't find it. 2. Is it possible to debug in the Camel routebuilder somehow? If I want to know how the message looks like before and after the .convertBodyTo(DOMSource.class). And most important: I want to know if an expression evaluates to true, i.e. I want to print-out the result of the when statement. Maybe something like this pseudocode: var travelRequest = xpath(//ins:TravelInsuranceRequest).namespace ins,http://dzone.com/insurance;)) print(travelRequest); .when(travelRequest).to(LUXURY_CAR_OUT); Kind regards, Kenneth H -- View this message in context: http://old.nabble.com/Help-to-understand-xpath-expression-in-camel-routebuilder-tp26779963p26794573.html Sent from the Camel - Users mailing list archive at Nabble.com.
Re: Help to understand xpath expression in camel routebuilder
On Tue, Dec 15, 2009 at 9:43 AM, Kenneth H phecda...@gmail.com wrote: Hi Jon, Your answer definitely helped. I have a couple of more questions though: 1. Where can I read about the .namespace() function syntax? I still don't get why ins is used in both functions. I tried w3schools but didn't find it. Did you find this page? http://www.w3schools.com/XML/xml_namespaces.asp That should help you understand usage of the namespace prefix and URI. 2. Is it possible to debug in the Camel routebuilder somehow? If I want to know how the message looks like before and after the .convertBodyTo(DOMSource.class). And most important: I want to know if an expression evaluates to true, i.e. I want to print-out the result of the when statement. Maybe something like this pseudocode: var travelRequest = xpath(//ins:TravelInsuranceRequest).namespace ins,http://dzone.com/insurance;)) print(travelRequest); .when(travelRequest).to(LUXURY_CAR_OUT); I guess it depends on how you have this deployed... if its a JUnit test, well Eclipse or IntelliJ can easily debug that for you. Other setups may require extra configuration of the app server / ESB to get debugging working. Actually, if you just want to see what the messages look like at various points in your route, try enabling the tracer http://camel.apache.org/tracer.html Kind regards, Kenneth H -- View this message in context: http://old.nabble.com/Help-to-understand-xpath-expression-in-camel-routebuilder-tp26779963p26794573.html Sent from the Camel - Users mailing list archive at Nabble.com. -- Cheers, Jon Camel in Action: http://manning.com/ibsen Blog: http://janstey.blogspot.com
Re: Help to understand xpath expression in camel routebuilder
1. Where can I read about the .namespace() function syntax? I still don't get why ins is used in both functions. I tried w3schools but didn't find it. Did you find this page? http://www.w3schools.com/XML/xml_namespaces.asp That should help you understand usage of the namespace prefix and URI. I know namespaces in general, bit it was the syntax of the .namespace() function in xpath, I was looking for. 2. Is it possible to debug in the Camel routebuilder somehow? If I want to know how the message looks like before and after the .convertBodyTo(DOMSource.class). And most important: I want to know if an expression evaluates to true, i.e. I want to print-out the result of the when statement. Maybe something like this pseudocode: var travelRequest = xpath(//ins:TravelInsuranceRequest).namespace ins,http://dzone.com/insurance;)) print(travelRequest); .when(travelRequest).to(LUXURY_CAR_OUT); I guess it depends on how you have this deployed... if its a JUnit test, well Eclipse or IntelliJ can easily debug that for you. Other setups may require extra configuration of the app server / ESB to get debugging working. Actually, if you just want to see what the messages look like at various points in your route, try enabling the tracer http://camel.apache.org/tracer.html I will look into the tracer - didn't know of that. I have just created a Maven project and deployed it on the Servicemix ESB. Hard to find out how to debug :) One last novice question. In the statement: from(seda:a).filter(header(foo).isEqualTo(bar)).to(seda:b); Where does the foo comes from, I mean, where do I set it? From Eclipse I'm creating a JMS Message, but the only headers availbe is these: http://publib.boulder.ibm.com/infocenter/tivihelp/v2r1/index.jsp?topic=/com.ibm.IBMDI.doc/referenceguide95.htm Do you know how I can use these headers/properties in a Camel choice statement? Basicly, I just want to create the most simple example, where to messages are send from Eclipse and goes to two different queues in a Camel choice statement. The messages should be simple tect or objects. Kend regards, Kenneth H -- View this message in context: http://old.nabble.com/Help-to-understand-xpath-expression-in-camel-routebuilder-tp26779963p26795823.html Sent from the Camel - Users mailing list archive at Nabble.com.
Re: Help to understand xpath expression in camel routebuilder
On Tue, Dec 15, 2009 at 11:26 AM, Kenneth H phecda...@gmail.com wrote: 1. Where can I read about the .namespace() function syntax? I still don't get why ins is used in both functions. I tried w3schools but didn't find it. Did you find this page? http://www.w3schools.com/XML/xml_namespaces.asp That should help you understand usage of the namespace prefix and URI. I know namespaces in general, bit it was the syntax of the .namespace() function in xpath, I was looking for. Ah Cool stuff. The public javadoc may be helpful to you then http://camel.apache.org/maven/camel-core/apidocs/org/apache/camel/builder/xml/XPathBuilder.html#namespace(java.lang.String,%20java.lang.String) 2. Is it possible to debug in the Camel routebuilder somehow? If I want to know how the message looks like before and after the .convertBodyTo(DOMSource.class). And most important: I want to know if an expression evaluates to true, i.e. I want to print-out the result of the when statement. Maybe something like this pseudocode: var travelRequest = xpath(//ins:TravelInsuranceRequest).namespace ins,http://dzone.com/insurance;)) print(travelRequest); .when(travelRequest).to(LUXURY_CAR_OUT); I guess it depends on how you have this deployed... if its a JUnit test, well Eclipse or IntelliJ can easily debug that for you. Other setups may require extra configuration of the app server / ESB to get debugging working. Actually, if you just want to see what the messages look like at various points in your route, try enabling the tracer http://camel.apache.org/tracer.html I will look into the tracer - didn't know of that. I have just created a Maven project and deployed it on the Servicemix ESB. Hard to find out how to debug :) If you are using the latest ServiceMix, you can follow some notes here to turn on debugging https://repository.apache.org/content/groups/public/org/apache/felix/karaf/manual/1.3.0-SNAPSHOT/manual-1.3.0-SNAPSHOT.html#KarafUsers%27Guideinonepage-5.1.Troubleshooting%2CDebuggingandProfiling One last novice question. In the statement: from(seda:a).filter(header(foo).isEqualTo(bar)).to(seda:b); Where does the foo comes from, I mean, where do I set it? From Eclipse I'm creating a JMS Message, but the only headers availbe is these: http://publib.boulder.ibm.com/infocenter/tivihelp/v2r1/index.jsp?topic=/com.ibm.IBMDI.doc/referenceguide95.htm Do you know how I can use these headers/properties in a Camel choice statement? Basicly, I just want to create the most simple example, where to messages are send from Eclipse and goes to two different queues in a Camel choice statement. The messages should be simple tect or objects. You should be able to access any of the JMS headers you mentioned in the same way the foo header is referenced. So how are you sending JMS messages from Eclipse? I'm assuming its a function of Tivoli in the link you provided? You can also use Camel to set a header like so from(seda:a).setHeader(foo, constant(bar))... Kend regards, Kenneth H -- View this message in context: http://old.nabble.com/Help-to-understand-xpath-expression-in-camel-routebuilder-tp26779963p26795823.html Sent from the Camel - Users mailing list archive at Nabble.com. -- Cheers, Jon Camel in Action: http://manning.com/ibsen Blog: http://janstey.blogspot.com
Re: Help to understand xpath expression in camel routebuilder
On Tue, Dec 15, 2009 at 11:26 AM, Kenneth H phecda...@gmail.com wrote: 1. Where can I read about the .namespace() function syntax? I still don't get why ins is used in both functions. I tried w3schools but didn't find it. Did you find this page? http://www.w3schools.com/XML/xml_namespaces.asp That should help you understand usage of the namespace prefix and URI. I know namespaces in general, bit it was the syntax of the .namespace() function in xpath, I was looking for. Ah Cool stuff. The public javadoc may be helpful to you then http://camel.apache.org/maven/camel-core/apidocs/org/apache/camel/builder/xml/XPathBuilder.html#namespace(java.lang.String,%20java.lang.String) Perfect. Actually I was looking here earlier, but I must have missed it. 2. Is it possible to debug in the Camel routebuilder somehow? If I want to know how the message looks like before and after the .convertBodyTo(DOMSource.class). And most important: I want to know if an expression evaluates to true, i.e. I want to print-out the result of the when statement. Maybe something like this pseudocode: var travelRequest = xpath(//ins:TravelInsuranceRequest).namespace ins,http://dzone.com/insurance;)) print(travelRequest); .when(travelRequest).to(LUXURY_CAR_OUT); I guess it depends on how you have this deployed... if its a JUnit test, well Eclipse or IntelliJ can easily debug that for you. Other setups may require extra configuration of the app server / ESB to get debugging working. Actually, if you just want to see what the messages look like at various points in your route, try enabling the tracer http://camel.apache.org/tracer.html I will look into the tracer - didn't know of that. I have just created a Maven project and deployed it on the Servicemix ESB. Hard to find out how to debug :) If you are using the latest ServiceMix, you can follow some notes here to turn on debugging https://repository.apache.org/content/groups/public/org/apache/felix/karaf/manual/1.3.0-SNAPSHOT/manual-1.3.0-SNAPSHOT.html#KarafUsers%27Guideinonepage-5.1.Troubleshooting%2CDebuggingandProfiling This might be very helpful to me! One last novice question. In the statement: from(seda:a).filter(header(foo).isEqualTo(bar)).to(seda:b); Where does the foo comes from, I mean, where do I set it? From Eclipse I'm creating a JMS Message, but the only headers availbe is these: http://publib.boulder.ibm.com/infocenter/tivihelp/v2r1/index.jsp?topic=/com.ibm.IBMDI.doc/referenceguide95.htm Do you know how I can use these headers/properties in a Camel choice statement? Basicly, I just want to create the most simple example, where to messages are send from Eclipse and goes to two different queues in a Camel choice statement. The messages should be simple tect or objects. You should be able to access any of the JMS headers you mentioned in the same way the foo header is referenced. So how are you sending JMS messages from Eclipse? I'm assuming its a function of Tivoli in the link you provided? I (or the writer of the document I'm reading) made af Response class called InsuranceResponse. The response class is sent to the Camel Routebuilder. I would like to swith on either the classname of the object I'm sending or a field, e.g. CompanyName, in the object. I create/send like this: ObjectMessage insuranceMessage = session.createObjectMessage(); InsuranceResponse response = new InsuranceResponse(); response.setRequestID(1); response.setInsuranceCompanyName(Luxury Cars); response.setPrice(100f); response.setResponseID(UUID.randomUUID().toString()); insuranceMessage.setObject(response); producer.send(insuranceMessage); Then I receive like this (responseMessage returns null all the time, but I guess it's beacuse my Camel Routebuilder isn't wotking, so no object is send to the queue): ObjectMessage responseMessage = (ObjectMessage) consumer.receive(); InsuranceResponse insuranceMessageReceived = (InsuranceResponse) responseMessage.getObject(); You can also use Camel to set a header like so from(seda:a).setHeader(foo, constant(bar))... Cool. But what is the corresponding function in Eclipse/JMS to the setHeader?! Kind regards Kenneth H -- View this message in context: http://old.nabble.com/Help-to-understand-xpath-expression-in-camel-routebuilder-tp26779963p26798115.html Sent from the Camel - Users mailing list archive at Nabble.com.
Re: Help to understand xpath expression in camel routebuilder
On Tue, Dec 15, 2009 at 1:33 PM, Kenneth H phecda...@gmail.com wrote: On Tue, Dec 15, 2009 at 11:26 AM, Kenneth H phecda...@gmail.com wrote: 1. Where can I read about the .namespace() function syntax? I still don't get why ins is used in both functions. I tried w3schools but didn't find it. Did you find this page? http://www.w3schools.com/XML/xml_namespaces.asp That should help you understand usage of the namespace prefix and URI. I know namespaces in general, bit it was the syntax of the .namespace() function in xpath, I was looking for. Ah Cool stuff. The public javadoc may be helpful to you then http://camel.apache.org/maven/camel- core/apidocs/org/apache/camel/builder/xml/XPathBuilder.html#namespace(java.lang.String,%20java.lang.String) Perfect. Actually I was looking here earlier, but I must have missed it. 2. Is it possible to debug in the Camel routebuilder somehow? If I want to know how the message looks like before and after the .convertBodyTo(DOMSource.class). And most important: I want to know if an expression evaluates to true, i.e. I want to print-out the result of the when statement. Maybe something like this pseudocode: var travelRequest = xpath(//ins:TravelInsuranceRequest).namespace ins,http://dzone.com/insurance;)) print(travelRequest); .when(travelRequest).to(LUXURY_CAR_OUT); I guess it depends on how you have this deployed... if its a JUnit test, well Eclipse or IntelliJ can easily debug that for you. Other setups may require extra configuration of the app server / ESB to get debugging working. Actually, if you just want to see what the messages look like at various points in your route, try enabling the tracer http://camel.apache.org/tracer.html I will look into the tracer - didn't know of that. I have just created a Maven project and deployed it on the Servicemix ESB. Hard to find out how to debug :) If you are using the latest ServiceMix, you can follow some notes here to turn on debugging https://repository.apache.org/content/groups/public/org/apache/felix/karaf/manual/1.3.0- SNAPSHOT/manual-1.3.0-SNAPSHOT.html#KarafUsers%27Guideinonepage-5.1.Troubleshooting%2CDebuggingandProfiling This might be very helpful to me! One last novice question. In the statement: from(seda:a).filter(header(foo).isEqualTo(bar)).to(seda:b); Where does the foo comes from, I mean, where do I set it? From Eclipse I'm creating a JMS Message, but the only headers availbe is these: http://publib.boulder.ibm.com/infocenter/tivihelp/v2r1/index.jsp?topic=/com.ibm.IBMDI.doc/referenceguide95.htm Do you know how I can use these headers/properties in a Camel choice statement? Basicly, I just want to create the most simple example, where to messages are send from Eclipse and goes to two different queues in a Camel choice statement. The messages should be simple tect or objects. You should be able to access any of the JMS headers you mentioned in the same way the foo header is referenced. So how are you sending JMS messages from Eclipse? I'm assuming its a function of Tivoli in the link you provided? I (or the writer of the document I'm reading) made af Response class called InsuranceResponse. The response class is sent to the Camel Routebuilder. I would like to swith on either the classname of the object I'm sending or a field, e.g. CompanyName, in the object. I create/send like this: ObjectMessage insuranceMessage = session.createObjectMessage(); InsuranceResponse response = new InsuranceResponse(); response.setRequestID(1); response.setInsuranceCompanyName(Luxury Cars); response.setPrice(100f); response.setResponseID(UUID.randomUUID().toString()); insuranceMessage.setObject(response); producer.send(insuranceMessage); Then I receive like this (responseMessage returns null all the time, but I guess it's beacuse my Camel Routebuilder isn't wotking, so no object is send to the queue): ObjectMessage responseMessage = (ObjectMessage) consumer.receive(); InsuranceResponse insuranceMessageReceived = (InsuranceResponse) responseMessage.getObject(); So I think you are looking at: http://soa.dzone.com/articles/pattern-based-development-with-0?page=0,3 And it looks like they are using JIBX to convert between InsuranceResponses and XML. So, in the Camel route, the message is already in XML form so we can use an XPath expression something like the following to switch on the company name: xpath(//ins:TravelInsuranceRequest/ins:insuranceCompanyName/text() = 'Luxury Cars').namespace(ins,http://dzone.com/insurance;) I haven't booted up the example myself so I don't know why you are not getting any messages using the raw JMS API. Do the ServiceMix logs or Camel logs with trace enabled give you any more info on where the holdup could be? You can also use Camel to set a header like so from(seda:a).setHeader(foo,
Re: Help to understand xpath expression in camel routebuilder
On Tue, Dec 15, 2009 at 1:33 PM, Kenneth H phecda...@gmail.com wrote: On Tue, Dec 15, 2009 at 11:26 AM, Kenneth H phecda...@gmail.com wrote: 1. Where can I read about the .namespace() function syntax? I still don't get why ins is used in both functions. I tried w3schools but didn't find it. Did you find this page? http://www.w3schools.com/XML/xml_namespaces.asp That should help you understand usage of the namespace prefix and URI. I know namespaces in general, bit it was the syntax of the .namespace() function in xpath, I was looking for. Ah Cool stuff. The public javadoc may be helpful to you then http://camel.apache.org/maven/camel- core/apidocs/org/apache/camel/builder/xml/XPathBuilder.html#namespace(java.lang.String,%20java.lang.String) Perfect. Actually I was looking here earlier, but I must have missed it. 2. Is it possible to debug in the Camel routebuilder somehow? If I want to know how the message looks like before and after the .convertBodyTo(DOMSource.class). And most important: I want to know if an expression evaluates to true, i.e. I want to print-out the result of the when statement. Maybe something like this pseudocode: var travelRequest = xpath(//ins:TravelInsuranceRequest).namespace ins,http://dzone.com/insurance;)) print(travelRequest); .when(travelRequest).to(LUXURY_CAR_OUT); I guess it depends on how you have this deployed... if its a JUnit test, well Eclipse or IntelliJ can easily debug that for you. Other setups may require extra configuration of the app server / ESB to get debugging working. Actually, if you just want to see what the messages look like at various points in your route, try enabling the tracer http://camel.apache.org/tracer.html I will look into the tracer - didn't know of that. I have just created a Maven project and deployed it on the Servicemix ESB. Hard to find out how to debug :) If you are using the latest ServiceMix, you can follow some notes here to turn on debugging https://repository.apache.org/content/groups/public/org/apache/felix/karaf/manual/1.3.0- SNAPSHOT/manual-1.3.0-SNAPSHOT.html#KarafUsers%27Guideinonepage-5.1.Troubleshooting%2CDebuggingandProfiling This might be very helpful to me! One last novice question. In the statement: from(seda:a).filter(header(foo).isEqualTo(bar)).to(seda:b); Where does the foo comes from, I mean, where do I set it? From Eclipse I'm creating a JMS Message, but the only headers availbe is these: http://publib.boulder.ibm.com/infocenter/tivihelp/v2r1/index.jsp?topic=/com.ibm.IBMDI.doc/referenceguide95.htm Do you know how I can use these headers/properties in a Camel choice statement? Basicly, I just want to create the most simple example, where to messages are send from Eclipse and goes to two different queues in a Camel choice statement. The messages should be simple tect or objects. You should be able to access any of the JMS headers you mentioned in the same way the foo header is referenced. So how are you sending JMS messages from Eclipse? I'm assuming its a function of Tivoli in the link you provided? I (or the writer of the document I'm reading) made af Response class called InsuranceResponse. The response class is sent to the Camel Routebuilder. I would like to swith on either the classname of the object I'm sending or a field, e.g. CompanyName, in the object. I create/send like this: ObjectMessage insuranceMessage = session.createObjectMessage(); InsuranceResponse response = new InsuranceResponse(); response.setRequestID(1); response.setInsuranceCompanyName(Luxury Cars); response.setPrice(100f); response.setResponseID(UUID.randomUUID().toString()); insuranceMessage.setObject(response); producer.send(insuranceMessage); Then I receive like this (responseMessage returns null all the time, but I guess it's beacuse my Camel Routebuilder isn't wotking, so no object is send to the queue): ObjectMessage responseMessage = (ObjectMessage) consumer.receive(); InsuranceResponse insuranceMessageReceived = (InsuranceResponse) responseMessage.getObject(); You can also use Camel to set a header like so from(seda:a).setHeader(foo, constant(bar))... Cool. But what is the corresponding function in Eclipse/JMS to the setHeader?! You are using the raw JMS API so you can set a property on the ObjectMessage before sending. See: http://java.sun.com/j2ee/1.4/docs/api/javax/jms/Message.html Kind regards Kenneth H -- View this message in context: http://old.nabble.com/Help-to-understand-xpath-expression-in-camel-routebuilder-tp26779963p26798115.html Sent from the Camel - Users mailing list archive at Nabble.com. -- Cheers, Jon Camel in Action: http://manning.com/ibsen Blog: http://janstey.blogspot.com
Re: Help to understand xpath expression in camel routebuilder
The xpath expression is going to be evaluated against the incoming message body. So, if we have a message like: ?xml version=1.0 encoding=UTF-8? TravelInsuranceRequest xmlns=http://dzone.com/insurance; ... /TravelInsuranceRequest the first when clause will evaluate to true since the xpath expression is searching for any element like TravelInsuranceRequest. The namespace bit tells Camel to search for TravelInsuranceRequest elements only in the http://dzone.com/insurance namespace. Does this help any? On Mon, Dec 14, 2009 at 3:40 PM, Kenneth H phecda...@gmail.com wrote: Hi, I'm trying to udnerstand a camel example, but I'm stuck at a poit where xpath is used. The builder is shown here: public void configure() { from(SERVICE_IN) // SERVICE_IN = jbi:service:http://esbinaction.com/insurance/insuranceDSLRouter .convertBodyTo(DOMSource.class) // Convert to DOM tree .choice() .when(xpath(//ins:TravelInsuranceRequest).namespace(ins, http://dzone.com/insurance;)) .to(TRAVEL_OUT) .when(xpath(//ins:CarInsuranceRequest).namespace(ins, http://dzone.com/insurance;)) .to(LUXURY_CAR_OUT, BUDGET_CAR_OUT) .otherwise() .to(FAILURE_OUT); } My problem is the when: what exactly does: when(xpath(//ins:TravelInsuranceRequest).namespace(ins, http://dzone.com/insurance;)) mean? Can anybody help me? Kind regards, Kenneth H -- View this message in context: http://old.nabble.com/Help-to-understand-xpath-expression-in-camel-routebuilder-tp26779963p26779963.html Sent from the Camel - Users mailing list archive at Nabble.com. -- Cheers, Jon Camel in Action: http://manning.com/ibsen Blog: http://janstey.blogspot.com