You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@camel.apache.org by geppo <ge...@gmail.com> on 2014/06/23 18:43:54 UTC
Filter on content of a tag
Hi,
I have a Camel route that reads from a queue containing XML messages e.g.
<MY_LIST>
<MSG>
<ID>1234</ID>
</MSG>
<SOURCE>source1</SOURCE>
...
I want to process only messages of type MyList and where SOURCE=source1
I've written the filter for the check MyList.class and it works fine, but I
don't know how to write the filter that checks the SOURCE tag. Any idea?
from(inboundQueue)
.routeId(id)
.filter().body(MyList.class)
.filter().body(MyList.getSource().equals("source1")) <-- Just some random
code!
.unmarshal(jaxb)
.process(myProcessor)
.log("Completed")
--
View this message in context: http://camel.465427.n5.nabble.com/Filter-on-content-of-a-tag-tp5752705.html
Sent from the Camel Development mailing list archive at Nabble.com.
Re: Filter on content of a tag
Posted by "Willem.Jiang" <wi...@gmail.com>.
Please use users mailing list instead of dev list to ask the user question.
--
View this message in context: http://camel.465427.n5.nabble.com/Filter-on-content-of-a-tag-tp5752705p5752717.html
Sent from the Camel Development mailing list archive at Nabble.com.
Re: AW: Filter on content of a tag
Posted by geppo <ge...@gmail.com>.
Thank you!
--
View this message in context: http://camel.465427.n5.nabble.com/Filter-on-content-of-a-tag-tp5752705p5752733.html
Sent from the Camel Development mailing list archive at Nabble.com.
AW: Filter on content of a tag
Posted by "Jan Matèrne (jhm)" <ap...@materne.de>.
This one works for me
Jan
import org.apache.camel.EndpointInject;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.mock.MockEndpoint;
import org.apache.camel.test.junit4.CamelTestSupport;
import org.junit.Test;
import static org.apache.camel.builder.SimpleBuilder.simple;
public class XmlFilterTest extends CamelTestSupport {
@EndpointInject(uri="mock:end")
MockEndpoint mock;
String bodyTemplate =
"<MY_LIST><MSG><ID>@id@</ID></MSG><SOURCE>@source@</SOURCE></MY_LIST>";
private void send(String id, String source) {
template.sendBody("direct:in", bodyTemplate.replace("@id@",
id).replace("@source@", source));
}
@Test
public void test() throws InterruptedException {
mock.expectedMessageCount(2);
mock.expectedMessagesMatches(
simple("${body} contains 'source1'"),
simple("${body} contains 'source1'")
);
send("1", "source1");
send("2", "source2");
send("3", "source1");
assertMockEndpointsSatisfied();
}
@Override
protected RouteBuilder createRouteBuilder() throws Exception {
return new RouteBuilder() {
@Override
public void configure() throws Exception {
from("direct:in")
.filter().xpath("/MY_LIST/SOURCE/text() = 'source1'")
.to("mock:end");
}
};
}
}
> -----Ursprüngliche Nachricht-----
> Von: geppo [mailto:gepporello@gmail.com]
> Gesendet: Montag, 23. Juni 2014 18:44
> An: dev@camel.apache.org
> Betreff: Filter on content of a tag
>
> Hi,
> I have a Camel route that reads from a queue containing XML messages
> e.g.
>
> <MY_LIST>
> <MSG>
> <ID>1234</ID>
> </MSG>
> <SOURCE>source1</SOURCE>
> ...
>
> I want to process only messages of type MyList and where SOURCE=source1
> I've written the filter for the check MyList.class and it works fine,
> but I don't know how to write the filter that checks the SOURCE tag.
> Any idea?
>
> from(inboundQueue)
> .routeId(id)
> .filter().body(MyList.class)
> .filter().body(MyList.getSource().equals("source1")) <-- Just some
> random code!
> .unmarshal(jaxb)
> .process(myProcessor)
> .log("Completed")
>
>
>
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/Filter-
> on-content-of-a-tag-tp5752705.html
> Sent from the Camel Development mailing list archive at Nabble.com.