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

  • Help on xpath-expression

    Hello,

    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"/>
    </util:map>

    <int-xml:xpath-expression expression="#{expressionsMap[headers.type]}"
    namespace-map="namespacesMap"
    id="IdExpression">

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

    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 nResolver.java:141)
    at org.springframework.beans.factory.support.Abstract BeanFactory.evaluateBeanDefinitionString(AbstractB eanFactory.java:1298)
    at org.springframework.beans.factory.support.BeanDefi nitionValueResolver.evaluate(BeanDefinitionValueRe solver.java:224)
    at org.springframework.beans.factory.support.BeanDefi nitionValueResolver.resolveValueIfNecessary(BeanDe finitionValueResolver.java:

  • #2
    Hello

    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-enricher>
      <header name="Id"
               expression="@evaluationType.evaluateXPath(T (org.springframework.xml.xpath.XPathExpressionFactory)
                 .createXPathExpression(@expressionsMap[headers.type], @namespacesMap), @nodeConverter.convertToNode(payload))"/>
    </header-enricher>
    I didn't check it, but just look how it is looks a bit a bit confusing.

    Cheers,
    Artem Bilan

    Comment

    Working...
    X