Mule expression in logger component not valid xpath - xpath

I have an xml like this:
<order>
<orderheader>
<orderissuedate>1/11/2013</orderissuedate>
</orderheader>
</order>
in the mule logger component set with INFO, i have a mule expression that tries to print out the orderissuedate 1/11/2013.
i use the expression:
[xpath('/order/orderheader//orderissuedate')] which didn't work.
i also tried: #[xpath('/order/orderheader/orderissuedate/text()').text] that didnt work also.
can someone tell me what the correct xpath expression is. i get this error message:
java.lang.RuntimeException: org.mule.api.MuleRuntimeException: Failed to evaluate XPath expression: "/Order/OrderHeader/OrderIssueDate/text()"
I've tested these xpath expressions using online xpath checkers, and they seem to work. thanks for your help.
Here is the original xml:
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE Order>
<Order
xmlns:core="rrn:org.xcbl:schemas/xcbl/v4_0/core/core.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<OrderHeader>
<OrderNumber>
<BuyerOrderNumber>111111</BuyerOrderNumber>
</OrderNumber>
<OrderIssueDate>2013-06-28T08:40:12</OrderIssueDate>
<OrderReferences>
<AccountCode>
<core:RefNum></core:RefNum>
</AccountCode>
</OrderReferences>
</OrderHeader>
</Order>
and the error output from mule:
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
java.lang.RuntimeException: org.mule.api.MuleRuntimeException: Failed to evaluate XPath expression: "/OrderIssueDate"
at org.mule.module.xml.el.XPathFunction.call(XPathFunction.java:50)
at org.mule.el.mvel.MVELFunctionAdaptor.call(MVELFunctionAdaptor.java:38)
at org.mvel2.optimizers.impl.refl.ReflectiveAccessorOptimizer.getMethod(ReflectiveAccessorOptimizer.java:1011)
at org.mvel2.optimizers.impl.refl.ReflectiveAccessorOptimizer.getMethod(ReflectiveAccessorOptimizer.java:987)
at org.mvel2.optimizers.impl.refl.ReflectiveAccessorOptimizer.compileGetChain(ReflectiveAccessorOptimizer.java:377)
at org.mvel2.optimizers.impl.refl.ReflectiveAccessorOptimizer.optimizeAccessor(ReflectiveAccessorOptimizer.java:143)
at org.mvel2.ast.ASTNode.optimize(ASTNode.java:159)
at org.mvel2.ast.ASTNode.getReducedValueAccelerated(ASTNode.java:115)
at org.mvel2.MVELRuntime.execute(MVELRuntime.java:85)
at org.mvel2.compiler.CompiledExpression.getDirectValue(CompiledExpression.java:123)
at org.mvel2.compiler.CompiledExpression.getValue(CompiledExpression.java:119)
at org.mvel2.compiler.CompiledExpression.getValue(CompiledExpression.java:113)
at org.mvel2.MVEL.executeExpression(MVEL.java:942)
at org.mule.el.mvel.MVELExpressionExecutor.execute(MVELExpressionExecutor.java:50)
at org.mule.el.mvel.MVELExpressionLanguage.evaluateInternal(MVELExpressionLanguage.java:214)
at org.mule.el.mvel.MVELExpressionLanguage.evaluate(MVELExpressionLanguage.java:163)
at org.mule.el.mvel.MVELExpressionLanguage.evaluate(MVELExpressionLanguage.java:142)
at org.mule.expression.DefaultExpressionManager.evaluate(DefaultExpressionManager.java:220)
at org.mule.expression.DefaultExpressionManager$2.match(DefaultExpressionManager.java:481)
at org.mule.util.TemplateParser.parse(TemplateParser.java:153)
at org.mule.util.TemplateParser.parse(TemplateParser.java:130)
at org.mule.expression.DefaultExpressionManager.parse(DefaultExpressionManager.java:477)
at org.mule.expression.DefaultExpressionManager.parse(DefaultExpressionManager.java:436)
at org.mule.api.processor.LoggerMessageProcessor.log(LoggerMessageProcessor.java:89)
at org.mule.api.processor.LoggerMessageProcessor.process(LoggerMessageProcessor.java:71)
at org.mule.execution.ExceptionToMessagingExceptionExecutionInterceptor.execute(ExceptionToMessagingExceptionExecutionInterceptor.java:27)
at org.mule.execution.MessageProcessorNotificationExecutionInterceptor.execute(MessageProcessorNotificationExecutionInterceptor.java:61)
at org.mule.execution.MessageProcessorExecutionTemplate.execute(MessageProcessorExecutionTemplate.java:47)
at org.mule.processor.chain.DefaultMessageProcessorChain.doProcess(DefaultMessageProcessorChain.java:95)
at org.mule.processor.chain.AbstractMessageProcessorChain.process(AbstractMessageProcessorChain.java:70)
at org.mule.execution.ExceptionToMessagingExceptionExecutionInterceptor.execute(ExceptionToMessagingExceptionExecutionInterceptor.java:27)
at org.mule.execution.MessageProcessorExecutionTemplate.execute(MessageProcessorExecutionTemplate.java:47)
at org.mule.processor.AbstractInterceptingMessageProcessorBase.processNext(AbstractInterceptingMessageProcessorBase.java:106)
at com.mulesoft.mule.module.datamapper.processors.DataMapperMessageProcessor.process(DataMapperMessageProcessor.java:132)
at org.mule.execution.ExceptionToMessagingExceptionExecutionInterceptor.execute(ExceptionToMessagingExceptionExecutionInterceptor.java:27)
at org.mule.execution.MessageProcessorNotificationExecutionInterceptor.execute(MessageProcessorNotificationExecutionInterceptor.java:61)
at org.mule.execution.MessageProcessorExecutionTemplate.execute(MessageProcessorExecutionTemplate.java:47)
at org.mule.processor.AbstractInterceptingMessageProcessorBase.processNext(AbstractInterceptingMessageProcessorBase.java:106)
at org.mule.interceptor.AbstractEnvelopeInterceptor.process(AbstractEnvelopeInterceptor.java:55)
at org.mule.processor.AsyncInterceptingMessageProcessor.processNextTimed(AsyncInterceptingMessageProcessor.java:122)
at org.mule.processor.AsyncInterceptingMessageProcessor$AsyncMessageProcessorWorker$1.process(AsyncInterceptingMessageProcessor.java:192)
at org.mule.processor.AsyncInterceptingMessageProcessor$AsyncMessageProcessorWorker$1.process(AsyncInterceptingMessageProcessor.java:185)
at org.mule.execution.ExecuteCallbackInterceptor.execute(ExecuteCallbackInterceptor.java:20)
at org.mule.execution.HandleExceptionInterceptor.execute(HandleExceptionInterceptor.java:34)
at org.mule.execution.HandleExceptionInterceptor.execute(HandleExceptionInterceptor.java:18)
at org.mule.execution.BeginAndResolveTransactionInterceptor.execute(BeginAndResolveTransactionInterceptor.java:58)
at org.mule.execution.ResolvePreviousTransactionInterceptor.execute(ResolvePreviousTransactionInterceptor.java:48)
at org.mule.execution.SuspendXaTransactionInterceptor.execute(SuspendXaTransactionInterceptor.java:54)
at org.mule.execution.ValidateTransactionalStateInterceptor.execute(ValidateTransactionalStateInterceptor.java:44)
at org.mule.execution.IsolateCurrentTransactionInterceptor.execute(IsolateCurrentTransactionInterceptor.java:44)
at org.mule.execution.ExternalTransactionInterceptor.execute(ExternalTransactionInterceptor.java:52)
at org.mule.execution.RethrowExceptionInterceptor.execute(RethrowExceptionInterceptor.java:32)
at org.mule.execution.RethrowExceptionInterceptor.execute(RethrowExceptionInterceptor.java:17)
at org.mule.execution.TransactionalErrorHandlingExecutionTemplate.execute(TransactionalErrorHandlingExecutionTemplate.java:113)
at org.mule.execution.TransactionalErrorHandlingExecutionTemplate.execute(TransactionalErrorHandlingExecutionTemplate.java:34)
at org.mule.processor.AsyncInterceptingMessageProcessor$AsyncMessageProcessorWorker.doRun(AsyncInterceptingMessageProcessor.java:184)
at org.mule.work.AbstractMuleEventWork.run(AbstractMuleEventWork.java:43)
at org.mule.work.WorkerContext.run(WorkerContext.java:311)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: org.mule.api.MuleRuntimeException: Failed to evaluate XPath expression: "/OrderIssueDate"
at org.mule.module.xml.expression.AbstractXPathExpressionEvaluator.evaluate(AbstractXPathExpressionEvaluator.java:144)
at org.mule.expression.DefaultExpressionManager.evaluate(DefaultExpressionManager.java:311)
at org.mule.expression.DefaultExpressionManager.evaluate(DefaultExpressionManager.java:230)
at org.mule.expression.DefaultExpressionManager.evaluate(DefaultExpressionManager.java:186)
at org.mule.module.xml.el.XPathFunction.call(XPathFunction.java:43)
... 60 more
Caused by: org.mule.api.transformer.TransformerException: Could not find a transformer to transform "SimpleDataType{type=java.util.LinkedHashMap, mimeType='*/*'}" to "SimpleDataType{type=org.dom4j.Document, mimeType='*/*'}".
at org.mule.registry.MuleRegistryHelper.lookupTransformer(MuleRegistryHelper.java:252)
at org.mule.DefaultMuleMessage.getPayload(DefaultMuleMessage.java:355)
at org.mule.DefaultMuleMessage.getPayload(DefaultMuleMessage.java:313)
at org.mule.module.xml.expression.AbstractXPathExpressionEvaluator.getPayloadForXPath(AbstractXPathExpressionEvaluator.java:154)
at org.mule.module.xml.expression.AbstractXPathExpressionEvaluator.evaluate(AbstractXPathExpressionEvaluator.java:115)
... 64 more
ERROR 2013-08-26 00:40:49,893 [[mule_egc2].EGC_FlowFlow1.stage1.02] org.mule.exception.DefaultMessagingExceptionStrategy:
********************************************************************************
Message : Could not find a transformer to transform "SimpleDataType{type=java.util.LinkedHashMap, mimeType='*/*'}" to "SimpleDataType{type=org.dom4j.Document, mimeType='*/*'}".
Code : MULE_ERROR-236
--------------------------------------------------------------------------------
Exception stack is:
1. Could not find a transformer to transform "SimpleDataType{type=java.util.LinkedHashMap, mimeType='*/*'}" to "SimpleDataType{type=org.dom4j.Document, mimeType='*/*'}". (org.mule.api.transformer.TransformerException)
org.mule.registry.MuleRegistryHelper:252 (http://www.mulesoft.org/docs/site/current3/apidocs/org/mule/api/transformer/TransformerException.html)
--------------------------------------------------------------------------------
Root Exception stack trace:
org.mule.api.transformer.TransformerException: Could not find a transformer to transform "SimpleDataType{type=java.util.LinkedHashMap, mimeType='*/*'}" to "SimpleDataType{type=org.dom4j.Document, mimeType='*/*'}".
at org.mule.registry.MuleRegistryHelper.lookupTransformer(MuleRegistryHelper.java:252)
at org.mule.DefaultMuleMessage.getPayload(DefaultMuleMessage.java:355)
at org.mule.DefaultMuleMessage.getPayload(DefaultMuleMessage.java:313)
+ 3 more (set debug level logging or '-Dmule.verbose.exceptions=true' for everything)
********************************************************************************

Use this:
<logger message="OrderIssueDate is #[xpath('//Order/OrderHeader/OrderIssueDate').text]" level="INFO" />
Make sure that to use the case correctly for your XML elements hierarchy. You have order in top XML while Order in lower one and so on

the xpath expression that would work according to me is #[xpath://orderissuedate] To print using the logger you should use something like <logger message="#[xpath://orderissuedate]" level="INFO"/>

From the conversation on one of the answers the following solutions hould work.
<logger message="Value of Order Issue Date #[xpath('//OrderIssueDate').text]" level="INFO" />
It would be better if the DTD of the Order is also provided.

Your original XML seems to have namespace :-
xmlns:core="rrn:org.xcbl:schemas/xcbl/v4_0/core/core.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
So, if you need to extract the value using Xpath from your original XML, you need Mule namespace manger :- https://developer.mulesoft.com/docs/display/current/XML+Namespaces
Other than that if you want to extract the value from your XML you shown above, you can use the Mules latest Xpath3 available right now from Mule version 3.6 which is easy to use :- https://developer.mulesoft.com/docs/display/current/XPath
Hope it helps you :)

