MULE:xpath表达式未从有效载荷中提取值 [英] MULE: xpath expression not extracting values from payload

查看:56
本文介绍了MULE:xpath表达式未从有效载荷中提取值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的流程,它接收一条XML消息,将其拆分为子元素,现在我试图获取一个值,但是得到了意外的结果.

I've got a simple flow, it takes an XML messages, splits it into sub elements and now I am trying to get a value, but getting unexpected results.

我的XML如下:

<?xml version="1.0" encoding="UTF-8" ?>
<ns0:RewardOfferDetail xmlns:ns0="http://example.com/schemas/v1_0/RewardOffer">
  <ns0:Offer>
    <ns0:OperationCode>U</ns0:OperationCode>
  </ns0:Offer>
  <ns0:Offer>
    <ns0:OperationCode>A</ns0:OperationCode>
  </ns0:Offer>
</ns0:RewardOfferDetail>

我需要从每个<Offer>

该拆分工作正常,当我在拆分后注销有效负载时,它是一个<Offer>很好.但是我尝试使用以下方法提取<OperationCode>的值:

The split works fine, and when I log out the payload after the split, it is a <Offer> just fine. but then I try to extract the value of <OperationCode> using this:

#[xpath('/rewardsns:Offer/rewardns:OperationCode')]

我什么也没得到,只是一个空值,然后尝试使用更广泛的xpath表达式:

I get nothing, just a null value, then I try using a broader xpath expression:

#[xpath('//rewardns:OperationCode')]

结果是两个节点,这使我相信xpath函数没有找到正确的位置.但我什至试图告诉它在哪里看,仍然没有运气.

And the result is two nodes, which leads me to believe that the xpath function is not looking at the right spot. but I've even trying telling it where to look and still no luck.

#[xpath('//rewardns:OperationCode', message.payload)]
#[xpath('//rewardns:OperationCode', payload)]

仍然产生两个节点.

有什么建议吗?

    <flow name="receiveMessageFlow">
    <jms:inbound-endpoint
        queue="#{loyaltySettings.getString('loyalty.queue.receive')}"
        connector-ref="jmsConnector" doc:name="Loyalty Queue" />

    <message-filter doc:name="XSD Validation" onUnaccepted="invalidXmlMessage">
        <filter ref="schemaValidation" />
    </message-filter>

    <splitter expression="#[xpath('/rewardns:RewardOfferDetail/rewardns:Offer')]" doc:name="Split Message" />

    <set-variable variableName="action" value="#[xpath('//rewardns:OperationCode')]" doc:name="Save Action Code"/>

    <logger message="Action is: '#[flowVars.action]'" level="WARN" doc:name="Log Action Code"/>

13:53:39,653 DEBUG [org.mule.transport.jms.MultiConsumerJmsMessageReceiver] (TIBCO EMS Session Dispatcher (741)) Message received it is of type: TibjmsTextMessage
13:53:39,653 DEBUG [org.mule.transport.jms.MultiConsumerJmsMessageReceiver] (TIBCO EMS Session Dispatcher (741)) Message received on Queue[M.ESS.ITM.LOYALTY.STARS.ItemMaint] (com.tibco.tibjms.TibjmsQueue)
13:53:39,653 DEBUG [org.mule.transport.jms.MultiConsumerJmsMessageReceiver] (TIBCO EMS Session Dispatcher (741)) Message CorrelationId is: 
13:53:39,653 DEBUG [org.mule.transport.jms.MultiConsumerJmsMessageReceiver] (TIBCO EMS Session Dispatcher (741)) Jms Message Id is: ID:EMS-SERVER.A305502CE7A4:995
13:53:39,653 DEBUG [org.mule.transport.jms.transformers.JMSMessageToObject] (TIBCO EMS Session Dispatcher (741)) Applying transformer JMSMessageToObject#218219976 (org.mule.transport.jms.transformers.JMSMessageToObject)
13:53:39,653 DEBUG [org.mule.transport.jms.transformers.JMSMessageToObject] (TIBCO EMS Session Dispatcher (741)) Object before transform: 
org.mule.DefaultMuleMessage
{
  id=998d2f50-13a0-11e5-b0f9-ac87a31af20c
  payload=com.tibco.tibjms.TibjmsTextMessage
  correlationId=
  correlationGroup=-1
  correlationSeq=-1
  encoding=UTF-8
  exceptionPayload=<not set>

Message properties:
  INVOCATION scoped properties:
  INBOUND scoped properties:
    JMSCorrelationID=
    JMSDeliveryMode=1
    JMSDestination=Queue[M.ESS.ITM.LOYALTY.STARS.ItemMaint]
    JMSExpiration=0
    JMSMessageID=ID:EMS-SERVER.A305502CE7A4:995
    JMSPriority=4
    JMSRedelivered=false
    JMSTimestamp=1426256459016
    JMSType=
    MULE_CORRELATION_ID=
    MULE_MESSAGE_ID=ID:EMS-SERVER.A305502CE7A4:995
  OUTBOUND scoped properties:
    MULE_ENCODING=UTF-8
  SESSION scoped properties:
}
13:53:39,654 DEBUG [org.mule.transport.jms.transformers.JMSMessageToObject] (TIBCO EMS Session Dispatcher (741)) Source object is TibjmsTextMessage
13:53:39,654 DEBUG [org.mule.transport.jms.transformers.JMSMessageToObject] (TIBCO EMS Session Dispatcher (741)) Message type received is: TibjmsTextMessage
13:53:39,654 DEBUG [org.mule.transport.jms.transformers.JMSMessageToObject] (TIBCO EMS Session Dispatcher (741)) Resulting object is String
13:53:39,654 DEBUG [org.mule.transport.jms.transformers.JMSMessageToObject] (TIBCO EMS Session Dispatcher (741)) Object after transform: <?xml version="1.0" encoding="UTF-8" ?>
<ns0:RewardOfferDetail xmlns:ns0="http://example.com/schemas/v1_0/RewardOffer">
  <ns0:Offer>
    <ns0:OperationCode>U</ns0:OperationCode>
  </ns0:Offer>
  <ns0:Offer>
    <ns0:OperationCode>A</ns0:OperationCode>
  </ns0:Offer>
