You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@synapse.apache.org by Bill Harts <bi...@hartsandco.com> on 2009/06/10 13:40:56 UTC

XPath doesn't return attribute value

 Hi all:

Since I'm new to Synapse and Axis2 I apologize in advance if I have missed
something here and report something that isn't actually broken.

*Problem:*
An XPath expression in my synapse.xml configuration file is unable to
retrieve an XML attribute from a message.  Example:

<log level="custom">
  <property name="sessID"
expression="//cfl:LoginResponse/cfl:LoginResponseData/@sessionID"
xmlns:cfl="http:www.test.com/cfl" />
</log>

The message body is:
 <soapenv:Body>
  <cfl:LoginResponse xmlns:cfl="http://www.test.com/cfl">
   <cfl:LoginResponseData sessionID="250446AD43C0EEF3ED2F3172F8FA0A3D"
statusCode="0"/>
  </cfl:LoginResponse>
 </soapenv:Body>

In this case the log mediator always returns null for the sessID variable.

*Cause:*
After poking around in a bunch of modules I believe that these XPath
expressions are being handled in module synapseXPath.java.  Specifically
there is a call in stringValueOf(MessageContext synCtx) to
BaseXPath.evaluate() which returns a List of element pointers retrieved by
the XPath expression.  The function then correctly checks each element to to
determine if it is of type OMTextImpl, OMElementImpl or OMDocumentImpl but
when an attribute has been found evaluate() returns an attribute of type
DocumentNavigator$OMAttributeEx.  It appears that there is no code in
stringValueOf() to handle this type of pointer.

*Solution:*
I added the following code to synapseXpath.java::stringValueOf at line 206:

                    ...
                    } else if (o instanceof OMAttributeEx) {
                        textValue.append(
((OMAttributeEx)o).getAttributeValue());
                   }
                   ...

Also, since the type OMAttributeEx is an inner class of type
DocumentNavigator I needed to add an import statement in SynapseXPath.java:

import org.apache.axiom.om.xpath.DocumentNavigator.OMAttributeEx;

Unfortunately, OMAtributeEx is defined as private to class DocumentNavigator
so I had to declare class and constructor OMAttributeEx as public in the
module DocumentNavigator.java in the Axiom project module axiom-api.jar.

If someone can point me to instructions for how to create a patch I will
post one here.

Thanks,
Bill

Re: XPath doesn't return attribute value

Posted by "Asankha C. Perera" <as...@apache.org>.
Hi Andreas
> Asankha,
>
> What is actually the reason for having our own stringValueOf method
> and not relying on the stringValueOf method of BaseXPath?
>   
I checked in the history of SVN, but I cannot seem to locate the origin 
of the method to trace back.. however, the BaseXPath method is defined as:

"/The string-value of the expression is determined per the string(..) 
core function defined in the XPath specification. This means that an 
expression that selects zero nodes will return the empty string, while 
an expression that selects one-or-more nodes will return the 
string-value of the first node./"

In the overridden case, we create the String representation as the 
concatenation of the text values of multi-node results. I think that is 
useful to check for existence of a value etc

cheers
asankha

-- 
Asankha C. Perera
AdroitLogic, http://adroitlogic.org

http://esbmagic.blogspot.com





Re: XPath doesn't return attribute value

Posted by Andreas Veithen <an...@gmail.com>.
Asankha,

What is actually the reason for having our own stringValueOf method
and not relying on the stringValueOf method of BaseXPath?

Andreas

On Wed, Jun 10, 2009 at 17:09, Asankha C. Perera<as...@apache.org> wrote:
> Hi Bill
>
> <log level="custom">
>   <property name="sessID"
> expression="//cfl:LoginResponse/cfl:LoginResponseData/@sessionID"
> xmlns:cfl="http:www.test.com/cfl" />
> </log>
>
> The message body is:
>  <soapenv:Body>
>   <cfl:LoginResponse xmlns:cfl="http://www.test.com/cfl">
>    <cfl:LoginResponseData sessionID="250446AD43C0EEF3ED2F3172F8FA0A3D"
> statusCode="0"/>
>   </cfl:LoginResponse>
>  </soapenv:Body>
>
> The namespaces in the log mediator for cfl is "http:..." (note the missing
> "//") and is thus different from what you see in the message.. was this a
> mistake?
>
> cheers
> asankha
>
> --
> Asankha C. Perera
> AdroitLogic, http://adroitlogic.org
>
> http://esbmagic.blogspot.com
>
>
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@synapse.apache.org
For additional commands, e-mail: dev-help@synapse.apache.org


Re: XPath doesn't return attribute value

