camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Raul Kripalani <r...@evosent.com>
Subject Re: xpath filter question
Date Sat, 16 Nov 2013 14:42:43 GMT
In the future, you can use the .logNamespaces() option of the XPath
expression to ask Camel to dump to your log files the namespaces that are
discovered in your incoming XML payload.

BTW - the work your processor is doing is simply to convert the payload to
a String. You can achieve this by using the .convertBodyTo(String.class)
DSL. But I suspect that you don't need it at all, as you yourself are
figuring out...

Regards,

*Raúl Kripalani*
Apache Camel PMC Member & Committer | Enterprise Architect, Open Source
Integration specialist
http://about.me/raulkripalani | http://www.linkedin.com/in/raulkripalani
http://blog.raulkr.net | twitter: @raulvk

On Fri, Nov 15, 2013 at 2:59 PM, John Dubchak <john@johndubchak.com> wrote:

> Hi Reji,
>
> Thanks for the response.  I added an .otherwise().log("xpath predicate
> failed...") and found out that I was running into an issue with namespaces.
>  Once I addressed the namespace issue, I was able to send a notification
> and have it work through the route correctly.
>
> Here is what I ended up with:
>
> DataFormat jaxb = new JaxbDataFormat("com.example.
> services.schemas.notification");
> Namespaces ns = new Namespaces("tns", "http://www.example.com/
> services/notifications");
>
> from("activemq:cdw.Notifications")
>     .log("Recieved notification ${id}: ")
>   .choice()
>         .when(ns.xpath("/tns:notification/tns:type = 'email'"))
>         .process(new Processor() {
>             @Override
>             public void process(Exchange exchange) throws Exception {
>                 String body = exchange.getIn().getBody(String.class);
>                 exchange.getOut().setBody(body);
>             }
>         })
>             .unmarshal(jaxb).bean(notifier, "send")
>         .otherwise().log("No match for message: ${id}").stop();
>
> I'm not entirely positive that I require the processor before
> unmarshaling, however it works and I may end up removing that and testing
> it again.  But, it was a namespace issue in the XML and xpath wasn't
> matching as a result.
>
> John
>
>
> On 11/14/13 7:04 PM, Reji Mathews wrote:
>
>> John
>>
>> What is the error?  Anything in log?  And to which component are u
>> sending the message after removing the processor
>>
>> Reji
>>
>> Ravindra.Godbole@cognizant.com wrote:
>>
>>  Can you share the sample xml message ? Does it have namespace in it ?
>>> ________________________________________
>>> From: John Dubchak [john@johndubchak.com]
>>> Sent: Friday, November 15, 2013 1:42 AM
>>> To: users@camel.apache.org
>>> Subject: xpath filter question
>>>
>>> Hi,
>>>
>>> I am trying to create a JavaDSL route that filters an incoming XML from
>>> an ActiveMQ queue.  The message is being delivered correctly and I can
>>> print it out if I short-circuit it with a processor that dumps the
>>> message.  However, removing the processor, I cannot seem to get the
>>> correct xpath expression to match on a particular value:
>>>
>>> from("activemq:cdw.Notifications")
>>>    .filter()
>>> .xpath("/parent_node[child_node = 'value of text']")
>>>
>>> Any insight into what I've messed up?
>>>
>>> Thanks,
>>> John
>>>
>>>
>>>
>>>
>>>
>>> This e-mail and any files transmitted with it are for the sole use of
>>> the intended recipient(s) and may contain confidential and privileged
>>> information. If you are not the intended recipient(s), please reply to the
>>> sender and destroy all copies of the original message. Any unauthorized
>>> review, use, disclosure, dissemination, forwarding, printing or copying of
>>> this email, and/or any action taken in reliance on the contents of this
>>> e-mail is strictly prohibited and may be unlawful.
>>>
>>
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message