gnanagurus
gnanagurus

Reputation: 903

WSO2 aggregator - xpath couldnt traverse

I have this proxy service to aggregate two xml messages into one.

  1. I have configured my aggregator class with xpath
  2. I am not sure whether my xpath with namespace works. I couldnt trace with logs.

My proxy configuration:

<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse"
       name="prescription"
       transports="https http jms"
       startOnLoad="true"
       trace="disable">
   <description/>
   <target>
      <inSequence>
         <aggregate>
            <completeCondition>
               <messageCount min="2" max="2"/>
            </completeCondition>
            <onComplete expression="//soapenv:Envelope//f:Prescription//f:identifier//f:id//@value">

               <send>
                  <endpoint>
                     <address uri="jms:/report?transport.jms.ConnectionFactoryJNDIName=QueueConnectionFactory&amp;java.naming.factory.initial=org.apache.activemq.jndi.ActiveMQInitialContextFactory&amp;java.naming.provider.url=tcp://localhost:61616"/>
                  </endpoint>
               </send>

            </onComplete>
         </aggregate>

      </inSequence>
      <outSequence>
         <drop/>
      </outSequence>
      <faultSequence/>
   </target>
   <parameter name="transport.jms.ContentType">
      <rules>
         <jmsProperty>contentType</jmsProperty>
         <default>application/xml</default>
      </rules>
   </parameter>
</proxy>

My input messages looks like this: ( I want to aggregate based on the patient id )

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ws="http://isova.wipro.com/">


<Prescription xmlns="http://hl7.org/fhir">
  <identifier>
    <id value="A0001"/>
  </identifier>
  <status value="active"/>
  <patient>
    <type value="Patient"/>
    <url value="Bhavani"/>
  </patient>
  <prescriber>
    <type value="Provider"/>
    <url value="Dr.Mathews"/>
  </prescriber>
  <medicine>
    <identification>
      <text value="Zintac"/>
    </identification>
  </medicine>
</Prescription></soapenv:Envelope>

Any suggestions ?

Regards Guru @gnanagurus


I couldnt help to solve this issue. This is my latest WSO2 proxy.

These are the two messages exist in'Prescription' queue.

Message1:

<?xml version='1.0' encoding='UTF-8'?><soapenv:Envelope xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope"><soapenv:Body><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ws="http://isova.wipro.com/">


<Prescription xmlns="http://hl7.org/fhir">
  <identifier>
    <id value="A0001"/>
  </identifier>
  <status value="active"/>
  <patient>
    <type value="Patient"/>
    <url value="Bhavani"/>
  </patient>
  <prescriber>
    <type value="Provider"/>
    <url value="Dr.Mathews"/>
  </prescriber>
  <medicine>
    <identification>
      <text value="Zintac"/>
    </identification>
  </medicine>
</Prescription></soapenv:Envelope></soapenv:Body></soapenv:Envelope>

Message 2:

<?xml version='1.0' encoding='UTF-8'?><soapenv:Envelope xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope"><soapenv:Body><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ws="http://isova.wipro.com/">


<Prescription xmlns="http://hl7.org/fhir">
  <identifier>
    <id value="A0001"/>
  </identifier>
  <status value="active"/>
  <patient>
    <type value="Patient"/>
    <url value="Bhavani"/>
  </patient>
  <prescriber>
    <type value="Provider"/>
    <url value="Dr.John"/>
  </prescriber>
  <medicine>
    <identification>
      <text value="tintac"/>
    </identification>
  </medicine>
</Prescription></soapenv:Envelope></soapenv:Body></soapenv:Envelope>

Proxy:

<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse"
       name="prescription"
       transports="https http jms"
       startOnLoad="true"
       trace="disable">
   <description/>
   <target>
      <inSequence>


         <aggregate>  
                <completeCondition>  
                    <messageCount min="2"/>  
                </completeCondition>  
                <onComplete expression="/Prescription">  
                <send>
                  <endpoint>
                     <address uri="jms:/report?transport.jms.ConnectionFactoryJNDIName=QueueConnectionFactory&amp;java.naming.factory.initial=org.apache.activemq.jndi.ActiveMQInitialContextFactory&amp;java.naming.provider.url=tcp://localhost:61616"/>
                  </endpoint>
               </send>
                </onComplete>  
            </aggregate>  
      </inSequence>
      <outSequence>
         <drop/>
      </outSequence>
      <faultSequence/>
   </target>
   <parameter name="transport.jms.ContentType">
      <rules>
         <jmsProperty>contentType</jmsProperty>
         <default>application/xml</default>
      </rules>
   </parameter>
</proxy>

This is not solving my aggregation. These two messages are not getting aggregator. I tried with multiple xpath with namespaces. Anyhelp is greatly needed.

Is there any WSO2 Aggregator custom java class which I can use instead of aggregate mediator ?

Regards Guru

Upvotes: 1

Views: 455

Answers (3)

Isuru Udana
Isuru Udana

Reputation: 281

What you are doing is not logically correct. You cannot aggregate messages at inSequence without having a iterate mediator placed at inSequence. There is a correlation between the Clone/Iterate and Aggregate mediator. You can only aggregate messages which are split or cloned within the same Proxy service.

Upvotes: 1

Subash Chaturanga
Subash Chaturanga

Reputation: 834

Your XPATH is wrong since you are not defining your namespaces.

I believe you are dealing with SOAP messages. If so did you copy the exact message above. I cannot see the SOAP body ? What you should be doing is enrich your xml payload into SOAP body and aggrgate them from the aggrgate mediator. There you only need to give XPATH considering SOAP body as the root. In your case it should be

<onComplete xmlns:f="http://hl7.org/fhir" expression="//f:Prescription/f:identifier/f:id/text()"> 

Upvotes: 1

Philipp
Philipp

Reputation: 4749

Yes you need to define the namespace f. You can do that directly at the beginning:

<proxy xmlns="http://ws.apache.org/ns/synapse" xmlns:f="http://hl7.org/fhir"

Then you can of course make log outputs to verify your xpath expressions (very useful):

<log level="custom">
   <property name="yourXPathTest" expression="$body/f:Prescription/f:identifier/f:id/@value"/>
</log>

Upvotes: 3

Related Questions