Posted by Bill Harts <pr...@gmail.com>.
Sorry, I just typed it wrong in my email, it should have the 2 slashes. The
bug still exists as described.  You can verify by putting a breakpoint
inside SynapseXPath and watching as it iterates over the returned List
objects.

Thanks,
Bill

On Wed, Jun 10, 2009 at 11:09 AM, Asankha C. Perera <as...@apache.org>wrote:

>  Hi Bill
>
> <log level="custom">
>   <property name="sessID"
> expression="//cfl:LoginResponse/cfl:LoginResponseData/@sessionID"
> xmlns:cfl="http:www.test.com/cfl" />
> </log>
>
> The message body is:
>  <soapenv:Body>
>   <cfl:LoginResponse xmlns:cfl="http://www.test.com/cfl">
>    <cfl:LoginResponseData sessionID="250446AD43C0EEF3ED2F3172F8FA0A3D"
> statusCode="0"/>
>   </cfl:LoginResponse>
>  </soapenv:Body>
>
> The namespaces in the log mediator for cfl is "http:..." <http:...> (note
> the missing "//") and is thus different from what you see in the message..
> was this a mistake?
>
> cheers
> asankha
>
> --
> Asankha C. Perera
> AdroitLogic, http://adroitlogic.org
> http://esbmagic.blogspot.com
>
>
>

Re: XPath doesn't return attribute value

Posted by "Asankha C. Perera" <as...@apache.org>.
Hi Bill
> <log level="custom">
>   <property name="sessID"  
> expression="//cfl:LoginResponse/cfl:LoginResponseData/@sessionID" 
> xmlns:cfl="http:www.test.com/cfl <http://www.test.com/cfl>" />
> </log>
>
> The message body is:
>  <soapenv:Body>
>   <cfl:LoginResponse xmlns:cfl="http://www.test.com/cfl">
>    <cfl:LoginResponseData sessionID="250446AD43C0EEF3ED2F3172F8FA0A3D" 
> statusCode="0"/>
>   </cfl:LoginResponse>
>  </soapenv:Body>
The namespaces in the log mediator for cfl is "http:..." (note the 
missing "//") and is thus different from what you see in the message.. 
was this a mistake?

cheers
asankha

-- 
Asankha C. Perera
AdroitLogic, http://adroitlogic.org

http://esbmagic.blogspot.com





Re: XPath doesn't return attribute value

Posted by Saliya Ekanayake <es...@gmail.com>.
Thanks Bill :)

Saliya

On Thu, Jun 11, 2009 at 11:25 PM, Bill Harts <pr...@gmail.com> wrote:

> Oh, and congratulations on getting married!  I hope you will be very happy.
>
> Regards,
> Bill
>
>
> On Thu, Jun 11, 2009 at 6:57 AM, Bill Harts <pr...@gmail.com> wrote:
>
>> Hi Saliya:
>>
>> Thanks for pointing this out.  It saves making a change to Axis2/Axiom.
>>
>> Congrats on being made a committer!
>>
>> Regards,
>> Bill
>>
>>
>> On Thu, Jun 11, 2009 at 6:42 AM, Saliya Ekanayake <es...@gmail.com>wrote:
>>
>>>
>>> Hi Bill,
>>>
>>> OMAttributeEx implements OMAttribute interface. So you may check instance
>>> of OMAttribute. This way you don't have to change access modifiers. Also
>>> additional imports are not necessary.
>>>
>>> Thanks,
>>> Saliya
>>>
>>>
>>> On Thu, Jun 11, 2009 at 3:02 PM, Asankha C. Perera <as...@apache.org>wrote:
>>>
>>>>  Hi Bill
>>>>
>>>> ....
>>>> *Solution:*
>>>> I added the following code to synapseXpath.java::stringValueOf at line
>>>> 206:
>>>>                     ...
>>>>                     } else if (o instanceof OMAttributeEx) {
>>>>                         textValue.append(
>>>> ((OMAttributeEx)o).getAttributeValue());
>>>>                    }
>>>>                    ...
>>>>
>>>> Also, since the type OMAttributeEx is an inner class of type
>>>> DocumentNavigator I needed to add an import statement in SynapseXPath.java:
>>>>
>>>> import org.apache.axiom.om.xpath.DocumentNavigator.OMAttributeEx;
>>>>
>>>> Unfortunately, OMAtributeEx is defined as private to class
>>>> DocumentNavigator so I had to declare class and constructor OMAttributeEx as
>>>> public in the module DocumentNavigator.java in the Axiom project module
>>>> axiom-api.jar.
>>>>
>>>> If someone can point me to instructions for how to create a patch I will
>>>> post one here.
>>>>
>>>> I think your solution is correct.. if your question is "how to create a
>>>> patch with svn?".. you should go to the project root, and issue "svn diff >
>>>> changes.patch" and attach this patch to a JIRA (selecting that you grant the
>>>> Apache foundation the rights to use the code).. then one of the comitters of
>>>> the relevant project (Synapse, Axiom etc) will apply the patch to the
>>>> codebase
>>>>
>>>> cheers
>>>> asankha
>>>>
>>>> --
>>>> Asankha C. Perera
>>>> AdroitLogic, http://adroitlogic.org
>>>> http://esbmagic.blogspot.com
>>>>
>>>>
>>>>
>>>
>>>
>>> --
>>> Saliya Ekanayake
>>> http://www.esaliya.blogspot.com
>>> http://www.esaliya.wordpress.com
>>>
>>
>>
>


