camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From toroskar <toros...@gmail.com>
Subject Xquery function error
Date Mon, 15 May 2017 11:45:06 GMT
Hi
We are in the progress of upgrading from Camel 2.18 to 2.18.3. Doing that we
get a strange error when we try to call an Xquery function. (This works
perfect in 2.17)

This piece of code is the problem.

 /Element innsedningElement =
            innsendingBuilder.evaluate(exchange.getContext(),
exchange.getIn().getBody(Document.class), Element.class);/

The error message we get when we evaluate the xquery is:

/Type error 
  XPTY0004: Required item type of value of variable $dokument is element();
supplied value
  has item type
Q{http://saxon.sf.net/java-type}org.apache.xerces.dom.DeferredElementImpl
org.apache.camel.RuntimeExpressionException:
net.sf.saxon.trans.XPathException: Required item type of value of variable
$dokument is element(); supplied value has item type
Q{http://saxon.sf.net/java-
type}org.apache.xerces.dom.DeferredElementImpl
	at
org.apache.camel.component.xquery.XQueryBuilder.evaluate(XQueryBuilder.java:148)
	at
org.apache.camel.component.xquery.XQueryBuilder.evaluate(XQueryBuilder.java:113)
	at
ske.navneendring.processor.dispatcher.LagVedleggreferanseliste.process(LagVedleggreferanseliste.java:47)
	at
org.apache.camel.processor.DelegateSyncProcessor.process(DelegateSyncProcessor.java:63)
	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)
	at org.apache.camel.processor.Pipeline.process(Pipeline.java:120)
	at org.apache.camel.processor.Pipeline.process(Pipeline.java:83)
	at
org.apache.camel.processor.ChoiceProcessor.process(ChoiceProcessor.java:117)
	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)
	at org.apache.camel.processor.Pipeline.process(Pipeline.java:120)
	at org.apache.camel.processor.Pipeline.process(Pipeline.java:83)
	at
org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:197)
	at
org.apache.camel.component.direct.DirectProducer.process(DirectProducer.java:62)
	at
org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:197)
	at
org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:97)
	at
org.apache.camel.impl.ProducerCache$1.doInProducer(ProducerCache.java:529)
	at
org.apache.camel.impl.ProducerCache$1.doInProducer(ProducerCache.java:497)
	at org.apache.camel.impl.ProducerCache.doInProducer(ProducerCache.java:365)
	at org.apache.camel.impl.ProducerCache.sendExchange(ProducerCache.java:497)
	at org.apache.camel.impl.ProducerCache.send(ProducerCache.java:209)
	at
org.apache.camel.impl.DefaultProducerTemplate.send(DefaultProducerTemplate.java:139)
	at
org.apache.camel.impl.DefaultProducerTemplate.send(DefaultProducerTemplate.java:125)
	at
ske.navneendring.route.DispatcherRouteTest.skalRouteTilFordelingskoe(DispatcherRouteTest.java:87)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at
org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
	at
org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
	at
org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
	at
org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
	at
org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
	at
org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:75)
	at
org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:86)
	at
com.github.tomakehurst.wiremock.junit.WireMockRule$1.evaluate(WireMockRule.java:72)
	at org.junit.rules.RunRules.evaluate(RunRules.java:20)
	at
org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:84)
	at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
	at
org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:252)
	at
org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:94)
	at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
	at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
	at
org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
	at
org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)
	at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
	at
org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:191)
	at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
	at
com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:117)
	at
com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:42)
	at
com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:253)
	at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:84)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at com.intellij.rt.execution.application.AppMain.main(AppMain.java:147)