You can use the mule latest xpath3 like this if you are getting namespaces
[xpath3('//*:orderissuedate/text()')]

Try this, it may help:
#[xpath3('//order/orderheader/orderissuedate/text()')]

Related

Mule 3.9 - Unable to fetch xml value using foreach of Xpath3 NODESET

I am unable to retrieve the XML values using the below code snippet in Mule 3.9.5 and it works with the lower versions. I am looking for the solutions in XPath using foreach only not splitter as per my use-case.
Mule flow XML
<foreach collection="#[xpath3('/ParentData/Data', payload, 'NODESET')]">
Sample XML
<ParentData>
<Data>
<test1>value1</test1>
<test2>value2</test2>
</Data>
<Data>
<test1>value1</test1>
<test2>value2</test2>
</Data>
</ParentData>
Actual Output
[]
Expected Output
<Data>
<test1>value1</test1>
<test2>value2</test2>
</Data>
<Data>
<test1>value1</test1>
<test2>value2</test2>
</Data>
Any suggestions ?
Using xpath3() returns a list of nodes of the XML implemented with Java class net.sf.saxon.dom.DOMNodeList. For some reason it doesn't print the details of each node in a <logger>.
I think it is clearer, more intuitive, better documented and portable to future versions of Mule to use DataWeave script instead.
Example:
<dw:transform-message doc:name="Transform Message">
<dw:input-payload mimeType="application/xml" />
<dw:set-variable variableName="data"><![CDATA[
%dw 1.0
%output application/java
---
payload.ParentData.*Data
]]>
</dw:set-variable>
</dw:transform-message>
<foreach collection="#[flowVars.data]" doc:name="For Each">
<logger message="Data=#[payload]" level="INFO" doc:name="Logger"/>
</foreach>
Output:
Data={test1=value1, test2=value2}
Data={test1=value1, test2=value2}
In Mule 4 you can use the DataWeave expression directly in the <foreach>.

