Hi
I have the following issue: I created a processor which sets depending on
the sessionid a header value in the exchange
When I configure now a "choice" in spring xml which routes based on this
header field I get an exception:
how should the route look like?
My code now: (xml)
<route>
<from ref="input1" />
<to uri="createProcessor" />
<to uri="realtimeProcessor" />
<to uri="queueSwitchProcessor" />
<choice>
<when>
<xpath>$queueid = "0"</xpath>
<to ref="output1"/>
</when>
<when>
<xpath>$queueid = "1"</xpath>
<to ref="output2"/>
</when>
<otherwise>
<to ref="output3"/>
</otherwise>
</choice>
</route>
My code of the processor (queueSwitchProcessor):
public void process(Exchange exchange) throws Exception {
ObjectImpressionTransportBean transportBean =
(ObjectImpressionTransportBean)(exchange.getIn().getBody());
String sessionid =
transportBean.getSensorCall().getParameter().get(PARAMETERKEY_SESSIONID);
if (sessionid != null) {
int queueid = sessionid.hashCode();
if (queueid < 0) {queueid = queueid * -1;}
queueid = queueid%numberOfConsumers;
exchange.getIn().setHeader("queueid",
Integer.toString(queueid));
} else {
exchange.getIn().setHeader("queueid", "0");
}
}
how do I access the header field "queueid" via xpath???
now i get this exception: (because its trying to access the body!!!)
2008-07-21 14:09:39,170 ERROR [DefaultMessageListenerContainer-17]
org.apache.camel.processor.DeadLetterChannel: Failed delivery for
exchangeId: ID-power/2826-1216642175780/0-8. On delivery attempt: 2 caught:
java.lang.ClassCastException:
com.fatwire.analytics.domain.ObjectImpressionTransportBean
java.lang.ClassCastException:
com.fatwire.analytics.domain.ObjectImpressionTransportBean
at
com.sun.org.apache.xpath.internal.jaxp.XPathExpressionImpl.eval(XPathExpressionImpl.java:115)
at
com.sun.org.apache.xpath.internal.jaxp.XPathExpressionImpl.eval(XPathExpressionImpl.java:97)
at
com.sun.org.apache.xpath.internal.jaxp.XPathExpressionImpl.evaluate(XPathExpressionImpl.java:178)
at
org.apache.camel.builder.xml.XPathBuilder.evaluateAs(XPathBuilder.java:429)
at
org.apache.camel.builder.xml.XPathBuilder.matches(XPathBuilder.java:98)
at
org.apache.camel.builder.xml.XPathBuilder.matches(XPathBuilder.java:63)
at
org.apache.camel.processor.ChoiceProcessor.process(ChoiceProcessor.java:47)
--
View this message in context:
http://www.nabble.com/how-to-use-xpath-in-spring-xml-and-query-header-fields-tp18567110s22882p18567110.html
Sent from the Camel - Users mailing list archive at Nabble.com.