Caused by: net.sf.saxon.trans.XPathException: Required item type of value of
variable $dokument is element(); supplied value has item type
Q{http://saxon.sf.net/java-type}org.apache.xerces.dom.DeferredElementImpl
	at
net.sf.saxon.expr.ItemTypeCheckingFunction.testConformance(ItemTypeCheckingFunction.java:68)
	at
net.sf.saxon.expr.ItemTypeCheckingFunction.mapItem(ItemTypeCheckingFunction.java:47)
	at net.sf.saxon.expr.ItemMappingIterator.next(ItemMappingIterator.java:113)
	at
net.sf.saxon.expr.CardinalityCheckingIterator.<init>(CardinalityCheckingIterator.java:51)
	at
net.sf.saxon.type.TypeHierarchy.applyFunctionConversionRules(TypeHierarchy.java:235)
	at
net.sf.saxon.expr.instruct.GlobalParameterSet.convertParameterValue(GlobalParameterSet.java:106)
	at net.sf.saxon.Controller.getConvertedParameter(Controller.java:371)
	at
net.sf.saxon.expr.instruct.GlobalParam.evaluateVariable(GlobalParam.java:64)
	at
net.sf.saxon.expr.GlobalVariableReference.evaluateVariable(GlobalVariableReference.java:127)
	at
net.sf.saxon.expr.parser.ExpressionTool.evaluate(ExpressionTool.java:297)
	at
net.sf.saxon.expr.UserFunctionCall.evaluateArguments(UserFunctionCall.java:621)
	at
net.sf.saxon.expr.UserFunctionCall.iterateEvents(UserFunctionCall.java:591)
	at
net.sf.saxon.query.XQueryExpression.internalIterateEvents(XQueryExpression.java:578)
	at net.sf.saxon.query.XQueryExpression.pull(XQueryExpression.java:507)
	at
org.apache.camel.component.xquery.XQueryBuilder.evaluateAsDOM(XQueryBuilder.java:182)
	at
org.apache.camel.component.xquery.XQueryBuilder.evaluate(XQueryBuilder.java:138)
	... 62 more
org.apache.camel.RuntimeExpressionException:
net.sf.saxon.trans.XPathException: Required item type of value of variable
$dokument is element(); supplied value has item type
Q{http://saxon.sf.net/java-type}org.apache.xerces.dom.DeferredElementImpl
	at
org.apache.camel.component.xquery.XQueryBuilder.evaluate(XQueryBuilder.java:148)
	at
org.apache.camel.component.xquery.XQueryBuilder.evaluate(XQueryBuilder.java:113)
	at
ske.navneendring.processor.dispatcher.LagVedleggreferanseliste.process(LagVedleggreferanseliste.java:47)
	at
org.apache.camel.processor.DelegateSyncProcessor.process(DelegateSyncProcessor.java:63)
	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)
	at org.apache.camel.processor.Pipeline.process(Pipeline.java:120)
	at org.apache.camel.processor.Pipeline.process(Pipeline.java:83)
	at
org.apache.camel.processor.ChoiceProcessor.process(ChoiceProcessor.java:117)
	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)
	at org.apache.camel.processor.Pipeline.process(Pipeline.java:120)
	at org.apache.camel.processor.Pipeline.process(Pipeline.java:83)
	at
org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:197)
	at
org.apache.camel.component.direct.DirectProducer.process(DirectProducer.java:62)
	at
org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:197)
	at
org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:97)
	at
org.apache.camel.impl.ProducerCache$1.doInProducer(ProducerCache.java:529)
	at
org.apache.camel.impl.ProducerCache$1.doInProducer(ProducerCache.java:497)
	at org.apache.camel.impl.ProducerCache.doInProducer(ProducerCache.java:365)
	at org.apache.camel.impl.ProducerCache.sendExchange(ProducerCache.java:497)
	at org.apache.camel.impl.ProducerCache.send(ProducerCache.java:209)
	at
org.apache.camel.impl.DefaultProducerTemplate.send(DefaultProducerTemplate.java:139)
	at
org.apache.camel.impl.DefaultProducerTemplate.send(DefaultProducerTemplate.java:125)
	at
ske.navneendring.route.DispatcherRouteTest.skalRouteTilFordelingskoe(DispatcherRouteTest.java:87)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at
org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
	at
org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
	at
org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
	at
org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
	at
org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
	at
org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:75)
	at
org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:86)
	at
com.github.tomakehurst.wiremock.junit.WireMockRule$1.evaluate(WireMockRule.java:72)
	at org.junit.rules.RunRules.evaluate(RunRules.java:20)
	at
org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:84)
	at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
	at
org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:252)
	at
org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:94)
	at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
	at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
	at
org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
	at
org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)
	at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
	at
org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:191)
	at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
	at
com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:117)
	at