-- 
Saliya Ekanayake
http://www.esaliya.blogspot.com
http://www.esaliya.wordpress.com

Re: XPath doesn't return attribute value

Posted by Bill Harts <pr...@gmail.com>.
Oh, and congratulations on getting married!  I hope you will be very happy.

Regards,
Bill

On Thu, Jun 11, 2009 at 6:57 AM, Bill Harts <pr...@gmail.com> wrote:

> Hi Saliya:
>
> Thanks for pointing this out.  It saves making a change to Axis2/Axiom.
>
> Congrats on being made a committer!
>
> Regards,
> Bill
>
>
> On Thu, Jun 11, 2009 at 6:42 AM, Saliya Ekanayake <es...@gmail.com>wrote:
>
>>
>> Hi Bill,
>>
>> OMAttributeEx implements OMAttribute interface. So you may check instance
>> of OMAttribute. This way you don't have to change access modifiers. Also
>> additional imports are not necessary.
>>
>> Thanks,
>> Saliya
>>
>>
>> On Thu, Jun 11, 2009 at 3:02 PM, Asankha C. Perera <as...@apache.org>wrote:
>>
>>>  Hi Bill
>>>
>>> ....
>>> *Solution:*
>>> I added the following code to synapseXpath.java::stringValueOf at line
>>> 206:
>>>                     ...
>>>                     } else if (o instanceof OMAttributeEx) {
>>>                         textValue.append(
>>> ((OMAttributeEx)o).getAttributeValue());
>>>                    }
>>>                    ...
>>>
>>> Also, since the type OMAttributeEx is an inner class of type
>>> DocumentNavigator I needed to add an import statement in SynapseXPath.java:
>>>
>>> import org.apache.axiom.om.xpath.DocumentNavigator.OMAttributeEx;
>>>
>>> Unfortunately, OMAtributeEx is defined as private to class
>>> DocumentNavigator so I had to declare class and constructor OMAttributeEx as
>>> public in the module DocumentNavigator.java in the Axiom project module
>>> axiom-api.jar.
>>>
>>> If someone can point me to instructions for how to create a patch I will
>>> post one here.
>>>
>>> I think your solution is correct.. if your question is "how to create a
>>> patch with svn?".. you should go to the project root, and issue "svn diff >
>>> changes.patch" and attach this patch to a JIRA (selecting that you grant the
>>> Apache foundation the rights to use the code).. then one of the comitters of
>>> the relevant project (Synapse, Axiom etc) will apply the patch to the
>>> codebase
>>>
>>> cheers
>>> asankha
>>>
>>> --
>>> Asankha C. Perera
>>> AdroitLogic, http://adroitlogic.org
>>> http://esbmagic.blogspot.com
>>>
>>>
>>>
>>
>>
>> --
>> Saliya Ekanayake
>> http://www.esaliya.blogspot.com
>> http://www.esaliya.wordpress.com
>>
>
>

Re: XPath doesn't return attribute value

Posted by Bill Harts <pr...@gmail.com>.
Hi Saliya:

Thanks for pointing this out.  It saves making a change to Axis2/Axiom.

Congrats on being made a committer!

Regards,
Bill

On Thu, Jun 11, 2009 at 6:42 AM, Saliya Ekanayake <es...@gmail.com> wrote:

