Announcement Announcement Module
No announcement yet.
Help on xpath-expression Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Help on xpath-expression


    I am trying to use xpath-expression to select a node (to enrich a header with it) from an XML document passed as a payload in SI, my xpath-expression varies according to the a type value in the header of the message, so I have created a map of expressions

    <util:map id="expressionsMap">
    <entry key="A" value="/a/b/c/@d"/>
    <entry key="B" value="/a/x/y/@f"/>
    <entry key="C" value="/a/w/d/@g"/>

    <int-xml:xpath-expression expression="#{expressionsMap[headers.type]}"

    <int-xml:header name="Id" xpath-expression-ref="IdExpression"/>

    I am getting an error below, I understand that the #{} is static initializer and headers is a runtime property, I am also aware that I can resolve the issue by creating a header-router and route to different xpath-header-enricher, I just feel that this is a better solution and if SI has support to such thing?

    ERROR: org.springframework.web.servlet.DispatcherServlet - Context initialization failed
    org.springframework.beans.factory.BeanExpressionEx ception: Expression parsing failed; nested exception is org.springframework.expression.spel.SpelEvaluation Exception: EL1008Epos 14): Field or property 'headers' cannot be found on object of type 'org.springframework.beans.factory.config.BeanExpr essionContext'
    at org.springframework.context.expression.StandardBea nExpressionResolver.evaluate(StandardBeanExpressio
    at BeanFactory.evaluateBeanDefinitionString(AbstractB
    at nitionValueResolver.evaluate(BeanDefinitionValueRe
    at nitionValueResolver.resolveValueIfNecessary(BeanDe

  • #2

    What you want is realy some hybrid dinamic routing.
    I really recommend to do:
    creating a header-router and route to different xpath-header-enricher
    Or you can try to use some relatively simple workaround:
    HTML Code:
    <bean id="nodeConverter" class="org.springframework.integration.xml.DefaultXmlPayloadConverter"/>
    <util:constant id="evaluationType" static-field="org.springframework.integration.xml.xpath.XPathEvaluationType.STRING_RESULT"/>
      <header name="Id"
               expression="@evaluationType.evaluateXPath(T (org.springframework.xml.xpath.XPathExpressionFactory)
                 .createXPathExpression(@expressionsMap[headers.type], @namespacesMap), @nodeConverter.convertToNode(payload))"/>
    I didn't check it, but just look how it is looks a bit a bit confusing.

    Artem Bilan