Details
-
Bug
-
Status: Resolved
-
Minor
-
Resolution: Fixed
-
3.20.1
-
None
-
Unknown
Description
I get a NullPointerException when running a basic route that sends data to the language:xquery endpoint. It looks like the exception is caused the the Saxon Configuration object not being initialized.
Here is an example that reproduces the error:
public class CamelXQueryLanguageTest { public static void main(String[] args) throws Exception { CamelContext context = new DefaultCamelContext(); context.start(); ProducerTemplate producer = context.createProducerTemplate(); String result = producer.requestBody( "language:xquery:upper-case(/message/text())", "<message>Hello from XQuery</message>", String.class); System.out.println("Result: " + result); context.stop(); } }
Here is the stack trace from this code:
Exception in thread "main" org.apache.camel.CamelExecutionException: Exception occurred during execution on the exchange: Exchange[] at org.apache.camel.CamelExecutionException.wrapCamelExecutionException(CamelExecutionException.java:45) at org.apache.camel.support.ExchangeHelper.extractResultBody(ExchangeHelper.java:660) at org.apache.camel.impl.engine.DefaultProducerTemplate.extractResultBody(DefaultProducerTemplate.java:591) at org.apache.camel.impl.engine.DefaultProducerTemplate.extractResultBody(DefaultProducerTemplate.java:587) at org.apache.camel.impl.engine.DefaultProducerTemplate.requestBody(DefaultProducerTemplate.java:414) at org.acme.CamelXQueryLanguageTest.main(CamelXQueryLanguageTest.java:14) Caused by: org.apache.camel.RuntimeExpressionException: java.lang.NullPointerException: Cannot invoke "net.sf.saxon.Configuration.makeErrorReporter()" because "config" is null at org.apache.camel.component.xquery.XQueryBuilder.evaluate(XQueryBuilder.java:202) at org.apache.camel.component.xquery.XQueryBuilder.evaluate(XQueryBuilder.java:167) at org.apache.camel.component.language.LanguageProducer.process(LanguageProducer.java:110) at org.apache.camel.support.AsyncProcessorConverterHelper$ProcessorToAsyncProcessorBridge.process(AsyncProcessorConverterHelper.java:66) at org.apache.camel.impl.engine.SharedCamelInternalProcessor.process(SharedCamelInternalProcessor.java:214) at org.apache.camel.impl.engine.SharedCamelInternalProcessor$1.process(SharedCamelInternalProcessor.java:111) at org.apache.camel.impl.engine.DefaultAsyncProcessorAwaitManager.process(DefaultAsyncProcessorAwaitManager.java:83) at org.apache.camel.impl.engine.SharedCamelInternalProcessor.process(SharedCamelInternalProcessor.java:108) at org.apache.camel.support.cache.DefaultProducerCache.send(DefaultProducerCache.java:199) at org.apache.camel.impl.engine.DefaultProducerTemplate.send(DefaultProducerTemplate.java:176) at org.apache.camel.impl.engine.DefaultProducerTemplate.send(DefaultProducerTemplate.java:172) at org.apache.camel.impl.engine.DefaultProducerTemplate.requestBody(DefaultProducerTemplate.java:413) ... 1 more Caused by: java.lang.NullPointerException: Cannot invoke "net.sf.saxon.Configuration.makeErrorReporter()" because "config" is null at net.sf.saxon.query.DynamicQueryContext.<init>(DynamicQueryContext.java:58) at org.apache.camel.component.xquery.XQueryBuilder.createDynamicContext(XQueryBuilder.java:569) at org.apache.camel.component.xquery.XQueryBuilder.evaluateAsDOM(XQueryBuilder.java:230) at org.apache.camel.component.xquery.XQueryBuilder.evaluate(XQueryBuilder.java:192) ... 12 more
If I create an instance of the Configuration object explicitly and set it in the XQueryLanguage, that NPE disappears only for another one to be thrown when evaluating the expression.
For example, if I add the following 2 lines before starting the context:
XQueryLanguage language = (XQueryLanguage) context.resolveLanguage("xquery"); language.setConfiguration(new Configuration()); context.start();
An exception now appears via:
Caused by: org.apache.camel.RuntimeExpressionException: java.lang.NullPointerException: Cannot invoke "net.sf.saxon.query.XQueryExpression.run(net.sf.saxon.query.DynamicQueryContext, javax.xml.transform.Result, java.util.Properties)" because "expression" is null at org.apache.camel.component.xquery.XQueryBuilder.evaluate(XQueryBuilder.java:202) at org.apache.camel.component.xquery.XQueryBuilder.evaluate(XQueryBuilder.java:167) at org.apache.camel.component.language.LanguageProducer.process(LanguageProducer.java:110) at org.apache.camel.support.AsyncProcessorConverterHelper$ProcessorToAsyncProcessorBridge.process(AsyncProcessorConverterHelper.java:66) at org.apache.camel.impl.engine.SharedCamelInternalProcessor.process(SharedCamelInternalProcessor.java:214) at org.apache.camel.impl.engine.SharedCamelInternalProcessor$1.process(SharedCamelInternalProcessor.java:111) at org.apache.camel.impl.engine.DefaultAsyncProcessorAwaitManager.process(DefaultAsyncProcessorAwaitManager.java:83) at org.apache.camel.impl.engine.SharedCamelInternalProcessor.process(SharedCamelInternalProcessor.java:108) at org.apache.camel.support.cache.DefaultProducerCache.send(DefaultProducerCache.java:199) at org.apache.camel.impl.engine.DefaultProducerTemplate.send(DefaultProducerTemplate.java:176) at org.apache.camel.impl.engine.DefaultProducerTemplate.send(DefaultProducerTemplate.java:172) at org.apache.camel.impl.engine.DefaultProducerTemplate.requestBody(DefaultProducerTemplate.java:413) ... 1 more Caused by: java.lang.NullPointerException: Cannot invoke "net.sf.saxon.query.XQueryExpression.run(net.sf.saxon.query.DynamicQueryContext, javax.xml.transform.Result, java.util.Properties)" because "expression" is null at org.apache.camel.component.xquery.XQueryBuilder.evaluateAsDOM(XQueryBuilder.java:232) at org.apache.camel.component.xquery.XQueryBuilder.evaluate(XQueryBuilder.java:192) ... 12 more