com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:42)
	at
com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:253)
	at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:84)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at com.intellij.rt.execution.application.AppMain.main(AppMain.java:147)
Caused by: net.sf.saxon.trans.XPathException: Required item type of value of
variable $dokument is element(); supplied value has item type
Q{http://saxon.sf.net/java-type}org.apache.xerces.dom.DeferredElementImpl
	at
net.sf.saxon.expr.ItemTypeCheckingFunction.testConformance(ItemTypeCheckingFunction.java:68)
/



The class we use:

/package ske.navneendring.processor.dispatcher;

import static org.apache.camel.builder.xml.XPathBuilder.xpath;
import static org.apache.camel.component.xquery.XQueryBuilder.xquery;

import java.nio.file.Files;
import java.nio.file.Paths;

import org.apache.camel.Exchange;
import org.apache.camel.Processor;
import org.apache.camel.builder.xml.XPathBuilder;
import org.apache.camel.component.xquery.XQueryBuilder;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;

import ske.navneendring.config.ExchangeProperties;

public class LagVedleggreferanseliste implements Processor {

    private static final String INNSENDING_ELEMENT_XPATH =
"/entry/content/innsending";
    private static final String VEDLEGG_XQ = "/xquery/vedlegg.xq";
    //private static final String VEDLEGG_XQ = "/xquery/vedleggtest.xq";
    private static final String DOK_PARAMETER = "dokument";

    @Override
    public void process(Exchange exchange) throws Exception {

        XPathBuilder innsendingBuilder = xpath(INNSENDING_ELEMENT_XPATH,
Element.class);
        Element innsedningElement =
            innsendingBuilder.evaluate(exchange.getContext(),
exchange.getIn().getBody(Document.class), Element.class);

        String xqueryFile = VEDLEGG_XQ;
        XQueryBuilder vedleggBuilder;
        /// For unittest purposes
        if (exchange.getProperty("XqueryFile", String.class) != null) {
            xqueryFile = exchange.getProperty("XqueryFile", String.class);
            vedleggBuilder = xquery(new
String(Files.readAllBytes(Paths.get(xqueryFile))));
        }
        else
        {
            vedleggBuilder = xquery(getClass().getResource(xqueryFile));
        }


        vedleggBuilder.parameter(DOK_PARAMETER, innsedningElement);
        String dokumenter = vedleggBuilder.evaluate(exchange, String.class);

        exchange.setProperty(ExchangeProperties.DOKUMENTER, dokumenter);
    }
}
/

And the Xquery function: 


/
declare namespace ns0 =
"urn:skatteetaten:felles:basistyper:v4:dokumentbasistyper";
declare namespace xf =
"http://tempuri.org/FellesBasis/Transformasjoner/FraBasistyperDokumentV2TilV4/";


declare function xf:FraFeedTilVedleggslise($dokument as element())
as element() {

    <ns0:dokumenter>


        {
        for $vedlegg in $dokument/vedlegg
        return
        <ns0:dokument>
           
<ns0:refTilInnhold>{data($vedlegg/link/href)}</ns0:refTilInnhold>
            <ns0:filnavn>{data($vedlegg/originaltFilnavn)}</ns0:filnavn>
            <ns0:filtype></ns0:filtype>
            <ns0:mimetype>{data($vedlegg/link/type)}</ns0:mimetype>
            <ns0:vedleggstype></ns0:vedleggstype>
           
<ns0:eksternreferanse>{data($vedlegg/altinnReferanse)}</ns0:eksternreferanse>
            <ns0:kryptert>false</ns0:kryptert>
            <ns0:internreferanse></ns0:internreferanse>
           
<ns0:presentasjonsnavn>{data($vedlegg/originaltFilnavn)}</ns0:presentasjonsnavn>
        </ns0:dokument>
        }

 </ns0:dokumenter>
};


declare variable $dokument as element() external;

xf:FraFeedTilVedleggslise($dokument)/



Do anyone have any clue of what has happened from 2.17 to 2.18 in this area?
Whats wrong?


Br
Tor Oskar Wilhelmsen






--
View this message in context: http://camel.465427.n5.nabble.com/Xquery-function-error-tp5799537.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Mime
View raw message