</ns0:RewardOfferDetail>
13:53:39,654 DEBUG [org.mule.transport.jms.transformers.JMSMessageToObject] (TIBCO EMS Session Dispatcher (741)) The transformed object is of expected type. Type is: String
13:53:39,669 DEBUG [org.mule.expression.DefaultExpressionManager] ([loyalty-nebula].receiveMessageFlow.stage1.02) Result of expression: xpath-branch:/rewardns:RewardOfferDetail/rewardns:Offer is: [[ns0:Offer: null], [ns0:Offer: null]]
13:53:39,669 DEBUG [org.mule.processor.chain.DefaultMessageProcessorChain] ([loyalty-nebula].receiveMessageFlow.stage1.02) Invoking DefaultMessageProcessorChain '(inner iterating chain) of 'receiveMessageFlow' processor chain' 
[ 
  AddFlowVariableTransformer{this=589f1380, name='AddFlowVariableTransformer', ignoreBadInput=false, returnClass=SimpleDataType{type=java.lang.Object, mimeType='*/*'}, sourceTypes=[SimpleDataType{type=java.lang.Object, mimeType='*/*'}]}, 
  org.mule.api.processor.LoggerMessageProcessor@be3c4ce, 
  org.mule.routing.requestreply.AsyncReplyToPropertyRequestReplyReplier
] with event MuleEvent: 0-998d2f53-13a0-11e5-b0f9-ac87a31af20c, stop processing=false, jms://M.ESS.ITM.LOYALTY.STARS.ItemMaint
13:53:39,669 DEBUG [org.mule.transformer.simple.AddFlowVariableTransformer] ([loyalty-nebula].receiveMessageFlow.stage1.02) Applying transformer AddFlowVariableTransformer (org.mule.transformer.simple.AddFlowVariableTransformer)
13:53:39,670 DEBUG [org.mule.transformer.simple.AddFlowVariableTransformer] ([loyalty-nebula].receiveMessageFlow.stage1.02) Object before transform: 
org.mule.DefaultMuleMessage
{
  id=998fa050-13a0-11e5-b0f9-ac87a31af20c
  payload=org.apache.xerces.dom.ElementNSImpl
  correlationId=<not set>
  correlationGroup=2
  correlationSeq=1
  encoding=UTF-8
  exceptionPayload=<not set>

Message properties:
  INVOCATION scoped properties:
  INBOUND scoped properties:
  OUTBOUND scoped properties:
    MULE_CORRELATION_GROUP_SIZE=2
    MULE_CORRELATION_SEQUENCE=1
    MULE_ENCODING=UTF-8
  SESSION scoped properties:
}
13:53:39,670 DEBUG [org.mule.expression.DefaultExpressionManager] ([loyalty-nebula].receiveMessageFlow.stage1.02) Result of expression: xpath-branch://rewardns:OperationCode is: [[ns0:OperationCode: null], [ns0:OperationCode: null]]
13:53:39,670 DEBUG [org.mule.transformer.simple.AddFlowVariableTransformer] ([loyalty-nebula].receiveMessageFlow.stage1.02) Object after transform: 
org.mule.DefaultMuleMessage
{
  id=998fa050-13a0-11e5-b0f9-ac87a31af20c
  payload=org.apache.xerces.dom.ElementNSImpl
  correlationId=<not set>
  correlationGroup=2
  correlationSeq=1
  encoding=UTF-8
  exceptionPayload=<not set>

Message properties:
  INVOCATION scoped properties:
    action=[[ns0:OperationCode: null], [ns0:OperationCode: null]]
  INBOUND scoped properties:
  OUTBOUND scoped properties:
    MULE_CORRELATION_GROUP_SIZE=2
    MULE_CORRELATION_SEQUENCE=1
    MULE_ENCODING=UTF-8
  SESSION scoped properties:
}
13:53:39,671 DEBUG [org.mule.transformer.simple.AddFlowVariableTransformer] ([loyalty-nebula].receiveMessageFlow.stage1.02) The transformed object is of expected type. Type is: DefaultMuleMessage
13:53:39,672 WARN  [org.mule.api.processor.LoggerMessageProcessor] ([loyalty-nebula].receiveMessageFlow.stage1.02) Action is: '[[ns0:OperationCode: null], [ns0:OperationCode: null]]'

推荐答案

这似乎可行

    xpath('./rewardns:OperationCode')

根据@David的解释,似乎xpath仍然可以访问整个文档中的元素.解决此问题的一种方法是在表达式中使用./锚定函数以将当前节点用作起点.

From what @David was explaining it seems that xpath can still access elements throughout the entire document. A way to get around this was to use a ./ in the expression to anchor the function to use the current node as a starting point.

因此最终组件如下所示:

So the final component looks like this:

    <set-variable variableName="action" value="#[xpath('./rewardns:OperationCode').getFirstChild().getNodeValue()]" doc:name="Save Action Code"/>

这篇关于MULE:xpath表达式未从有效载荷中提取值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