1
votes

I have problem to use xquery on a JMS message using apache camel and wildfly.

My code reads from an jms queue and try to filter the message

import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.cdi.ContextName;
import org.apache.camel.component.jms.JmsComponent;
import org.wildfly.extension.camel.CamelAware;

import javax.annotation.Resource;
import javax.ejb.Startup;
import javax.enterprise.context.ApplicationScoped;
import javax.jms.ConnectionFactory;


@Startup
@CamelAware
@ApplicationScoped
@ContextName("test")
class MyRouteBuilder extends RouteBuilder {


    @Resource(mappedName = "java:jboss/DefaultJMSConnectionFactory")
    private ConnectionFactory connectionFactory;

    @Override
    public void configure() throws Exception {

        getContext().addComponent("jms", JmsComponent.jmsComponentAutoAcknowledge(connectionFactory));


        from("jms:queue:test1").
                routeId("test").
                to("log:jms?showAll=true").
                filter().xquery("fn:contains(//person/name/text(),'james')").
                to("file://Users/asse/Outbound");

When I run the code with the message <person><name>james</name><person> I get the error:

Message History --------------------------------------------------------------------------------------------------------------------------------------- RouteId ProcessorId Processor
Elapsed (ms) [test ] [test ] [jms://queue:test1
] [ 5] [test ] [to7 ] [log:jms?showAll=true
] [ 1] [test ] [filter7 ] [filter[xquery{XQuery[net.sf.saxon.query.XQueryExpression@3af367ad]}] ] [ 2]

Stacktrace ---------------------------------------------------------------------------------------------------------------------------------------: org.apache.camel.RuntimeExpressionException: java.lang.NullPointerException: External object cannot wrap a Java null at org.apache.camel.component.xquery.XQueryBuilder.matches(XQueryBuilder.java:220) at org.apache.camel.processor.FilterProcessor.matches(FilterProcessor.java:65) at org.apache.camel.processor.FilterProcessor.process(FilterProcessor.java:51) at org.apache.camel.management.InstrumentationProcessor.process(InstrumentationProcessor.java:77) at org.apache.camel.processor.RedeliveryErrorHandler.process(RedeliveryErrorHandler.java:542) at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:197)

I don't understand why! Can anyone help me with this problem??

1
The above code works for wildfly 9.0.2 final with wildfly-camel-patch-3.3.0 but not with wildfly 10.1.0 final and wildfly-camel-patch 4.3.0 and 4.4.0. The code also work in all versions if the message come from a file endpoint.anpt

1 Answers

1
votes

Encountered the same issue with standalone camel 2.18.1.

I believe this is a bug in camel caused by upgrading to Saxon version 9.7.0, which no longer allows null values to be put into query context The bug is in class org.apache.camel.component.xquery.XQueryBuilder. It attempt to add all Exchange headers and properties to query execution context in method org.apache.camel.component.xquery.XQueryBuilder#configureQuery. If any of the headers or properties have null values (and in case of JMS message there will be lots of headers), an exception is thrown.

I was able to reproduce the issue and it seems it is not the only problem with xquery in camel 2.18

I've logged a jira issue https://issues.apache.org/jira/browse/CAMEL-10653