Just replace "setHeader" with "setProperty" ...
Jan
package de.materne.camel.test;
import org.apache.camel.Exchange;
import org.apache.camel.Predicate;
import org.apache.camel.builder.PredicateBuilder;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.mock.MockEndpoint;
import org.apache.camel.test.junit4.CamelTestSupport;
import org.junit.Test;
public class XPathTest extends CamelTestSupport {
@Test
public void check() throws InterruptedException {
MockEndpoint mock = getMockEndpoint("mock:end");
mock.expectedMessageCount(1);
mock.expectedMessagesMatches(PredicateBuilder.and(
propertyIs("author", "ABC"),
propertyIs("type", "Children"),
propertyIs("id", "123"),
propertyIs("name", "XYZ")
));
String xml = "<book author=\"ABC\"
type=\"Children\"><id>123</id><name>XYZ</name></book>";
template.sendBody("direct:in", xml);
assertMockEndpointsSatisfied();
}
private Predicate propertyIs(final String propertyKey, final String
expectedValue) {
return new Predicate() {
@Override
public boolean matches(Exchange exchange) {
Object actualValue = exchange.getProperty(propertyKey);
return actualValue != null &&
actualValue.equals(expectedValue);
}
};
}
@Override
protected RouteBuilder createRouteBuilder() throws Exception {
return new RouteBuilder() {
@Override
public void configure() throws Exception {
from("direct:in")
.setProperty("author", xpath("/book/@author",
String.class))
.setProperty("type", xpath("/book/@type", String.class))
.setProperty("id", xpath("/book/id", String.class))
.setProperty("name", xpath("/book/name", String.class))
.to("mock:end");
}
};
}
}
> -----Ursprüngliche Nachricht-----
> Von: Satyam Maloo [mailto:[email protected]]
> Gesendet: Donnerstag, 27. März 2014 13:49
> An: [email protected]
> Betreff: Re: AW: Extract the value from property
>
> Thanks for replying, but I know how it is done with header. I want the
> solution using property.
>
>
>
> -----
> Satyam
> --
> View this message in context:
> http://camel.465427.n5.nabble.com/Extract-the-value-from-property-
> tp5749428p5749435.html
> Sent from the Camel - Users mailing list archive at Nabble.com.