>
> Hi Bill,
>
> OMAttributeEx implements OMAttribute interface. So you may check instance
> of OMAttribute. This way you don't have to change access modifiers. Also
> additional imports are not necessary.
>
> Thanks,
> Saliya
>
>
> On Thu, Jun 11, 2009 at 3:02 PM, Asankha C. Perera <as...@apache.org>wrote:
>
>>  Hi Bill
>>
>> ....
>> *Solution:*
>> I added the following code to synapseXpath.java::stringValueOf at line
>> 206:
>>                     ...
>>                     } else if (o instanceof OMAttributeEx) {
>>                         textValue.append(
>> ((OMAttributeEx)o).getAttributeValue());
>>                    }
>>                    ...
>>
>> Also, since the type OMAttributeEx is an inner class of type
>> DocumentNavigator I needed to add an import statement in SynapseXPath.java:
>>
>> import org.apache.axiom.om.xpath.DocumentNavigator.OMAttributeEx;
>>
>> Unfortunately, OMAtributeEx is defined as private to class
>> DocumentNavigator so I had to declare class and constructor OMAttributeEx as
>> public in the module DocumentNavigator.java in the Axiom project module
>> axiom-api.jar.
>>
>> If someone can point me to instructions for how to create a patch I will
>> post one here.
>>
>> I think your solution is correct.. if your question is "how to create a
>> patch with svn?".. you should go to the project root, and issue "svn diff >
>> changes.patch" and attach this patch to a JIRA (selecting that you grant the
>> Apache foundation the rights to use the code).. then one of the comitters of
>> the relevant project (Synapse, Axiom etc) will apply the patch to the
>> codebase
>>
>> cheers
>> asankha
>>
>> --
>> Asankha C. Perera
>> AdroitLogic, http://adroitlogic.org
>> http://esbmagic.blogspot.com
>>
>>
>>
>
>
> --
> Saliya Ekanayake
> http://www.esaliya.blogspot.com
> http://www.esaliya.wordpress.com
>

Re: XPath doesn't return attribute value

Posted by Saliya Ekanayake <es...@gmail.com>.
Hi Bill,

OMAttributeEx implements OMAttribute interface. So you may check instance of
OMAttribute. This way you don't have to change access modifiers. Also
additional imports are not necessary.

Thanks,
Saliya

On Thu, Jun 11, 2009 at 3:02 PM, Asankha C. Perera <as...@apache.org>wrote:

>  Hi Bill
>
> ....
> *Solution:*
> I added the following code to synapseXpath.java::stringValueOf at line 206:
>                     ...
>                     } else if (o instanceof OMAttributeEx) {
>                         textValue.append(
> ((OMAttributeEx)o).getAttributeValue());
>                    }
>                    ...
>
> Also, since the type OMAttributeEx is an inner class of type
> DocumentNavigator I needed to add an import statement in SynapseXPath.java:
>
> import org.apache.axiom.om.xpath.DocumentNavigator.OMAttributeEx;
>
> Unfortunately, OMAtributeEx is defined as private to class
> DocumentNavigator so I had to declare class and constructor OMAttributeEx as
> public in the module DocumentNavigator.java in the Axiom project module
> axiom-api.jar.
>
> If someone can point me to instructions for how to create a patch I will
> post one here.
>
> I think your solution is correct.. if your question is "how to create a
> patch with svn?".. you should go to the project root, and issue "svn diff >
> changes.patch" and attach this patch to a JIRA (selecting that you grant the
> Apache foundation the rights to use the code).. then one of the comitters of
> the relevant project (Synapse, Axiom etc) will apply the patch to the
> codebase
>
> cheers
> asankha
>
> --
> Asankha C. Perera
> AdroitLogic, http://adroitlogic.org
> http://esbmagic.blogspot.com
>
>
>


-- 
Saliya Ekanayake
http://www.esaliya.blogspot.com
http://www.esaliya.wordpress.com

Re: XPath doesn't return attribute value

Posted by "Asankha C. Perera" <as...@apache.org>.
Hi Bill
> ....
> _Solution:_
> I added the following code to synapseXpath.java::stringValueOf at line 
> 206:
>                     ...
>                     } else if (o instanceof OMAttributeEx) {
>                         textValue.append( 
> ((OMAttributeEx)o).getAttributeValue());
>                    }
>                    ...
>
> Also, since the type OMAttributeEx is an inner class of type 
> DocumentNavigator I needed to add an import statement in 
> SynapseXPath.java:
>
> import org.apache.axiom.om.xpath.DocumentNavigator.OMAttributeEx;
>
> Unfortunately, OMAtributeEx is defined as private to class 
> DocumentNavigator so I had to declare class and constructor 
> OMAttributeEx as public in the module DocumentNavigator.java in the 
> Axiom project module axiom-api.jar. 
>
> If someone can point me to instructions for how to create a patch I 
> will post one here.
I think your solution is correct.. if your question is "how to create a 
patch with svn?".. you should go to the project root, and issue "svn 
diff > changes.patch" and attach this patch to a JIRA (selecting that 
you grant the Apache foundation the rights to use the code).. then one 
of the comitters of the relevant project (Synapse, Axiom etc) will apply 
the patch to the codebase

cheers
asankha

-- 
Asankha C. Perera
AdroitLogic, http://adroitlogic.org

http://esbmagic.blogspot.com