Read value from XML within another XML: Mule

I am making a SOAP webservice call and I get the below response. I want to read the value in internal XML, the value is 12345684 in 1234684 in the below XML.
I was able to get internal XML using #[xpath3('//:processaResponse /return[2]')], store it in a flow variable and #[xpath3('/AckReg/DataArea/PRegistration/PRDet/Person/IDSet/:ID[#schemeName="aid"]/text()')].
This works when I try an online parser, but it doesn't read the value in Mule.
Is there any way to extract 1234684 in oa:ID tag using one XPath.
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Header>
<ns3:TXID xmlns:ns3="http://a.d.r.test.com/"></ns3:TXID>
<ns3:SESSIONID xmlns:ns3="http://a.d.r.test.com/"></ns3:SESSIONID>
</soapenv:Header>
<soapenv:Body>
<ns3:processaResponse xmlns:ns3="http://a.d.r.test.com/" xmlns:ns2="http://p.r.test.com/">
<return>Hi</return>
<return>
<?xml version="1.0" encoding="UTF-8"?>
<AckReg
xmlns="http://www.test.com/e/1" languageCode="en-US" releaseID="normalizedString" systemEnvironmentCode="test" versionID="normalizedString"
xmlns:oa="www.test.com/r/9"
xsi:schemaLocation="http://www.test.com/a/1 ../test/test.xsd">
<Apa>
<oa:CreationDateTime>2018-04-05</oa:CreationDateTime>
</Apa>
<DataArea>
<Ack>
<OArea>
<o:Sender>
<o:LID schemeAgencyName="testi" schemeName="Application ID">test</o:LID>
</o:Sender>
</OArea>
<OriginalActionVerb/>
</Ack>
<PRegistration>
<testids>
<IDSet schemeAgencyName="try">
<oa:ID schemeName="abcid">1234684</oa:ID>
</IDSet>
</testids>
<PRDet>
<Person>
<IDSet schemeAgencyName="try">
<oa:ID schemeName="aid">1364561</oa:ID>
</IDSet>
<IDSet schemeAgencyName="enada">
<oa:ID schemeName="Employee ID">adsad</oa:ID>
</IDSet>
</Person>
<User>
<oa:ID/>
</User>
</PRDet>
</PRegistration>
</DataArea>
</AckReg>
</return>
</ns3:processaResponse>
</soapenv:Body>
</soapenv:Envelope>
In your expressions you were missing namespace prefixes or namespace wildcards *: on some nodes - so your expressions failed.
Is there any way to extract 1234684 in oa:ID tag using one XPath.
Combining both of your partial expressions is possible with namespace wildcards:
//*:processaResponse/return[2]/*:AckReg/*:DataArea/*:PRegistration/*:testids/*:IDSet/*:ID[#schemeName='abcid']/text()
Or you can use an absolute path with namespace wildcards:
/*:Envelope/*:Body/*:processaResponse/return[2]/*:AckReg/*:DataArea/*:PRegistration/*:testids/*:IDSet/*:ID[#schemeName='abcid']/text()
Output in both cases:
1234684
You can even use XmlSlurper class using groovy script to fetch that respective value.
root = new XmlSlurper( false, true).parseText(payload).declareNamespace('soapenv':"http://schemas.xmlsoap.org/soap/envelope/")

xpath assertion for jdbc response

I have query which run in jdbc step in soapui which the result are:
<Results>
<ResultSet fetchSize="128">
<Row rowNumber="1">
<MODEL_ID>Deposit</MODEL_ID>
<VALUE1>1</VALUE1>
<VALUE2/>
<VALUE_SET/>
<SCORE>1.00</SCORE>
</Row>
<Row rowNumber="2">
<MODEL_ID>Deposit</MODEL_ID>
<VALUE1>2</VALUE1>
<VALUE2/>
<VALUE_SET/>
<SCORE>2.00</SCORE>
</Row>
I want to assert the MODEL_ID under rowNumber="2".
I used this XPath expression: //*:Results/ResultSet/rowNumber="2"/MODEL_ID
I got the following error:
Runtimeexception: Required item type of first operand of '/' is node ();supplied value has item type es:string
//*:Results/ResultSet/Row[#rowNumber="2"]/MODEL_ID
The *:Results part looks a bit suspicious... are namespaces involved?
checked: //Results/ResultSet/Row[2]/MODEL_ID

Syntax for release-strategy-expression in spring integration

Here is the code snippet of what is expected:
<int:resequencer input-channel="resequencerChannel" output-channel="headerRoutingChannel"
send-timeout="10000" release-strategy-expression="size() eq (T(java.lang.Runtime).getRuntime().availableProcessors() * 3)"/>
But the syntax seems to be incorrect. I would like to know the actual syntax for the release-strategy-expression.
Thanks in advance.
Stack Trace:
Caused by: org.springframework.expression.spel.SpelEvaluationException: EL1005E:(pos 8): Type cannot be found 'org.springframework.util.Assert'
at org.springframework.expression.spel.support.StandardTypeLocator.findType(StandardTypeLocator.java:115)
at org.springframework.expression.spel.ExpressionState.findType(ExpressionState.java:138)
at org.springframework.expression.spel.ast.TypeReference.getValueInternal(TypeReference.java:58)
at org.springframework.expression.spel.ast.CompoundExpression.getValueRef(CompoundExpression.java:48)
at org.springframework.expression.spel.ast.CompoundExpression.getValueInternal(CompoundExpression.java:84)
at org.springframework.expression.spel.ast.Ternary.getValueInternal(Ternary.java:57)
at org.springframework.expression.spel.ast.MethodReference.getArguments(MethodReference.java:147)
at org.springframework.expression.spel.ast.MethodReference.getValueRef(MethodReference.java:66)
at org.springframework.expression.spel.ast.CompoundExpression.getValueRef(CompoundExpression.java:63)
at org.springframework.expression.spel.ast.CompoundExpression.getValueInternal(CompoundExpression.java:84)
at org.springframework.expression.spel.ast.SpelNodeImpl.getTypedValue(SpelNodeImpl.java:114)
at org.springframework.expression.spel.standard.SpelExpression.getValue(SpelExpression.java:111)
at org.springframework.integration.util.AbstractExpressionEvaluator.evaluateExpression(AbstractExpressionEvaluator.java:144)
at org.springframework.integration.util.MessagingMethodInvokerHelper.processInternal(MessagingMethodInvokerHelper.java:268)
at org.springframework.integration.util.MessagingMethodInvokerHelper.process(MessagingMethodInvokerHelper.java:142)
at org.springframework.integration.handler.MethodInvokingMessageProcessor.processMessage(MethodInvokingMessageProcessor.java:73)
If you are trying to release when the group size reaches 3x the available processors...
size() eq ... ?

Xmllint using XSD+XMLCatalog cannot find uri

I am trying to use xmllint with an XSD file that uses one xs:import without the #schemaLocation attrib set. (In OxygenXMLEditor this setup is working fine)
XSD relevant section:
...
<!-- this one is the trouble -->
<xs:import namespace="http://www.w3.org/1999/xhtml" />
<!-- this one is resolved fine -->
<xs:import namespace="http://www.idpf.org/2007/ops" schemaLocation="conf/b.xsd"/>
...
Given this XML Catalog file:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE catalog PUBLIC "-//OASIS//DTD XML Catalogs V1.1//EN" "http://www.oasis-open.org/committees/entity/release/1.1/catalog.dtd">
<catalog xmlns="urn:oasis:names:tc:entity:xmlns:xml:catalog">
<uri name="http://www.w3.org/1999/xhtml" uri="file:///home/me/code/base5html.xsd"/>
</catalog>
Ok, then I run it:
$ export XML_CATALOG_FILES=~/code/mycatalog.xml
$ export XML_DEBUG_CATALOG=1
$ xmllint --load-trace --noout --schema myschema.xsd test_doc.xml
Result (approx):
Loaded URL="myschema.xsd" ID="(null)"
Loaded URL="conf/b.xsd" ID="(null)"
Loaded URL="c.xsd" ID="(null)"
c.xsd:17: element element: Schemas parser error : Element '{http://www.w3.org/2001/XMLSchema}element', attribute 'ref': The QName value '{http://www.w3.org/1999/xhtml}p' does not resolve to a(n) element declaration.
c.xsd:18: element element: Schemas parser error : Element '{http://www.w3.org/2001/XMLSchema}element', attribute 'ref': The QName value '{http://www.w3.org/1999/xhtml}cite' does not resolve to a(n) element declaration.
c.xsd:26: element attributeGroup: Schemas parser error : Element '{http://www.w3.org/2001/XMLSchema}attributeGroup', attribute 'ref': The QName value '{http://www.w3.org/1999/xhtml}normAttrGrp' does not resolve to a(n) attribute group definition.
...
(more taken out)
...
WXS schema public/ctrl/lov.xsd failed to compile
Loaded URL="myschema.xml" ID="(null)"
Q: Isn't XSD+XMLCat a supported feature in libxml2 ?
( No hints to be found anywhere on the homepage : http://xmlsoft.org/catalog.html )

Resources