2014-11-16 30 views
1

使用XPath函數我有一個輸入SOAP XML如下: -如何在騾

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:v1="http://services.test.com/schema/MainData/V1"> 
    <soapenv:Header> 
    </soapenv:Header> 
    <soapenv:Body> 
     <v1:retrieveDataRequest> 
     <v1:Id>662</v1:Id> 
     </v1:retrieveDataRequest> 
    </soapenv:Body> 
</soapenv:Envelope> 

現在我的問題很簡單...

我怎麼可以像使用計數)XPath函數(,名字(),子()等在騾子

我想在像下面這樣的SOAP請求使用XPath: -

<logger message="#[xpath('count(//v1:retrieveDataRequest/v1:Id)')]" level="INFO" doc:name="Logger"/> 

乙UT斯達康它拋出以下異常: -

Exception stack is: 
1. No Such Function {http://www.mulesoft.org/schema/mule/core}:count (org.jaxen.UnresolvableException) 
    org.jaxen.SimpleFunctionContext:127 (null) 
2. Failed to evaluate XPath expression: "count(//v1:retrieveDataRequest/v1:Id)" (org.mule.api.MuleRuntimeException) 
    org.mule.module.xml.expression.AbstractXPathExpressionEvaluator:141 (http://www.mulesoft.org/docs/site/current3/apidocs/org/mule/api/MuleRuntimeException.html) 
3. org.mule.api.MuleRuntimeException: Failed to evaluate XPath expression: "count(//v1:retrieveDataRequest/v1:Id)" (java.lang.RuntimeException) 
    org.mule.module.xml.el.XPathFunction:70 (null) 
4. [Error: org.mule.api.MuleRuntimeException: Failed to evaluate XPath expression: "count(//v1:retrieveDataRequest/v1:Id)"] 
[Near : {... xpath('count(//v1:retrieveData ....}] 
      ^
[Line: 1, Column: 1] (org.mule.mvel2.CompileException) 
    org.mule.mvel2.optimizers.impl.refl.ReflectiveAccessorOptimizer:437 (http://www.mulesoft.org/docs/site/current3/apidocs/org/mule/mvel2/CompileException.html) 
5. Execution of the expression "xpath('count(//v1:retrieveDataRequest/v1:Id)')" failed. (org.mule.api.expression.ExpressionRuntimeException) 
    org.mule.el.mvel.MVELExpressionLanguage:202 (http://www.mulesoft.org/docs/site/current3/apidocs/org/mule/api/expression/ExpressionRuntimeException.html) 
6. Execution of the expression "xpath('count(//v1:retrieveDataRequest/v1:Id)')" failed. (org.mule.api.expression.ExpressionRuntimeException). Message payload is of type: String (org.mule.api.MessagingException) 
    org.mule.execution.ExceptionToMessagingExceptionExecutionInterceptor:32 (http://www.mulesoft.org/docs/site/current3/apidocs/org/mule/api/MessagingException.html) 
-------------------------------------------------------------------------------- 
Root Exception stack trace: 
org.jaxen.UnresolvableException: No Such Function {http://www.mulesoft.org/schema/mule/core}:count 
    at org.jaxen.SimpleFunctionContext.getFunction(SimpleFunctionContext.java:127) 
    at org.jaxen.ContextSupport.getFunction(ContextSupport.java:242) 
    at org.jaxen.Context.getFunction(Context.java:216) 
    + 3 more (set debug level logging or '-Dmule.verbose.exceptions=true' for everything) 

請注意: - 我已經使用騾命名空間經理如下: -

<mulexml:namespace-manager includeConfigNamespaces="true"> 
    <mulexml:namespace prefix="soapenv" uri="http://schemas.xmlsoap.org/soap/envelope/"/> 
    <mulexml:namespace prefix="v1" uri="http://services.test.com/schema/MainData/V1"/> 
</mulexml:namespace-manager> 

和我得到結果如下: - <logger message="#[xpath('//v1:retrieveDataRequest/v1:Id').text]" level="INFO" doc:name="Logger"/>

請幫忙

回答

3

相關位o F中的異常,你可以上面沒有示出,爲:

 
Root Exception stack trace: 
org.jaxen.UnresolvableException: No Such Function {http://www.mulesoft.org/schema/mule/core}:count 
at org.jaxen.SimpleFunctionContext.getFunction(SimpleFunctionContext.java:127) 
at org.jaxen.ContextSupport.getFunction(ContextSupport.java:242) 
at org.jaxen.Context.getFunction(Context.java:216) 
    + 3 more (set debug level logging or '-Dmule.verbose.exceptions=true' for everything) 

正如可以看到的,count XPath函數在騾命名空間進行評價。這是在您的namespace-manager中使用includeConfigNamespaces="true"的副作用。您似乎不需要Mule命名空間來評估您的XPath(您在SOAP消息中沒有使用任何Mule命名空間),因此您應該將此值設置爲false。

這將固定在騾3.6,每MULE-7030

+0

太好了...謝謝大衛......我已經更新了這個問題,除了例外 –

1

所以,按照大衛的建議..最後的工作解決方法是設置includeConfigNamespaces="false": -

<mulexml:namespace-manager includeConfigNamespaces="false"> 
    <mulexml:namespace prefix="soapenv" uri="http://schemas.xmlsoap.org/soap/envelope/"/> 
    <mulexml:namespace prefix="v1" uri="http://services.test.com/schema/MainData/V1"/> 
</mulexml:namespace-manager> 

所以,現在,我可以像使用count() XPATH功能沒有任何問題,現在: -

<logger message="#[xpath('count(//v1:retrieveDataRequest/v1:Id)')]" level="INFO" doc:name="Logger"/>