You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@synapse.apache.org by indika kumara <in...@gmail.com> on 2009/06/19 09:30:23 UTC

XPath evaluation doesn't work on resources picked from registry

Devs

$subject is due to we do  'detach()'  on picked resource OMElement .
If I add detached element to a OMDocument as a child, it works

Existing code  SImpleURLRegistry

result.detach();
inputStream.close();


Modified code

result.detach();
OMDocumentImpl omDocument = new OMDocumentImpl();
omDocument.addChild(result);
inputStream.close();


Are there any best solution other than what I did ?  I haven't deep
AXIOM knowledge?  Could anyone help me?

Thanks
Indika

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


Re: XPath evaluation doesn't work on resources picked from registry

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

I downloaded the June 25 nightly build #845 and all seems to be working
again so this may have been a temporary problem.  Sorry I don't have time to
troubleshoot but it appears to have gone away.

Bill

On Wed, Jun 24, 2009 at 3:50 AM, indika kumara <in...@gmail.com>wrote:

> I always use current svn trunk.
>
>
> On Wed, Jun 24, 2009 at 1:13 PM, Bill Harts <pr...@gmail.com> wrote:
>
>> I will try this on my system.  What build # did you test this on?
>>
>> Thanks,
>> Bill
>>
>>
>> On Wed, Jun 24, 2009 at 1:26 AM, indika kumara <in...@gmail.com>wrote:
>>
>>> Bill , following is the sample I ahve tested - This is similar to sample
>>> 300. It worked
>>>
>>>
>>> <!-- Introduction to Tasks with simple trigger -->
>>> <definitions xmlns="http://ws.apache.org/ns/synapse">
>>>
>>>     <task class="org.apache.synapse.startup.tasks.MessageInjector"
>>> name="CheckPrice">
>>>         <property name="to" value="
>>> http://localhost:9000/services/SimpleStockQuoteService"/>
>>>         <property name="soapAction" value="urn:getQuote"/>
>>>         <property name="message">
>>>             <m0:getQuote xmlns:m0="http://services.samples">
>>>                 <m0:request>
>>>                     <m0:symbol sessionID="one"/>
>>>                 </m0:request>
>>>             </m0:getQuote>
>>>         </property>
>>>         <trigger interval="5"/>
>>>     </task>
>>>
>>>     <in>
>>>         <filter xmlns="http://ws.apache.org/ns/synapse"
>>>
>>> xpath="boolean(//m:getQuote/m:request/m:symbol/@sessionID)"
>>>                 xmlns:m="http://services.samples">
>>>             <log level="custom">
>>>                 <property name="sessID"
>>> expression="//m:getQuote/m:request/m:symbol/@sessionID"
>>>                           xmlns:m="http://services.samples"/>
>>>             </log>
>>>         </filter>
>>>         <send/>
>>>     </in>
>>>     <out>
>>>         <log level="custom">
>>>             <property name="Stock_Quote_on"
>>>
>>> expression="//ns:return/ax21:lastTradeTimestamp/child::text()"
>>>                       xmlns:ax21="http://services.samples/xsd"
>>> xmlns:ns="http://services.samples"/>
>>>             <property name="For_the_organization"
>>> expression="//ns:return/ax21:name/child::text()"
>>>                       xmlns:ax21="http://services.samples/xsd"
>>> xmlns:ns="http://services.samples"/>
>>>             <property name="Last_Value"
>>> expression="//ns:return/ax21:last/child::text()"
>>>                       xmlns:ax21="http://services.samples/xsd"
>>> xmlns:ns="http://services.samples"/>
>>>         </log>
>>>     </out>
>>>
>>> </definitions>
>>>
>>>
>>> On Wed, Jun 24, 2009 at 1:20 AM, Bill Harts <pr...@gmail.com> wrote:
>>>
>>>> pls try with no data in the symbol tag like
>>>>
>>>> <m:symbol *sessionID="one" /*>
>>>>
>>>>
>>>>
>>>> Mixtped pn my iphne
>>>>
>>>> On Jun 23, 2009, at 2:25 PM, indika kumara <in...@gmail.com>
>>>> wrote:
>>>>
>>>> Bill ,  I have tested your scenario with the following mediator
>>>> configuration and the message. It worked.
>>>>
>>>> Mediator configuration
>>>>
>>>> <filter xmlns=" <http://ws.apache.org/ns/synapse>
>>>> http://ws.apache.org/ns/synapse"
>>>> xpath="boolean(//m:GetQuote/m:symbol/@sessionID)"   xmlns:m="<http://www.webserviceX.NET/>
>>>> http://www.webserviceX.NET/">
>>>>     <log level="custom">
>>>>         <property name="sessID"
>>>> expression="//m:GetQuote/m:symbol/@sessionID"   xmlns:m="<http://www.webserviceX.NET/>
>>>> http://www.webserviceX.NET/"/>
>>>>     </log>
>>>> </filter>
>>>>
>>>> Message
>>>>
>>>> <m:GetQuote xmlns:m=" <http://www.webserviceX.NET/>
>>>> http://www.webserviceX.NET/">
>>>> <m:symbol *sessionID="one"*>IBM</m:symbol>
>>>> </m:GetQuote>
>>>>
>>>> Out put
>>>>
>>>> *sessID = one*
>>>>
>>>> Thanks
>>>> Indika
>>>>
>>>>
>>>
>>
>

Re: XPath evaluation doesn't work on resources picked from registry

Posted by indika kumara <in...@gmail.com>.
I always use current svn trunk.

On Wed, Jun 24, 2009 at 1:13 PM, Bill Harts <pr...@gmail.com> wrote:

> I will try this on my system.  What build # did you test this on?
>
> Thanks,
> Bill
>
>
> On Wed, Jun 24, 2009 at 1:26 AM, indika kumara <in...@gmail.com>wrote:
>
>> Bill , following is the sample I ahve tested - This is similar to sample
>> 300. It worked
>>
>>
>> <!-- Introduction to Tasks with simple trigger -->
>> <definitions xmlns="http://ws.apache.org/ns/synapse">
>>
>>     <task class="org.apache.synapse.startup.tasks.MessageInjector"
>> name="CheckPrice">
>>         <property name="to" value="
>> http://localhost:9000/services/SimpleStockQuoteService"/>
>>         <property name="soapAction" value="urn:getQuote"/>
>>         <property name="message">
>>             <m0:getQuote xmlns:m0="http://services.samples">
>>                 <m0:request>
>>                     <m0:symbol sessionID="one"/>
>>                 </m0:request>
>>             </m0:getQuote>
>>         </property>
>>         <trigger interval="5"/>
>>     </task>
>>
>>     <in>
>>         <filter xmlns="http://ws.apache.org/ns/synapse"
>>
>> xpath="boolean(//m:getQuote/m:request/m:symbol/@sessionID)"
>>                 xmlns:m="http://services.samples">
>>             <log level="custom">
>>                 <property name="sessID"
>> expression="//m:getQuote/m:request/m:symbol/@sessionID"
>>                           xmlns:m="http://services.samples"/>
>>             </log>
>>         </filter>
>>         <send/>
>>     </in>
>>     <out>
>>         <log level="custom">
>>             <property name="Stock_Quote_on"
>>
>> expression="//ns:return/ax21:lastTradeTimestamp/child::text()"
>>                       xmlns:ax21="http://services.samples/xsd" xmlns:ns="
>> http://services.samples"/>
>>             <property name="For_the_organization"
>> expression="//ns:return/ax21:name/child::text()"
>>                       xmlns:ax21="http://services.samples/xsd" xmlns:ns="
>> http://services.samples"/>
>>             <property name="Last_Value"
>> expression="//ns:return/ax21:last/child::text()"
>>                       xmlns:ax21="http://services.samples/xsd" xmlns:ns="
>> http://services.samples"/>
>>         </log>
>>     </out>
>>
>> </definitions>
>>
>>
>> On Wed, Jun 24, 2009 at 1:20 AM, Bill Harts <pr...@gmail.com> wrote:
>>
>>> pls try with no data in the symbol tag like
>>>
>>> <m:symbol *sessionID="one" /*>
>>>
>>>
>>>
>>> Mixtped pn my iphne
>>>
>>> On Jun 23, 2009, at 2:25 PM, indika kumara <in...@gmail.com>
>>> wrote:
>>>
>>> Bill ,  I have tested your scenario with the following mediator
>>> configuration and the message. It worked.
>>>
>>> Mediator configuration
>>>
>>> <filter xmlns=" <http://ws.apache.org/ns/synapse>
>>> http://ws.apache.org/ns/synapse"
>>> xpath="boolean(//m:GetQuote/m:symbol/@sessionID)"   xmlns:m="<http://www.webserviceX.NET/>
>>> http://www.webserviceX.NET/">
>>>     <log level="custom">
>>>         <property name="sessID"
>>> expression="//m:GetQuote/m:symbol/@sessionID"   xmlns:m="<http://www.webserviceX.NET/>
>>> http://www.webserviceX.NET/"/>
>>>     </log>
>>> </filter>
>>>
>>> Message
>>>
>>> <m:GetQuote xmlns:m=" <http://www.webserviceX.NET/>
>>> http://www.webserviceX.NET/">
>>> <m:symbol *sessionID="one"*>IBM</m:symbol>
>>> </m:GetQuote>
>>>
>>> Out put
>>>
>>> *sessID = one*
>>>
>>> Thanks
>>> Indika
>>>
>>>
>>
>

Re: XPath evaluation doesn't work on resources picked from registry

Posted by Bill Harts <pr...@gmail.com>.
I will try this on my system.  What build # did you test this on?

Thanks,
Bill

On Wed, Jun 24, 2009 at 1:26 AM, indika kumara <in...@gmail.com>wrote:

> Bill , following is the sample I ahve tested - This is similar to sample
> 300. It worked
>
>
> <!-- Introduction to Tasks with simple trigger -->
> <definitions xmlns="http://ws.apache.org/ns/synapse">
>
>     <task class="org.apache.synapse.startup.tasks.MessageInjector"
> name="CheckPrice">
>         <property name="to" value="
> http://localhost:9000/services/SimpleStockQuoteService"/>
>         <property name="soapAction" value="urn:getQuote"/>
>         <property name="message">
>             <m0:getQuote xmlns:m0="http://services.samples">
>                 <m0:request>
>                     <m0:symbol sessionID="one"/>
>                 </m0:request>
>             </m0:getQuote>
>         </property>
>         <trigger interval="5"/>
>     </task>
>
>     <in>
>         <filter xmlns="http://ws.apache.org/ns/synapse"
>                 xpath="boolean(//m:getQuote/m:request/m:symbol/@sessionID)"
>                 xmlns:m="http://services.samples">
>             <log level="custom">
>                 <property name="sessID"
> expression="//m:getQuote/m:request/m:symbol/@sessionID"
>                           xmlns:m="http://services.samples"/>
>             </log>
>         </filter>
>         <send/>
>     </in>
>     <out>
>         <log level="custom">
>             <property name="Stock_Quote_on"
>
> expression="//ns:return/ax21:lastTradeTimestamp/child::text()"
>                       xmlns:ax21="http://services.samples/xsd" xmlns:ns="
> http://services.samples"/>
>             <property name="For_the_organization"
> expression="//ns:return/ax21:name/child::text()"
>                       xmlns:ax21="http://services.samples/xsd" xmlns:ns="
> http://services.samples"/>
>             <property name="Last_Value"
> expression="//ns:return/ax21:last/child::text()"
>                       xmlns:ax21="http://services.samples/xsd" xmlns:ns="
> http://services.samples"/>
>         </log>
>     </out>
>
> </definitions>
>
>
> On Wed, Jun 24, 2009 at 1:20 AM, Bill Harts <pr...@gmail.com> wrote:
>
>> pls try with no data in the symbol tag like
>>
>> <m:symbol *sessionID="one" /*>
>>
>>
>>
>> Mixtped pn my iphne
>>
>> On Jun 23, 2009, at 2:25 PM, indika kumara <in...@gmail.com> wrote:
>>
>> Bill ,  I have tested your scenario with the following mediator
>> configuration and the message. It worked.
>>
>> Mediator configuration
>>
>> <filter xmlns=" <http://ws.apache.org/ns/synapse>
>> http://ws.apache.org/ns/synapse"
>> xpath="boolean(//m:GetQuote/m:symbol/@sessionID)"   xmlns:m="<http://www.webserviceX.NET/>
>> http://www.webserviceX.NET/">
>>     <log level="custom">
>>         <property name="sessID"
>> expression="//m:GetQuote/m:symbol/@sessionID"   xmlns:m="<http://www.webserviceX.NET/>
>> http://www.webserviceX.NET/"/>
>>     </log>
>> </filter>
>>
>> Message
>>
>> <m:GetQuote xmlns:m=" <http://www.webserviceX.NET/>
>> http://www.webserviceX.NET/">
>> <m:symbol *sessionID="one"*>IBM</m:symbol>
>> </m:GetQuote>
>>
>> Out put
>>
>> *sessID = one*
>>
>> Thanks
>> Indika
>>
>>
>

Re: XPath evaluation doesn't work on resources picked from registry

Posted by indika kumara <in...@gmail.com>.
Bill , following is the sample I ahve tested - This is similar to sample
300. It worked


<!-- Introduction to Tasks with simple trigger -->
<definitions xmlns="http://ws.apache.org/ns/synapse">

    <task class="org.apache.synapse.startup.tasks.MessageInjector"
name="CheckPrice">
        <property name="to" value="
http://localhost:9000/services/SimpleStockQuoteService"/>
        <property name="soapAction" value="urn:getQuote"/>
        <property name="message">
            <m0:getQuote xmlns:m0="http://services.samples">
                <m0:request>
                    <m0:symbol sessionID="one"/>
                </m0:request>
            </m0:getQuote>
        </property>
        <trigger interval="5"/>
    </task>

    <in>
        <filter xmlns="http://ws.apache.org/ns/synapse"
                xpath="boolean(//m:getQuote/m:request/m:symbol/@sessionID)"
                xmlns:m="http://services.samples">
            <log level="custom">
                <property name="sessID"
expression="//m:getQuote/m:request/m:symbol/@sessionID"
                          xmlns:m="http://services.samples"/>
            </log>
        </filter>
        <send/>
    </in>
    <out>
        <log level="custom">
            <property name="Stock_Quote_on"

expression="//ns:return/ax21:lastTradeTimestamp/child::text()"
                      xmlns:ax21="http://services.samples/xsd" xmlns:ns="
http://services.samples"/>
            <property name="For_the_organization"
expression="//ns:return/ax21:name/child::text()"
                      xmlns:ax21="http://services.samples/xsd" xmlns:ns="
http://services.samples"/>
            <property name="Last_Value"
expression="//ns:return/ax21:last/child::text()"
                      xmlns:ax21="http://services.samples/xsd" xmlns:ns="
http://services.samples"/>
        </log>
    </out>

</definitions>

On Wed, Jun 24, 2009 at 1:20 AM, Bill Harts <pr...@gmail.com> wrote:

> pls try with no data in the symbol tag like
>
> <m:symbol *sessionID="one" /*>
>
>
>
> Mixtped pn my iphne
>
> On Jun 23, 2009, at 2:25 PM, indika kumara <in...@gmail.com> wrote:
>
> Bill ,  I have tested your scenario with the following mediator
> configuration and the message. It worked.
>
> Mediator configuration
>
> <filter xmlns=" <http://ws.apache.org/ns/synapse>
> http://ws.apache.org/ns/synapse"
> xpath="boolean(//m:GetQuote/m:symbol/@sessionID)"   xmlns:m="<http://www.webserviceX.NET/>
> http://www.webserviceX.NET/">
>     <log level="custom">
>         <property name="sessID"
> expression="//m:GetQuote/m:symbol/@sessionID"   xmlns:m="<http://www.webserviceX.NET/>
> http://www.webserviceX.NET/"/>
>     </log>
> </filter>
>
> Message
>
> <m:GetQuote xmlns:m=" <http://www.webserviceX.NET/>
> http://www.webserviceX.NET/">
> <m:symbol *sessionID="one"*>IBM</m:symbol>
> </m:GetQuote>
>
> Out put
>
> *sessID = one*
>
> Thanks
> Indika
>
>

Re: XPath evaluation doesn't work on resources picked from registry

Posted by Bill Harts <pr...@gmail.com>.
pls try with no data in the symbol tag like

> <m:symbol sessionID="one" />


Mixtped pn my iphne

On Jun 23, 2009, at 2:25 PM, indika kumara <in...@gmail.com>  
wrote:

> Bill ,  I have tested your scenario with the following mediator  
> configuration and the message. It worked.
>
> Mediator configuration
>
> <filter xmlns="http://ws.apache.org/ns/synapse" xpath="boolean(// 
> m:GetQuote/m:symbol/@sessionID)"   xmlns:m="http://www.webserviceX.NET/ 
> ">
>     <log level="custom">
>         <property name="sessID" expression="//m:GetQuote/m:symbol/ 
> @sessionID"   xmlns:m="http://www.webserviceX.NET/"/>
>     </log>
> </filter>
>
> Message
>
> <m:GetQuote xmlns:m="http://www.webserviceX.NET/">
> <m:symbol sessionID="one">IBM</m:symbol>
> </m:GetQuote>
>
> Out put
>
> sessID = one
>
> Thanks
> Indika

Re: XPath evaluation doesn't work on resources picked from registry

Posted by indika kumara <in...@gmail.com>.
Bill ,  I have tested your scenario with the following mediator
configuration and the message. It worked.

Mediator configuration

<filter xmlns="http://ws.apache.org/ns/synapse"
xpath="boolean(//m:GetQuote/m:symbol/@sessionID)"   xmlns:m="
http://www.webserviceX.NET/">
    <log level="custom">
        <property name="sessID"
expression="//m:GetQuote/m:symbol/@sessionID"   xmlns:m="
http://www.webserviceX.NET/"/>
    </log>
</filter>

Message

<m:GetQuote xmlns:m="http://www.webserviceX.NET/">
<m:symbol *sessionID="one"*>IBM</m:symbol>
</m:GetQuote>

Out put

*sessID = one*

Thanks
Indika

Re: XPath evaluation doesn't work on resources picked from registry

Posted by Andreas Veithen <an...@gmail.com>.
Are you sure that you don't have a merge conflict in your local copy?

Andreas

On Tue, Jun 23, 2009 at 15:44, Bill Harts<pr...@gmail.com> wrote:
> FYI, SYNAPSE-557 did fix the problem with returning attributes.  What I am
> reporting here seems to be something specific to using XPATH in a Log
> mediator (i.e, it works ok in the Filter mediator).
>
> I am trying to get the latest trunk (787669) to compile now so I can debug
> it.  There are 2 problems in Endpoint.java that cause it not to compile.
>
> [INFO]
> ------------------------------------------------------------------------
> [ERROR] BUILD FAILURE
> [INFO]
> ------------------------------------------------------------------------
> [INFO] Compilation failure
>
> C:\Apache\Synapse-Trunk\modules\core\src\main\java\org\apache\synapse\endpoints\
> Endpoint.java:[39,0] <identifier> expected
>
> C:\Apache\Synapse-Trunk\modules\core\src\main\java\org\apache\synapse\endpoints\
> Endpoint.java:[44,54] = expected
>
>
> [INFO]
> ------------------------------------------------------------------------
> [INFO] For more information, run Maven with the -e switch
> [INFO]
> ------------------------------------------------------------------------
> [INFO] Total time: 3 minutes 56 seconds
> [INFO] Finished at: Tue Jun 23 09:36:12 EDT 2009
> [INFO] Final Memory: 30M/63M
> [INFO]
> ------------------------------------------------------------------------
> C:\Apache\Synapse-Trunk>
>
> Bill
>
> On Tue, Jun 23, 2009 at 5:32 AM, Andreas Veithen <an...@gmail.com>
> wrote:
>>
>> Strange, this is actually a problem that should have been fixed
>> recently; see SYNAPSE-557.
>>
>> Andreas
>>
>> On Mon, Jun 22, 2009 at 23:28, Bill Harts<pr...@gmail.com> wrote:
>> > Hi Guys:
>> >
>> > I'm not sure but I believe something has broken with using xpath
>> > expressions
>> > in a log mediator possibly related to your recent changes.  I think this
>> > was
>> > working until I downloaded yesterday's snapshot I was using a 3-week old
>> > snapshot).
>> >
>> > Here's the code from my my mediator file:
>> >
>> > <!-- If there's a sessionID attribute in the message this must be a
>> > response
>> > to a Login -->
>> > <filter
>> > xpath="boolean(//cfl:LoginResponse/cfl:LoginResponseData/@sessionID)"
>> > xmlns:cfl="http://www.harts.com/cfl" >
>> >
>> >      <log level="custom">
>> >
>> >          <property name="sessID"
>> > expression="//cfl:LoginResponse/cfl:LoginResponseData/@sessionID"
>> > xmlns:cfl="http://www.harts.com/cfl"/>
>> >
>> >      </log>
>> >
>> >      <!-- Other logic goes here -->
>> >
>> > </filter>
>> >
>> > It passes the filter test but the log mediator just displays "sessID=".
>> > Since the expressions in the filter and log mediators are the same I
>> > don't
>> > think this should happen.
>> >
>> > Bill
>> >
>> > On Sun, Jun 21, 2009 at 1:11 PM, indika kumara <in...@gmail.com>
>> > wrote:
>> >>
>> >> Hi Saliya
>> >>
>> >> This Use case scenario is related with XPath evaluation on the
>> >> resources picked from the registry. After reading the resource we
>> >> close input stream as it is needed.
>> >>
>> >> In this use case, parent is always an OMDocument.
>> >>
>> >> For both following code, you get ‘org.apache.axiom.om.OMException:
>> >> com.ctc.wstx.exc.WstxIOException: Stream closed’.
>> >>
>> >> 1)     remove result.detach()
>> >>
>> >> 2)     replace result.detach() with  result.build()
>> >>
>> >> (Please refers SimpleURLRegistry.java)
>> >>
>> >> Note that here ‘result = builder.getDocumentElement();’ and it is not
>> >> builder.getDocument(). If It is possible to call build() method on
>> >> OMDocument this issue (‘Stream closed’) may not be occurred (I didn’t
>> >> look at AXIOM code).  As Andreas pointed out ‘OMDocument has no method
>> >> to build the entire tree and detach() do that as a side effect”.
>> >>
>> >> I didn't look at deep but feel current possible solutions are what
>> >> Andreas suggested.
>> >>
>> >> Thanks
>> >> Indika
>> >>
>> >> On Sun, Jun 21, 2009 at 5:31 PM, Saliya Ekanayake <es...@gmail.com>
>> >> wrote:
>> >> >
>> >> > Hi Indika,
>> >> >
>> >> > I tested your point and found the cause. Simply, in the second case
>> >> > there is no parent for the root element. Therefore, evaluating an
>> >> > XPath
>> >> > containing <hello> element will cause an exception. But if you
>> >> > evaluate an
>> >> > XPath like, //anotherthing/insideanother, you will get the desired
>> >> > result.
>> >> >
>> >> > So the solution I would like to suggest in this case is to first
>> >> > check
>> >> > the parent of the element. If the parent is an instance of OMDocument
>> >> > then
>> >> > we need not detach (if you need to build then just use
>> >> > OMNode#build()). If
>> >> > the parent is an instance of OMElement then you need to detach since
>> >> > you
>> >> > want the element to be isolated from the connecting tree.
>> >> >
>> >> > Thanks,
>> >> > Saliya
>> >> >
>> >> > On Sun, Jun 21, 2009 at 11:06 AM, indika kumara
>> >> > <in...@gmail.com>
>> >> > wrote:
>> >> >>
>> >> >>         Hi Saliya
>> >> >>
>> >> >>         Following shown my scenarios.
>> >> >>
>> >> >>
>> >> >>        Scenario 1  - without detach on root element
>> >> >>
>> >> >>         String str = "<hello><something>wow
>> >> >>
>> >> >> nice</something><anotherthing><insideanother>great</insideanother></anotherthing></hello>";
>> >> >>         XMLStreamReader parser = XMLInputFactory.newInstance().
>> >> >>                 createXMLStreamReader(new
>> >> >> ByteArrayInputStream(str.getBytes()));
>> >> >>         StAXOMBuilder builder = new StAXOMBuilder(parser);
>> >> >>         OMElement root = builder.getDocumentElement();
>> >> >> //        root.detach();
>> >> >>
>> >> >>         AXIOMXPath xpath = new AXIOMXPath("//hello/something");
>> >> >>         OMElement node = (OMElement) xpath.selectSingleNode(root);
>> >> >>         System.out.println(node == null);
>> >> >>         if (node != null) {
>> >> >>             System.out.println(node.getText());
>> >> >>         }
>> >> >>
>> >> >>
>> >> >>       Out put :
>> >> >>
>> >> >>        false
>> >> >>        wow nice
>> >> >>
>> >> >>
>> >> >>        Scenario 2 - with  detach on root element
>> >> >>
>> >> >>         String str = "<hello><something>wow
>> >> >>
>> >> >> nice</something><anotherthing><insideanother>great</insideanother></anotherthing></hello>";
>> >> >>         XMLStreamReader parser = XMLInputFactory.newInstance().
>> >> >>                 createXMLStreamReader(new
>> >> >> ByteArrayInputStream(str.getBytes()));
>> >> >>         StAXOMBuilder builder = new StAXOMBuilder(parser);
>> >> >>         OMElement root = builder.getDocumentElement();
>> >> >>         root.detach();
>> >> >>
>> >> >>         AXIOMXPath xpath = new AXIOMXPath("//hello/something");
>> >> >>         OMElement node = (OMElement) xpath.selectSingleNode(root);
>> >> >>         System.out.println(node == null);
>> >> >>         if (node != null) {
>> >> >>             System.out.println(node.getText());
>> >> >>         }
>> >> >>
>> >> >>        Output
>> >> >>
>> >> >>        true
>> >> >>
>> >> >>
>> >> >>    In second case , XPath  have not been evaluated correctly.
>> >> >>
>> >> >> Thanks
>> >> >> Indika
>> >> >>
>> >> >> On Sat, Jun 20, 2009 at 9:40 PM, Saliya Ekanayake
>> >> >> <es...@gmail.com>
>> >> >> wrote:
>> >> >>>
>> >> >>> Hi,
>> >> >>>
>> >> >>> Um, I am not really clarified with the problem here. I agree that
>> >> >>> the
>> >> >>> full tree should be built before we can evaluate XPath. Adding the
>> >> >>> element
>> >> >>> to a new OMDocument, however, just to get this done seems not
>> >> >>> right.
>> >> >>> Additionally, the original OMDocument created by the builder will
>> >> >>> be there
>> >> >>> even if you detach the element. Detach will only remove the element
>> >> >>> from the
>> >> >>> tree to which it belongs. To check this, you can get the builder
>> >> >>> from the
>> >> >>> detached element and ask for the OMDocument.  IMHO, we can call
>> >> >>> result.build() if necessary.
>> >> >>>
>> >> >>> Btw. I am not clear why XPath doesn't work on the detached element.
>> >> >>> I
>> >> >>> did a simple test as follows and XPath worked, may be I have missed
>> >> >>> something (please let me know if so).
>> >> >>>
>> >> >>>     public static void main(String[] args) throws
>> >> >>> XMLStreamException,
>> >> >>> JaxenException {
>> >> >>>         String str = "<hello><something>wow
>> >> >>>
>> >> >>> nice</something><anotherthing><insideanother>great</insideanother></anotherthing></hello>";
>> >> >>>         StAXOMBuilder builder = new StAXOMBuilder(new
>> >> >>> ByteArrayInputStream(str.getBytes()));
>> >> >>>         OMElement root = builder.getDocumentElement();
>> >> >>>
>> >> >>>         OMDocument doc = builder.getDocument();
>> >> >>>         System.out.println(doc == null);
>> >> >>>
>> >> >>>         OMElement anotherthing = root.getFirstChildWithName(new
>> >> >>> QName("anotherthing"));
>> >> >>>         anotherthing.detach();
>> >> >>>
>> >> >>>         doc =
>> >> >>> ((StAXOMBuilder)anotherthing.getBuilder()).getDocument();
>> >> >>>         System.out.println(doc == null);
>> >> >>>
>> >> >>>         AXIOMXPath xpath = new AXIOMXPath("//insideanother");
>> >> >>>         OMElement node = (OMElement)
>> >> >>> xpath.selectSingleNode(anotherthing);
>> >> >>>         System.out.println(node.getText());
>> >> >>>     }
>> >> >>>
>> >> >>> Thanks,
>> >> >>> Saliya
>> >> >>>
>> >> >>> On Sat, Jun 20, 2009 at 4:45 AM, Andreas Veithen
>> >> >>> <an...@gmail.com> wrote:
>> >> >>>>
>> >> >>>> StAXOMBuilder actually already creates an OMDocument (which can be
>> >> >>>> retrieved by the getDocument method). The important thing is that
>> >> >>>> we
>> >> >>>> need to make sure that the Axiom tree is fully built before
>> >> >>>> closing
>> >> >>>> the input stream. I guess that the detach method is used because
>> >> >>>> it
>> >> >>>> has the side effect of fully building the element and because
>> >> >>>> OMDocument has no method to build the entire tree (see
>> >> >>>> WSCOMMONS-479).
>> >> >>>>
>> >> >>>> This gives us two solutions:
>> >> >>>>
>> >> >>>> - Use StAXOMBuilder#getDocument and iterate over its children to
>> >> >>>> make
>> >> >>>> sure the document is fully built.
>> >> >>>> - Continue to use "detach" and add the element to a new document,
>> >> >>>> as
>> >> >>>> you suggested. Note that you should not use OMDocumentImpl
>> >> >>>> directly,
>> >> >>>> but create it using the OMFactory.
>> >> >>>>
>> >> >>>> Andreas
>> >> >>>>
>> >> >>>> On Fri, Jun 19, 2009 at 09:30, indika
>> >> >>>> kumara<in...@gmail.com>
>> >> >>>> wrote:
>> >> >>>> > Devs
>> >> >>>> >
>> >> >>>> > $subject is due to we do  'detach()'  on picked resource
>> >> >>>> > OMElement
>> >> >>>> > .
>> >> >>>> > If I add detached element to a OMDocument as a child, it works
>> >> >>>> >
>> >> >>>> > Existing code  SImpleURLRegistry
>> >> >>>> >
>> >> >>>> > result.detach();
>> >> >>>> > inputStream.close();
>> >> >>>> >
>> >> >>>> >
>> >> >>>> > Modified code
>> >> >>>> >
>> >> >>>> > result.detach();
>> >> >>>> > OMDocumentImpl omDocument = new OMDocumentImpl();
>> >> >>>> > omDocument.addChild(result);
>> >> >>>> > inputStream.close();
>> >> >>>> >
>> >> >>>> >
>> >> >>>> > Are there any best solution other than what I did ?  I haven't
>> >> >>>> > deep
>> >> >>>> > AXIOM knowledge?  Could anyone help me?
>> >> >>>> >
>> >> >>>> > Thanks
>> >> >>>> > Indika
>> >> >>>> >
>> >> >>>> >
>> >> >>>> >
>> >> >>>> > ---------------------------------------------------------------------
>> >> >>>> > To unsubscribe, e-mail: dev-unsubscribe@synapse.apache.org
>> >> >>>> > For additional commands, e-mail: dev-help@synapse.apache.org
>> >> >>>> >
>> >> >>>> >
>> >> >>>>
>> >> >>>>
>> >> >>>> ---------------------------------------------------------------------
>> >> >>>> To unsubscribe, e-mail: dev-unsubscribe@synapse.apache.org
>> >> >>>> For additional commands, e-mail: dev-help@synapse.apache.org
>> >> >>>>
>> >> >>>
>> >> >>>
>> >> >>>
>> >> >>> --
>> >> >>> Saliya Ekanayake
>> >> >>> http://www.esaliya.blogspot.com
>> >> >>> http://www.esaliya.wordpress.com
>> >> >>
>> >> >
>> >> >
>> >> >
>> >> > --
>> >> > Saliya Ekanayake
>> >> > http://www.esaliya.blogspot.com
>> >> > http://www.esaliya.wordpress.com
>> >>
>> >> ---------------------------------------------------------------------
>> >> To unsubscribe, e-mail: dev-unsubscribe@synapse.apache.org
>> >> For additional commands, e-mail: dev-help@synapse.apache.org
>> >>
>> >
>> >
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: dev-unsubscribe@synapse.apache.org
>> For additional commands, e-mail: dev-help@synapse.apache.org
>>
>
>

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


Re: XPath evaluation doesn't work on resources picked from registry

Posted by Bill Harts <pr...@gmail.com>.
FYI, SYNAPSE-557 did fix the problem with returning attributes.  What I am
reporting here seems to be something specific to using XPATH in a Log
mediator (i.e, it works ok in the Filter mediator).

I am trying to get the latest trunk (787669) to compile now so I can debug
it.  There are 2 problems in Endpoint.java that cause it not to compile.

[INFO]
------------------------------------------------------------------------
[ERROR] BUILD FAILURE
[INFO]
------------------------------------------------------------------------
[INFO] Compilation failure

C:\Apache\Synapse-Trunk\modules\core\src\main\java\org\apache\synapse\endpoints\
Endpoint.java:[39,0] <identifier> expected

C:\Apache\Synapse-Trunk\modules\core\src\main\java\org\apache\synapse\endpoints\
Endpoint.java:[44,54] = expected


[INFO]
------------------------------------------------------------------------
[INFO] For more information, run Maven with the -e switch
[INFO]
------------------------------------------------------------------------
[INFO] Total time: 3 minutes 56 seconds
[INFO] Finished at: Tue Jun 23 09:36:12 EDT 2009
[INFO] Final Memory: 30M/63M
[INFO]
------------------------------------------------------------------------
C:\Apache\Synapse-Trunk>

Bill

On Tue, Jun 23, 2009 at 5:32 AM, Andreas Veithen
<an...@gmail.com>wrote:

> Strange, this is actually a problem that should have been fixed
> recently; see SYNAPSE-557.
>
> Andreas
>
> On Mon, Jun 22, 2009 at 23:28, Bill Harts<pr...@gmail.com> wrote:
> > Hi Guys:
> >
> > I'm not sure but I believe something has broken with using xpath
> expressions
> > in a log mediator possibly related to your recent changes.  I think this
> was
> > working until I downloaded yesterday's snapshot I was using a 3-week old
> > snapshot).
> >
> > Here's the code from my my mediator file:
> >
> > <!-- If there's a sessionID attribute in the message this must be a
> response
> > to a Login -->
> > <filter
> > xpath="boolean(//cfl:LoginResponse/cfl:LoginResponseData/@sessionID)"
> > xmlns:cfl="http://www.harts.com/cfl" >
> >
> >      <log level="custom">
> >
> >          <property name="sessID"
> > expression="//cfl:LoginResponse/cfl:LoginResponseData/@sessionID"
> > xmlns:cfl="http://www.harts.com/cfl"/>
> >
> >      </log>
> >
> >      <!-- Other logic goes here -->
> >
> > </filter>
> >
> > It passes the filter test but the log mediator just displays "sessID=".
> > Since the expressions in the filter and log mediators are the same I
> don't
> > think this should happen.
> >
> > Bill
> >
> > On Sun, Jun 21, 2009 at 1:11 PM, indika kumara <in...@gmail.com>
> > wrote:
> >>
> >> Hi Saliya
> >>
> >> This Use case scenario is related with XPath evaluation on the
> >> resources picked from the registry. After reading the resource we
> >> close input stream as it is needed.
> >>
> >> In this use case, parent is always an OMDocument.
> >>
> >> For both following code, you get ‘org.apache.axiom.om.OMException:
> >> com.ctc.wstx.exc.WstxIOException: Stream closed’.
> >>
> >> 1)     remove result.detach()
> >>
> >> 2)     replace result.detach() with  result.build()
> >>
> >> (Please refers SimpleURLRegistry.java)
> >>
> >> Note that here ‘result = builder.getDocumentElement();’ and it is not
> >> builder.getDocument(). If It is possible to call build() method on
> >> OMDocument this issue (‘Stream closed’) may not be occurred (I didn’t
> >> look at AXIOM code).  As Andreas pointed out ‘OMDocument has no method
> >> to build the entire tree and detach() do that as a side effect”.
> >>
> >> I didn't look at deep but feel current possible solutions are what
> >> Andreas suggested.
> >>
> >> Thanks
> >> Indika
> >>
> >> On Sun, Jun 21, 2009 at 5:31 PM, Saliya Ekanayake <es...@gmail.com>
> >> wrote:
> >> >
> >> > Hi Indika,
> >> >
> >> > I tested your point and found the cause. Simply, in the second case
> >> > there is no parent for the root element. Therefore, evaluating an
> XPath
> >> > containing <hello> element will cause an exception. But if you
> evaluate an
> >> > XPath like, //anotherthing/insideanother, you will get the desired
> result.
> >> >
> >> > So the solution I would like to suggest in this case is to first check
> >> > the parent of the element. If the parent is an instance of OMDocument
> then
> >> > we need not detach (if you need to build then just use
> OMNode#build()). If
> >> > the parent is an instance of OMElement then you need to detach since
> you
> >> > want the element to be isolated from the connecting tree.
> >> >
> >> > Thanks,
> >> > Saliya
> >> >
> >> > On Sun, Jun 21, 2009 at 11:06 AM, indika kumara <
> indika.kuma@gmail.com>
> >> > wrote:
> >> >>
> >> >>         Hi Saliya
> >> >>
> >> >>         Following shown my scenarios.
> >> >>
> >> >>
> >> >>        Scenario 1  - without detach on root element
> >> >>
> >> >>         String str = "<hello><something>wow
> >> >>
> nice</something><anotherthing><insideanother>great</insideanother></anotherthing></hello>";
> >> >>         XMLStreamReader parser = XMLInputFactory.newInstance().
> >> >>                 createXMLStreamReader(new
> >> >> ByteArrayInputStream(str.getBytes()));
> >> >>         StAXOMBuilder builder = new StAXOMBuilder(parser);
> >> >>         OMElement root = builder.getDocumentElement();
> >> >> //        root.detach();
> >> >>
> >> >>         AXIOMXPath xpath = new AXIOMXPath("//hello/something");
> >> >>         OMElement node = (OMElement) xpath.selectSingleNode(root);
> >> >>         System.out.println(node == null);
> >> >>         if (node != null) {
> >> >>             System.out.println(node.getText());
> >> >>         }
> >> >>
> >> >>
> >> >>       Out put :
> >> >>
> >> >>        false
> >> >>        wow nice
> >> >>
> >> >>
> >> >>        Scenario 2 - with  detach on root element
> >> >>
> >> >>         String str = "<hello><something>wow
> >> >>
> nice</something><anotherthing><insideanother>great</insideanother></anotherthing></hello>";
> >> >>         XMLStreamReader parser = XMLInputFactory.newInstance().
> >> >>                 createXMLStreamReader(new
> >> >> ByteArrayInputStream(str.getBytes()));
> >> >>         StAXOMBuilder builder = new StAXOMBuilder(parser);
> >> >>         OMElement root = builder.getDocumentElement();
> >> >>         root.detach();
> >> >>
> >> >>         AXIOMXPath xpath = new AXIOMXPath("//hello/something");
> >> >>         OMElement node = (OMElement) xpath.selectSingleNode(root);
> >> >>         System.out.println(node == null);
> >> >>         if (node != null) {
> >> >>             System.out.println(node.getText());
> >> >>         }
> >> >>
> >> >>        Output
> >> >>
> >> >>        true
> >> >>
> >> >>
> >> >>    In second case , XPath  have not been evaluated correctly.
> >> >>
> >> >> Thanks
> >> >> Indika
> >> >>
> >> >> On Sat, Jun 20, 2009 at 9:40 PM, Saliya Ekanayake <esaliya@gmail.com
> >
> >> >> wrote:
> >> >>>
> >> >>> Hi,
> >> >>>
> >> >>> Um, I am not really clarified with the problem here. I agree that
> the
> >> >>> full tree should be built before we can evaluate XPath. Adding the
> element
> >> >>> to a new OMDocument, however, just to get this done seems not right.
> >> >>> Additionally, the original OMDocument created by the builder will be
> there
> >> >>> even if you detach the element. Detach will only remove the element
> from the
> >> >>> tree to which it belongs. To check this, you can get the builder
> from the
> >> >>> detached element and ask for the OMDocument.  IMHO, we can call
> >> >>> result.build() if necessary.
> >> >>>
> >> >>> Btw. I am not clear why XPath doesn't work on the detached element.
> I
> >> >>> did a simple test as follows and XPath worked, may be I have missed
> >> >>> something (please let me know if so).
> >> >>>
> >> >>>     public static void main(String[] args) throws
> XMLStreamException,
> >> >>> JaxenException {
> >> >>>         String str = "<hello><something>wow
> >> >>>
> nice</something><anotherthing><insideanother>great</insideanother></anotherthing></hello>";
> >> >>>         StAXOMBuilder builder = new StAXOMBuilder(new
> >> >>> ByteArrayInputStream(str.getBytes()));
> >> >>>         OMElement root = builder.getDocumentElement();
> >> >>>
> >> >>>         OMDocument doc = builder.getDocument();
> >> >>>         System.out.println(doc == null);
> >> >>>
> >> >>>         OMElement anotherthing = root.getFirstChildWithName(new
> >> >>> QName("anotherthing"));
> >> >>>         anotherthing.detach();
> >> >>>
> >> >>>         doc =
> >> >>> ((StAXOMBuilder)anotherthing.getBuilder()).getDocument();
> >> >>>         System.out.println(doc == null);
> >> >>>
> >> >>>         AXIOMXPath xpath = new AXIOMXPath("//insideanother");
> >> >>>         OMElement node = (OMElement)
> >> >>> xpath.selectSingleNode(anotherthing);
> >> >>>         System.out.println(node.getText());
> >> >>>     }
> >> >>>
> >> >>> Thanks,
> >> >>> Saliya
> >> >>>
> >> >>> On Sat, Jun 20, 2009 at 4:45 AM, Andreas Veithen
> >> >>> <an...@gmail.com> wrote:
> >> >>>>
> >> >>>> StAXOMBuilder actually already creates an OMDocument (which can be
> >> >>>> retrieved by the getDocument method). The important thing is that
> we
> >> >>>> need to make sure that the Axiom tree is fully built before closing
> >> >>>> the input stream. I guess that the detach method is used because it
> >> >>>> has the side effect of fully building the element and because
> >> >>>> OMDocument has no method to build the entire tree (see
> >> >>>> WSCOMMONS-479).
> >> >>>>
> >> >>>> This gives us two solutions:
> >> >>>>
> >> >>>> - Use StAXOMBuilder#getDocument and iterate over its children to
> make
> >> >>>> sure the document is fully built.
> >> >>>> - Continue to use "detach" and add the element to a new document,
> as
> >> >>>> you suggested. Note that you should not use OMDocumentImpl
> directly,
> >> >>>> but create it using the OMFactory.
> >> >>>>
> >> >>>> Andreas
> >> >>>>
> >> >>>> On Fri, Jun 19, 2009 at 09:30, indika kumara<indika.kuma@gmail.com
> >
> >> >>>> wrote:
> >> >>>> > Devs
> >> >>>> >
> >> >>>> > $subject is due to we do  'detach()'  on picked resource
> OMElement
> >> >>>> > .
> >> >>>> > If I add detached element to a OMDocument as a child, it works
> >> >>>> >
> >> >>>> > Existing code  SImpleURLRegistry
> >> >>>> >
> >> >>>> > result.detach();
> >> >>>> > inputStream.close();
> >> >>>> >
> >> >>>> >
> >> >>>> > Modified code
> >> >>>> >
> >> >>>> > result.detach();
> >> >>>> > OMDocumentImpl omDocument = new OMDocumentImpl();
> >> >>>> > omDocument.addChild(result);
> >> >>>> > inputStream.close();
> >> >>>> >
> >> >>>> >
> >> >>>> > Are there any best solution other than what I did ?  I haven't
> deep
> >> >>>> > AXIOM knowledge?  Could anyone help me?
> >> >>>> >
> >> >>>> > Thanks
> >> >>>> > Indika
> >> >>>> >
> >> >>>> >
> >> >>>> >
> ---------------------------------------------------------------------
> >> >>>> > To unsubscribe, e-mail: dev-unsubscribe@synapse.apache.org
> >> >>>> > For additional commands, e-mail: dev-help@synapse.apache.org
> >> >>>> >
> >> >>>> >
> >> >>>>
> >> >>>>
> ---------------------------------------------------------------------
> >> >>>> To unsubscribe, e-mail: dev-unsubscribe@synapse.apache.org
> >> >>>> For additional commands, e-mail: dev-help@synapse.apache.org
> >> >>>>
> >> >>>
> >> >>>
> >> >>>
> >> >>> --
> >> >>> Saliya Ekanayake
> >> >>> http://www.esaliya.blogspot.com
> >> >>> http://www.esaliya.wordpress.com
> >> >>
> >> >
> >> >
> >> >
> >> > --
> >> > Saliya Ekanayake
> >> > http://www.esaliya.blogspot.com
> >> > http://www.esaliya.wordpress.com
> >>
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: dev-unsubscribe@synapse.apache.org
> >> For additional commands, e-mail: dev-help@synapse.apache.org
> >>
> >
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@synapse.apache.org
> For additional commands, e-mail: dev-help@synapse.apache.org
>
>

Re: XPath evaluation doesn't work on resources picked from registry

Posted by Andreas Veithen <an...@gmail.com>.
Strange, this is actually a problem that should have been fixed
recently; see SYNAPSE-557.

Andreas

On Mon, Jun 22, 2009 at 23:28, Bill Harts<pr...@gmail.com> wrote:
> Hi Guys:
>
> I'm not sure but I believe something has broken with using xpath expressions
> in a log mediator possibly related to your recent changes.  I think this was
> working until I downloaded yesterday's snapshot I was using a 3-week old
> snapshot).
>
> Here's the code from my my mediator file:
>
> <!-- If there's a sessionID attribute in the message this must be a response
> to a Login -->
> <filter
> xpath="boolean(//cfl:LoginResponse/cfl:LoginResponseData/@sessionID)"
> xmlns:cfl="http://www.harts.com/cfl" >
>
>      <log level="custom">
>
>          <property name="sessID"
> expression="//cfl:LoginResponse/cfl:LoginResponseData/@sessionID"
> xmlns:cfl="http://www.harts.com/cfl"/>
>
>      </log>
>
>      <!-- Other logic goes here -->
>
> </filter>
>
> It passes the filter test but the log mediator just displays "sessID=".
> Since the expressions in the filter and log mediators are the same I don't
> think this should happen.
>
> Bill
>
> On Sun, Jun 21, 2009 at 1:11 PM, indika kumara <in...@gmail.com>
> wrote:
>>
>> Hi Saliya
>>
>> This Use case scenario is related with XPath evaluation on the
>> resources picked from the registry. After reading the resource we
>> close input stream as it is needed.
>>
>> In this use case, parent is always an OMDocument.
>>
>> For both following code, you get ‘org.apache.axiom.om.OMException:
>> com.ctc.wstx.exc.WstxIOException: Stream closed’.
>>
>> 1)     remove result.detach()
>>
>> 2)     replace result.detach() with  result.build()
>>
>> (Please refers SimpleURLRegistry.java)
>>
>> Note that here ‘result = builder.getDocumentElement();’ and it is not
>> builder.getDocument(). If It is possible to call build() method on
>> OMDocument this issue (‘Stream closed’) may not be occurred (I didn’t
>> look at AXIOM code).  As Andreas pointed out ‘OMDocument has no method
>> to build the entire tree and detach() do that as a side effect”.
>>
>> I didn't look at deep but feel current possible solutions are what
>> Andreas suggested.
>>
>> Thanks
>> Indika
>>
>> On Sun, Jun 21, 2009 at 5:31 PM, Saliya Ekanayake <es...@gmail.com>
>> wrote:
>> >
>> > Hi Indika,
>> >
>> > I tested your point and found the cause. Simply, in the second case
>> > there is no parent for the root element. Therefore, evaluating an XPath
>> > containing <hello> element will cause an exception. But if you evaluate an
>> > XPath like, //anotherthing/insideanother, you will get the desired result.
>> >
>> > So the solution I would like to suggest in this case is to first check
>> > the parent of the element. If the parent is an instance of OMDocument then
>> > we need not detach (if you need to build then just use OMNode#build()). If
>> > the parent is an instance of OMElement then you need to detach since you
>> > want the element to be isolated from the connecting tree.
>> >
>> > Thanks,
>> > Saliya
>> >
>> > On Sun, Jun 21, 2009 at 11:06 AM, indika kumara <in...@gmail.com>
>> > wrote:
>> >>
>> >>         Hi Saliya
>> >>
>> >>         Following shown my scenarios.
>> >>
>> >>
>> >>        Scenario 1  - without detach on root element
>> >>
>> >>         String str = "<hello><something>wow
>> >> nice</something><anotherthing><insideanother>great</insideanother></anotherthing></hello>";
>> >>         XMLStreamReader parser = XMLInputFactory.newInstance().
>> >>                 createXMLStreamReader(new
>> >> ByteArrayInputStream(str.getBytes()));
>> >>         StAXOMBuilder builder = new StAXOMBuilder(parser);
>> >>         OMElement root = builder.getDocumentElement();
>> >> //        root.detach();
>> >>
>> >>         AXIOMXPath xpath = new AXIOMXPath("//hello/something");
>> >>         OMElement node = (OMElement) xpath.selectSingleNode(root);
>> >>         System.out.println(node == null);
>> >>         if (node != null) {
>> >>             System.out.println(node.getText());
>> >>         }
>> >>
>> >>
>> >>       Out put :
>> >>
>> >>        false
>> >>        wow nice
>> >>
>> >>
>> >>        Scenario 2 - with  detach on root element
>> >>
>> >>         String str = "<hello><something>wow
>> >> nice</something><anotherthing><insideanother>great</insideanother></anotherthing></hello>";
>> >>         XMLStreamReader parser = XMLInputFactory.newInstance().
>> >>                 createXMLStreamReader(new
>> >> ByteArrayInputStream(str.getBytes()));
>> >>         StAXOMBuilder builder = new StAXOMBuilder(parser);
>> >>         OMElement root = builder.getDocumentElement();
>> >>         root.detach();
>> >>
>> >>         AXIOMXPath xpath = new AXIOMXPath("//hello/something");
>> >>         OMElement node = (OMElement) xpath.selectSingleNode(root);
>> >>         System.out.println(node == null);
>> >>         if (node != null) {
>> >>             System.out.println(node.getText());
>> >>         }
>> >>
>> >>        Output
>> >>
>> >>        true
>> >>
>> >>
>> >>    In second case , XPath  have not been evaluated correctly.
>> >>
>> >> Thanks
>> >> Indika
>> >>
>> >> On Sat, Jun 20, 2009 at 9:40 PM, Saliya Ekanayake <es...@gmail.com>
>> >> wrote:
>> >>>
>> >>> Hi,
>> >>>
>> >>> Um, I am not really clarified with the problem here. I agree that the
>> >>> full tree should be built before we can evaluate XPath. Adding the element
>> >>> to a new OMDocument, however, just to get this done seems not right.
>> >>> Additionally, the original OMDocument created by the builder will be there
>> >>> even if you detach the element. Detach will only remove the element from the
>> >>> tree to which it belongs. To check this, you can get the builder from the
>> >>> detached element and ask for the OMDocument.  IMHO, we can call
>> >>> result.build() if necessary.
>> >>>
>> >>> Btw. I am not clear why XPath doesn't work on the detached element. I
>> >>> did a simple test as follows and XPath worked, may be I have missed
>> >>> something (please let me know if so).
>> >>>
>> >>>     public static void main(String[] args) throws XMLStreamException,
>> >>> JaxenException {
>> >>>         String str = "<hello><something>wow
>> >>> nice</something><anotherthing><insideanother>great</insideanother></anotherthing></hello>";
>> >>>         StAXOMBuilder builder = new StAXOMBuilder(new
>> >>> ByteArrayInputStream(str.getBytes()));
>> >>>         OMElement root = builder.getDocumentElement();
>> >>>
>> >>>         OMDocument doc = builder.getDocument();
>> >>>         System.out.println(doc == null);
>> >>>
>> >>>         OMElement anotherthing = root.getFirstChildWithName(new
>> >>> QName("anotherthing"));
>> >>>         anotherthing.detach();
>> >>>
>> >>>         doc =
>> >>> ((StAXOMBuilder)anotherthing.getBuilder()).getDocument();
>> >>>         System.out.println(doc == null);
>> >>>
>> >>>         AXIOMXPath xpath = new AXIOMXPath("//insideanother");
>> >>>         OMElement node = (OMElement)
>> >>> xpath.selectSingleNode(anotherthing);
>> >>>         System.out.println(node.getText());
>> >>>     }
>> >>>
>> >>> Thanks,
>> >>> Saliya
>> >>>
>> >>> On Sat, Jun 20, 2009 at 4:45 AM, Andreas Veithen
>> >>> <an...@gmail.com> wrote:
>> >>>>
>> >>>> StAXOMBuilder actually already creates an OMDocument (which can be
>> >>>> retrieved by the getDocument method). The important thing is that we
>> >>>> need to make sure that the Axiom tree is fully built before closing
>> >>>> the input stream. I guess that the detach method is used because it
>> >>>> has the side effect of fully building the element and because
>> >>>> OMDocument has no method to build the entire tree (see
>> >>>> WSCOMMONS-479).
>> >>>>
>> >>>> This gives us two solutions:
>> >>>>
>> >>>> - Use StAXOMBuilder#getDocument and iterate over its children to make
>> >>>> sure the document is fully built.
>> >>>> - Continue to use "detach" and add the element to a new document, as
>> >>>> you suggested. Note that you should not use OMDocumentImpl directly,
>> >>>> but create it using the OMFactory.
>> >>>>
>> >>>> Andreas
>> >>>>
>> >>>> On Fri, Jun 19, 2009 at 09:30, indika kumara<in...@gmail.com>
>> >>>> wrote:
>> >>>> > Devs
>> >>>> >
>> >>>> > $subject is due to we do  'detach()'  on picked resource OMElement
>> >>>> > .
>> >>>> > If I add detached element to a OMDocument as a child, it works
>> >>>> >
>> >>>> > Existing code  SImpleURLRegistry
>> >>>> >
>> >>>> > result.detach();
>> >>>> > inputStream.close();
>> >>>> >
>> >>>> >
>> >>>> > Modified code
>> >>>> >
>> >>>> > result.detach();
>> >>>> > OMDocumentImpl omDocument = new OMDocumentImpl();
>> >>>> > omDocument.addChild(result);
>> >>>> > inputStream.close();
>> >>>> >
>> >>>> >
>> >>>> > Are there any best solution other than what I did ?  I haven't deep
>> >>>> > AXIOM knowledge?  Could anyone help me?
>> >>>> >
>> >>>> > Thanks
>> >>>> > Indika
>> >>>> >
>> >>>> >
>> >>>> > ---------------------------------------------------------------------
>> >>>> > To unsubscribe, e-mail: dev-unsubscribe@synapse.apache.org
>> >>>> > For additional commands, e-mail: dev-help@synapse.apache.org
>> >>>> >
>> >>>> >
>> >>>>
>> >>>> ---------------------------------------------------------------------
>> >>>> To unsubscribe, e-mail: dev-unsubscribe@synapse.apache.org
>> >>>> For additional commands, e-mail: dev-help@synapse.apache.org
>> >>>>
>> >>>
>> >>>
>> >>>
>> >>> --
>> >>> Saliya Ekanayake
>> >>> http://www.esaliya.blogspot.com
>> >>> http://www.esaliya.wordpress.com
>> >>
>> >
>> >
>> >
>> > --
>> > Saliya Ekanayake
>> > http://www.esaliya.blogspot.com
>> > http://www.esaliya.wordpress.com
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: dev-unsubscribe@synapse.apache.org
>> For additional commands, e-mail: dev-help@synapse.apache.org
>>
>
>

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


Re: XPath evaluation doesn't work on resources picked from registry

Posted by Bill Harts <pr...@gmail.com>.
I will try to debug it today.
Bill

On Tue, Jun 23, 2009 at 1:07 AM, indika kumara <in...@gmail.com>wrote:

> But bill my change only with resources picked from the registry. This issue
> seems with XPath on Payload ...It is impossible to correlate those two .
> Could you re-check please?
>
> On Tue, Jun 23, 2009 at 10:34 AM, indika kumara <in...@gmail.com>wrote:
>
>>
>> Bill I will check .. Thanks for pointing out issue .
>>
>> Thanks
>> Inidka
>>
>> On Tue, Jun 23, 2009 at 2:58 AM, Bill Harts <pr...@gmail.com> wrote:
>>
>>> Hi Guys:
>>>
>>> I'm not sure but I believe something has broken with using xpath
>>> expressions in a log mediator possibly related to your recent changes.  I
>>> think this was working until I downloaded yesterday's snapshot I was using a
>>> 3-week old snapshot).
>>>
>>> Here's the code from my my mediator file:
>>>
>>> <!-- If there's a sessionID attribute in the message this must be a response to a Login -->
>>> <filter xpath="boolean(//cfl:LoginResponse/cfl:LoginResponseData/@sessionID)" xmlns:cfl="http://www.harts.com/cfl" >
>>>
>>>
>>>      <log level="custom">
>>>
>>>
>>>          <property name="sessID" expression="//cfl:LoginResponse/cfl:LoginResponseData/@sessionID" xmlns:cfl="http://www.harts.com/cfl"/>
>>>
>>>
>>>      </log>
>>>
>>>      <!-- Other logic goes here -->
>>>
>>>
>>> </filter>
>>>
>>> It passes the filter test but the log mediator just displays "sessID=".
>>> Since the expressions in the filter and log mediators are the same I don't
>>> think this should happen.
>>>
>>> Bill
>>>
>>>
>>> On Sun, Jun 21, 2009 at 1:11 PM, indika kumara <in...@gmail.com>wrote:
>>>
>>>> Hi Saliya
>>>>
>>>> This Use case scenario is related with XPath evaluation on the
>>>> resources picked from the registry. After reading the resource we
>>>> close input stream as it is needed.
>>>>
>>>> In this use case, parent is always an OMDocument.
>>>>
>>>> For both following code, you get ‘org.apache.axiom.om.OMException:
>>>> com.ctc.wstx.exc.WstxIOException: Stream closed’.
>>>>
>>>> 1)     remove result.detach()
>>>>
>>>> 2)     replace result.detach() with  result.build()
>>>>
>>>> (Please refers SimpleURLRegistry.java)
>>>>
>>>> Note that here ‘result = builder.getDocumentElement();’ and it is not
>>>> builder.getDocument(). If It is possible to call build() method on
>>>> OMDocument this issue (‘Stream closed’) may not be occurred (I didn’t
>>>> look at AXIOM code).  As Andreas pointed out ‘OMDocument has no method
>>>> to build the entire tree and detach() do that as a side effect”.
>>>>
>>>> I didn't look at deep but feel current possible solutions are what
>>>> Andreas suggested.
>>>>
>>>> Thanks
>>>> Indika
>>>>
>>>> On Sun, Jun 21, 2009 at 5:31 PM, Saliya Ekanayake <es...@gmail.com>
>>>> wrote:
>>>> >
>>>> > Hi Indika,
>>>> >
>>>> > I tested your point and found the cause. Simply, in the second case
>>>> there is no parent for the root element. Therefore, evaluating an XPath
>>>> containing <hello> element will cause an exception. But if you evaluate an
>>>> XPath like, //anotherthing/insideanother, you will get the desired result.
>>>> >
>>>> > So the solution I would like to suggest in this case is to first check
>>>> the parent of the element. If the parent is an instance of OMDocument then
>>>> we need not detach (if you need to build then just use OMNode#build()). If
>>>> the parent is an instance of OMElement then you need to detach since you
>>>> want the element to be isolated from the connecting tree.
>>>> >
>>>> > Thanks,
>>>> > Saliya
>>>> >
>>>> > On Sun, Jun 21, 2009 at 11:06 AM, indika kumara <
>>>> indika.kuma@gmail.com> wrote:
>>>> >>
>>>> >>         Hi Saliya
>>>> >>
>>>> >>         Following shown my scenarios.
>>>> >>
>>>> >>
>>>> >>        Scenario 1  - without detach on root element
>>>> >>
>>>> >>         String str = "<hello><something>wow
>>>> nice</something><anotherthing><insideanother>great</insideanother></anotherthing></hello>";
>>>> >>         XMLStreamReader parser = XMLInputFactory.newInstance().
>>>> >>                 createXMLStreamReader(new
>>>> ByteArrayInputStream(str.getBytes()));
>>>> >>         StAXOMBuilder builder = new StAXOMBuilder(parser);
>>>> >>         OMElement root = builder.getDocumentElement();
>>>> >> //        root.detach();
>>>> >>
>>>> >>         AXIOMXPath xpath = new AXIOMXPath("//hello/something");
>>>> >>         OMElement node = (OMElement) xpath.selectSingleNode(root);
>>>> >>         System.out.println(node == null);
>>>> >>         if (node != null) {
>>>> >>             System.out.println(node.getText());
>>>> >>         }
>>>> >>
>>>> >>
>>>> >>       Out put :
>>>> >>
>>>> >>        false
>>>> >>        wow nice
>>>> >>
>>>> >>
>>>> >>        Scenario 2 - with  detach on root element
>>>> >>
>>>> >>         String str = "<hello><something>wow
>>>> nice</something><anotherthing><insideanother>great</insideanother></anotherthing></hello>";
>>>> >>         XMLStreamReader parser = XMLInputFactory.newInstance().
>>>> >>                 createXMLStreamReader(new
>>>> ByteArrayInputStream(str.getBytes()));
>>>> >>         StAXOMBuilder builder = new StAXOMBuilder(parser);
>>>> >>         OMElement root = builder.getDocumentElement();
>>>> >>         root.detach();
>>>> >>
>>>> >>         AXIOMXPath xpath = new AXIOMXPath("//hello/something");
>>>> >>         OMElement node = (OMElement) xpath.selectSingleNode(root);
>>>> >>         System.out.println(node == null);
>>>> >>         if (node != null) {
>>>> >>             System.out.println(node.getText());
>>>> >>         }
>>>> >>
>>>> >>        Output
>>>> >>
>>>> >>        true
>>>> >>
>>>> >>
>>>> >>    In second case , XPath  have not been evaluated correctly.
>>>> >>
>>>> >> Thanks
>>>> >> Indika
>>>> >>
>>>> >> On Sat, Jun 20, 2009 at 9:40 PM, Saliya Ekanayake <es...@gmail.com>
>>>> wrote:
>>>> >>>
>>>> >>> Hi,
>>>> >>>
>>>> >>> Um, I am not really clarified with the problem here. I agree that
>>>> the full tree should be built before we can evaluate XPath. Adding the
>>>> element to a new OMDocument, however, just to get this done seems not right.
>>>> Additionally, the original OMDocument created by the builder will be there
>>>> even if you detach the element. Detach will only remove the element from the
>>>> tree to which it belongs. To check this, you can get the builder from the
>>>> detached element and ask for the OMDocument.  IMHO, we can call
>>>> result.build() if necessary.
>>>> >>>
>>>> >>> Btw. I am not clear why XPath doesn't work on the detached element.
>>>> I did a simple test as follows and XPath worked, may be I have missed
>>>> something (please let me know if so).
>>>> >>>
>>>> >>>     public static void main(String[] args) throws
>>>> XMLStreamException, JaxenException {
>>>> >>>         String str = "<hello><something>wow
>>>> nice</something><anotherthing><insideanother>great</insideanother></anotherthing></hello>";
>>>> >>>         StAXOMBuilder builder = new StAXOMBuilder(new
>>>> ByteArrayInputStream(str.getBytes()));
>>>> >>>         OMElement root = builder.getDocumentElement();
>>>> >>>
>>>> >>>         OMDocument doc = builder.getDocument();
>>>> >>>         System.out.println(doc == null);
>>>> >>>
>>>> >>>         OMElement anotherthing = root.getFirstChildWithName(new
>>>> QName("anotherthing"));
>>>> >>>         anotherthing.detach();
>>>> >>>
>>>> >>>         doc =
>>>> ((StAXOMBuilder)anotherthing.getBuilder()).getDocument();
>>>> >>>         System.out.println(doc == null);
>>>> >>>
>>>> >>>         AXIOMXPath xpath = new AXIOMXPath("//insideanother");
>>>> >>>         OMElement node = (OMElement)
>>>> xpath.selectSingleNode(anotherthing);
>>>> >>>         System.out.println(node.getText());
>>>> >>>     }
>>>> >>>
>>>> >>> Thanks,
>>>> >>> Saliya
>>>> >>>
>>>> >>> On Sat, Jun 20, 2009 at 4:45 AM, Andreas Veithen <
>>>> andreas.veithen@gmail.com> wrote:
>>>> >>>>
>>>> >>>> StAXOMBuilder actually already creates an OMDocument (which can be
>>>> >>>> retrieved by the getDocument method). The important thing is that
>>>> we
>>>> >>>> need to make sure that the Axiom tree is fully built before closing
>>>> >>>> the input stream. I guess that the detach method is used because it
>>>> >>>> has the side effect of fully building the element and because
>>>> >>>> OMDocument has no method to build the entire tree (see
>>>> WSCOMMONS-479).
>>>> >>>>
>>>> >>>> This gives us two solutions:
>>>> >>>>
>>>> >>>> - Use StAXOMBuilder#getDocument and iterate over its children to
>>>> make
>>>> >>>> sure the document is fully built.
>>>> >>>> - Continue to use "detach" and add the element to a new document,
>>>> as
>>>> >>>> you suggested. Note that you should not use OMDocumentImpl
>>>> directly,
>>>> >>>> but create it using the OMFactory.
>>>> >>>>
>>>> >>>> Andreas
>>>> >>>>
>>>> >>>> On Fri, Jun 19, 2009 at 09:30, indika kumara<in...@gmail.com>
>>>> wrote:
>>>> >>>> > Devs
>>>> >>>> >
>>>> >>>> > $subject is due to we do  'detach()'  on picked resource
>>>> OMElement .
>>>> >>>> > If I add detached element to a OMDocument as a child, it works
>>>> >>>> >
>>>> >>>> > Existing code  SImpleURLRegistry
>>>> >>>> >
>>>> >>>> > result.detach();
>>>> >>>> > inputStream.close();
>>>> >>>> >
>>>> >>>> >
>>>> >>>> > Modified code
>>>> >>>> >
>>>> >>>> > result.detach();
>>>> >>>> > OMDocumentImpl omDocument = new OMDocumentImpl();
>>>> >>>> > omDocument.addChild(result);
>>>> >>>> > inputStream.close();
>>>> >>>> >
>>>> >>>> >
>>>> >>>> > Are there any best solution other than what I did ?  I haven't
>>>> deep
>>>> >>>> > AXIOM knowledge?  Could anyone help me?
>>>> >>>> >
>>>> >>>> > Thanks
>>>> >>>> > Indika
>>>> >>>> >
>>>> >>>> >
>>>> ---------------------------------------------------------------------
>>>> >>>> > To unsubscribe, e-mail: dev-unsubscribe@synapse.apache.org
>>>> >>>> > For additional commands, e-mail: dev-help@synapse.apache.org
>>>> >>>> >
>>>> >>>> >
>>>> >>>>
>>>> >>>>
>>>> ---------------------------------------------------------------------
>>>> >>>> To unsubscribe, e-mail: dev-unsubscribe@synapse.apache.org
>>>> >>>> For additional commands, e-mail: dev-help@synapse.apache.org
>>>> >>>>
>>>> >>>
>>>> >>>
>>>> >>>
>>>> >>> --
>>>> >>> Saliya Ekanayake
>>>> >>> http://www.esaliya.blogspot.com
>>>> >>> http://www.esaliya.wordpress.com
>>>> >>
>>>> >
>>>> >
>>>> >
>>>> > --
>>>> > Saliya Ekanayake
>>>> > http://www.esaliya.blogspot.com
>>>> > http://www.esaliya.wordpress.com
>>>>
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: dev-unsubscribe@synapse.apache.org
>>>> For additional commands, e-mail: dev-help@synapse.apache.org
>>>>
>>>>
>>>
>>
>

Re: XPath evaluation doesn't work on resources picked from registry

Posted by indika kumara <in...@gmail.com>.
But bill my change only with resources picked from the registry. This issue
seems with XPath on Payload ...It is impossible to correlate those two .
Could you re-check please?

On Tue, Jun 23, 2009 at 10:34 AM, indika kumara <in...@gmail.com>wrote:

>
> Bill I will check .. Thanks for pointing out issue .
>
> Thanks
> Inidka
>
> On Tue, Jun 23, 2009 at 2:58 AM, Bill Harts <pr...@gmail.com> wrote:
>
>> Hi Guys:
>>
>> I'm not sure but I believe something has broken with using xpath
>> expressions in a log mediator possibly related to your recent changes.  I
>> think this was working until I downloaded yesterday's snapshot I was using a
>> 3-week old snapshot).
>>
>> Here's the code from my my mediator file:
>>
>> <!-- If there's a sessionID attribute in the message this must be a response to a Login -->
>> <filter xpath="boolean(//cfl:LoginResponse/cfl:LoginResponseData/@sessionID)" xmlns:cfl="http://www.harts.com/cfl" >
>>
>>      <log level="custom">
>>
>>          <property name="sessID" expression="//cfl:LoginResponse/cfl:LoginResponseData/@sessionID" xmlns:cfl="http://www.harts.com/cfl"/>
>>
>>      </log>
>>
>>      <!-- Other logic goes here -->
>>
>> </filter>
>>
>> It passes the filter test but the log mediator just displays "sessID=".
>> Since the expressions in the filter and log mediators are the same I don't
>> think this should happen.
>>
>> Bill
>>
>>
>> On Sun, Jun 21, 2009 at 1:11 PM, indika kumara <in...@gmail.com>wrote:
>>
>>> Hi Saliya
>>>
>>> This Use case scenario is related with XPath evaluation on the
>>> resources picked from the registry. After reading the resource we
>>> close input stream as it is needed.
>>>
>>> In this use case, parent is always an OMDocument.
>>>
>>> For both following code, you get ‘org.apache.axiom.om.OMException:
>>> com.ctc.wstx.exc.WstxIOException: Stream closed’.
>>>
>>> 1)     remove result.detach()
>>>
>>> 2)     replace result.detach() with  result.build()
>>>
>>> (Please refers SimpleURLRegistry.java)
>>>
>>> Note that here ‘result = builder.getDocumentElement();’ and it is not
>>> builder.getDocument(). If It is possible to call build() method on
>>> OMDocument this issue (‘Stream closed’) may not be occurred (I didn’t
>>> look at AXIOM code).  As Andreas pointed out ‘OMDocument has no method
>>> to build the entire tree and detach() do that as a side effect”.
>>>
>>> I didn't look at deep but feel current possible solutions are what
>>> Andreas suggested.
>>>
>>> Thanks
>>> Indika
>>>
>>> On Sun, Jun 21, 2009 at 5:31 PM, Saliya Ekanayake <es...@gmail.com>
>>> wrote:
>>> >
>>> > Hi Indika,
>>> >
>>> > I tested your point and found the cause. Simply, in the second case
>>> there is no parent for the root element. Therefore, evaluating an XPath
>>> containing <hello> element will cause an exception. But if you evaluate an
>>> XPath like, //anotherthing/insideanother, you will get the desired result.
>>> >
>>> > So the solution I would like to suggest in this case is to first check
>>> the parent of the element. If the parent is an instance of OMDocument then
>>> we need not detach (if you need to build then just use OMNode#build()). If
>>> the parent is an instance of OMElement then you need to detach since you
>>> want the element to be isolated from the connecting tree.
>>> >
>>> > Thanks,
>>> > Saliya
>>> >
>>> > On Sun, Jun 21, 2009 at 11:06 AM, indika kumara <in...@gmail.com>
>>> wrote:
>>> >>
>>> >>         Hi Saliya
>>> >>
>>> >>         Following shown my scenarios.
>>> >>
>>> >>
>>> >>        Scenario 1  - without detach on root element
>>> >>
>>> >>         String str = "<hello><something>wow
>>> nice</something><anotherthing><insideanother>great</insideanother></anotherthing></hello>";
>>> >>         XMLStreamReader parser = XMLInputFactory.newInstance().
>>> >>                 createXMLStreamReader(new
>>> ByteArrayInputStream(str.getBytes()));
>>> >>         StAXOMBuilder builder = new StAXOMBuilder(parser);
>>> >>         OMElement root = builder.getDocumentElement();
>>> >> //        root.detach();
>>> >>
>>> >>         AXIOMXPath xpath = new AXIOMXPath("//hello/something");
>>> >>         OMElement node = (OMElement) xpath.selectSingleNode(root);
>>> >>         System.out.println(node == null);
>>> >>         if (node != null) {
>>> >>             System.out.println(node.getText());
>>> >>         }
>>> >>
>>> >>
>>> >>       Out put :
>>> >>
>>> >>        false
>>> >>        wow nice
>>> >>
>>> >>
>>> >>        Scenario 2 - with  detach on root element
>>> >>
>>> >>         String str = "<hello><something>wow
>>> nice</something><anotherthing><insideanother>great</insideanother></anotherthing></hello>";
>>> >>         XMLStreamReader parser = XMLInputFactory.newInstance().
>>> >>                 createXMLStreamReader(new
>>> ByteArrayInputStream(str.getBytes()));
>>> >>         StAXOMBuilder builder = new StAXOMBuilder(parser);
>>> >>         OMElement root = builder.getDocumentElement();
>>> >>         root.detach();
>>> >>
>>> >>         AXIOMXPath xpath = new AXIOMXPath("//hello/something");
>>> >>         OMElement node = (OMElement) xpath.selectSingleNode(root);
>>> >>         System.out.println(node == null);
>>> >>         if (node != null) {
>>> >>             System.out.println(node.getText());
>>> >>         }
>>> >>
>>> >>        Output
>>> >>
>>> >>        true
>>> >>
>>> >>
>>> >>    In second case , XPath  have not been evaluated correctly.
>>> >>
>>> >> Thanks
>>> >> Indika
>>> >>
>>> >> On Sat, Jun 20, 2009 at 9:40 PM, Saliya Ekanayake <es...@gmail.com>
>>> wrote:
>>> >>>
>>> >>> Hi,
>>> >>>
>>> >>> Um, I am not really clarified with the problem here. I agree that the
>>> full tree should be built before we can evaluate XPath. Adding the element
>>> to a new OMDocument, however, just to get this done seems not right.
>>> Additionally, the original OMDocument created by the builder will be there
>>> even if you detach the element. Detach will only remove the element from the
>>> tree to which it belongs. To check this, you can get the builder from the
>>> detached element and ask for the OMDocument.  IMHO, we can call
>>> result.build() if necessary.
>>> >>>
>>> >>> Btw. I am not clear why XPath doesn't work on the detached element. I
>>> did a simple test as follows and XPath worked, may be I have missed
>>> something (please let me know if so).
>>> >>>
>>> >>>     public static void main(String[] args) throws XMLStreamException,
>>> JaxenException {
>>> >>>         String str = "<hello><something>wow
>>> nice</something><anotherthing><insideanother>great</insideanother></anotherthing></hello>";
>>> >>>         StAXOMBuilder builder = new StAXOMBuilder(new
>>> ByteArrayInputStream(str.getBytes()));
>>> >>>         OMElement root = builder.getDocumentElement();
>>> >>>
>>> >>>         OMDocument doc = builder.getDocument();
>>> >>>         System.out.println(doc == null);
>>> >>>
>>> >>>         OMElement anotherthing = root.getFirstChildWithName(new
>>> QName("anotherthing"));
>>> >>>         anotherthing.detach();
>>> >>>
>>> >>>         doc =
>>> ((StAXOMBuilder)anotherthing.getBuilder()).getDocument();
>>> >>>         System.out.println(doc == null);
>>> >>>
>>> >>>         AXIOMXPath xpath = new AXIOMXPath("//insideanother");
>>> >>>         OMElement node = (OMElement)
>>> xpath.selectSingleNode(anotherthing);
>>> >>>         System.out.println(node.getText());
>>> >>>     }
>>> >>>
>>> >>> Thanks,
>>> >>> Saliya
>>> >>>
>>> >>> On Sat, Jun 20, 2009 at 4:45 AM, Andreas Veithen <
>>> andreas.veithen@gmail.com> wrote:
>>> >>>>
>>> >>>> StAXOMBuilder actually already creates an OMDocument (which can be
>>> >>>> retrieved by the getDocument method). The important thing is that we
>>> >>>> need to make sure that the Axiom tree is fully built before closing
>>> >>>> the input stream. I guess that the detach method is used because it
>>> >>>> has the side effect of fully building the element and because
>>> >>>> OMDocument has no method to build the entire tree (see
>>> WSCOMMONS-479).
>>> >>>>
>>> >>>> This gives us two solutions:
>>> >>>>
>>> >>>> - Use StAXOMBuilder#getDocument and iterate over its children to
>>> make
>>> >>>> sure the document is fully built.
>>> >>>> - Continue to use "detach" and add the element to a new document, as
>>> >>>> you suggested. Note that you should not use OMDocumentImpl directly,
>>> >>>> but create it using the OMFactory.
>>> >>>>
>>> >>>> Andreas
>>> >>>>
>>> >>>> On Fri, Jun 19, 2009 at 09:30, indika kumara<in...@gmail.com>
>>> wrote:
>>> >>>> > Devs
>>> >>>> >
>>> >>>> > $subject is due to we do  'detach()'  on picked resource OMElement
>>> .
>>> >>>> > If I add detached element to a OMDocument as a child, it works
>>> >>>> >
>>> >>>> > Existing code  SImpleURLRegistry
>>> >>>> >
>>> >>>> > result.detach();
>>> >>>> > inputStream.close();
>>> >>>> >
>>> >>>> >
>>> >>>> > Modified code
>>> >>>> >
>>> >>>> > result.detach();
>>> >>>> > OMDocumentImpl omDocument = new OMDocumentImpl();
>>> >>>> > omDocument.addChild(result);
>>> >>>> > inputStream.close();
>>> >>>> >
>>> >>>> >
>>> >>>> > Are there any best solution other than what I did ?  I haven't
>>> deep
>>> >>>> > AXIOM knowledge?  Could anyone help me?
>>> >>>> >
>>> >>>> > Thanks
>>> >>>> > Indika
>>> >>>> >
>>> >>>> >
>>> ---------------------------------------------------------------------
>>> >>>> > To unsubscribe, e-mail: dev-unsubscribe@synapse.apache.org
>>> >>>> > For additional commands, e-mail: dev-help@synapse.apache.org
>>> >>>> >
>>> >>>> >
>>> >>>>
>>> >>>>
>>> ---------------------------------------------------------------------
>>> >>>> To unsubscribe, e-mail: dev-unsubscribe@synapse.apache.org
>>> >>>> For additional commands, e-mail: dev-help@synapse.apache.org
>>> >>>>
>>> >>>
>>> >>>
>>> >>>
>>> >>> --
>>> >>> Saliya Ekanayake
>>> >>> http://www.esaliya.blogspot.com
>>> >>> http://www.esaliya.wordpress.com
>>> >>
>>> >
>>> >
>>> >
>>> > --
>>> > Saliya Ekanayake
>>> > http://www.esaliya.blogspot.com
>>> > http://www.esaliya.wordpress.com
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: dev-unsubscribe@synapse.apache.org
>>> For additional commands, e-mail: dev-help@synapse.apache.org
>>>
>>>
>>
>

Re: XPath evaluation doesn't work on resources picked from registry

Posted by indika kumara <in...@gmail.com>.
Bill I will check .. Thanks for pointing out issue .

Thanks
Inidka

On Tue, Jun 23, 2009 at 2:58 AM, Bill Harts <pr...@gmail.com> wrote:

> Hi Guys:
>
> I'm not sure but I believe something has broken with using xpath
> expressions in a log mediator possibly related to your recent changes.  I
> think this was working until I downloaded yesterday's snapshot I was using a
> 3-week old snapshot).
>
> Here's the code from my my mediator file:
>
> <!-- If there's a sessionID attribute in the message this must be a response to a Login -->
> <filter xpath="boolean(//cfl:LoginResponse/cfl:LoginResponseData/@sessionID)" xmlns:cfl="http://www.harts.com/cfl" >
>      <log level="custom">
>          <property name="sessID" expression="//cfl:LoginResponse/cfl:LoginResponseData/@sessionID" xmlns:cfl="http://www.harts.com/cfl"/>
>      </log>
>
>      <!-- Other logic goes here -->
> </filter>
>
> It passes the filter test but the log mediator just displays "sessID=".
> Since the expressions in the filter and log mediators are the same I don't
> think this should happen.
>
> Bill
>
>
> On Sun, Jun 21, 2009 at 1:11 PM, indika kumara <in...@gmail.com>wrote:
>
>> Hi Saliya
>>
>> This Use case scenario is related with XPath evaluation on the
>> resources picked from the registry. After reading the resource we
>> close input stream as it is needed.
>>
>> In this use case, parent is always an OMDocument.
>>
>> For both following code, you get ‘org.apache.axiom.om.OMException:
>> com.ctc.wstx.exc.WstxIOException: Stream closed’.
>>
>> 1)     remove result.detach()
>>
>> 2)     replace result.detach() with  result.build()
>>
>> (Please refers SimpleURLRegistry.java)
>>
>> Note that here ‘result = builder.getDocumentElement();’ and it is not
>> builder.getDocument(). If It is possible to call build() method on
>> OMDocument this issue (‘Stream closed’) may not be occurred (I didn’t
>> look at AXIOM code).  As Andreas pointed out ‘OMDocument has no method
>> to build the entire tree and detach() do that as a side effect”.
>>
>> I didn't look at deep but feel current possible solutions are what
>> Andreas suggested.
>>
>> Thanks
>> Indika
>>
>> On Sun, Jun 21, 2009 at 5:31 PM, Saliya Ekanayake <es...@gmail.com>
>> wrote:
>> >
>> > Hi Indika,
>> >
>> > I tested your point and found the cause. Simply, in the second case
>> there is no parent for the root element. Therefore, evaluating an XPath
>> containing <hello> element will cause an exception. But if you evaluate an
>> XPath like, //anotherthing/insideanother, you will get the desired result.
>> >
>> > So the solution I would like to suggest in this case is to first check
>> the parent of the element. If the parent is an instance of OMDocument then
>> we need not detach (if you need to build then just use OMNode#build()). If
>> the parent is an instance of OMElement then you need to detach since you
>> want the element to be isolated from the connecting tree.
>> >
>> > Thanks,
>> > Saliya
>> >
>> > On Sun, Jun 21, 2009 at 11:06 AM, indika kumara <in...@gmail.com>
>> wrote:
>> >>
>> >>         Hi Saliya
>> >>
>> >>         Following shown my scenarios.
>> >>
>> >>
>> >>        Scenario 1  - without detach on root element
>> >>
>> >>         String str = "<hello><something>wow
>> nice</something><anotherthing><insideanother>great</insideanother></anotherthing></hello>";
>> >>         XMLStreamReader parser = XMLInputFactory.newInstance().
>> >>                 createXMLStreamReader(new
>> ByteArrayInputStream(str.getBytes()));
>> >>         StAXOMBuilder builder = new StAXOMBuilder(parser);
>> >>         OMElement root = builder.getDocumentElement();
>> >> //        root.detach();
>> >>
>> >>         AXIOMXPath xpath = new AXIOMXPath("//hello/something");
>> >>         OMElement node = (OMElement) xpath.selectSingleNode(root);
>> >>         System.out.println(node == null);
>> >>         if (node != null) {
>> >>             System.out.println(node.getText());
>> >>         }
>> >>
>> >>
>> >>       Out put :
>> >>
>> >>        false
>> >>        wow nice
>> >>
>> >>
>> >>        Scenario 2 - with  detach on root element
>> >>
>> >>         String str = "<hello><something>wow
>> nice</something><anotherthing><insideanother>great</insideanother></anotherthing></hello>";
>> >>         XMLStreamReader parser = XMLInputFactory.newInstance().
>> >>                 createXMLStreamReader(new
>> ByteArrayInputStream(str.getBytes()));
>> >>         StAXOMBuilder builder = new StAXOMBuilder(parser);
>> >>         OMElement root = builder.getDocumentElement();
>> >>         root.detach();
>> >>
>> >>         AXIOMXPath xpath = new AXIOMXPath("//hello/something");
>> >>         OMElement node = (OMElement) xpath.selectSingleNode(root);
>> >>         System.out.println(node == null);
>> >>         if (node != null) {
>> >>             System.out.println(node.getText());
>> >>         }
>> >>
>> >>        Output
>> >>
>> >>        true
>> >>
>> >>
>> >>    In second case , XPath  have not been evaluated correctly.
>> >>
>> >> Thanks
>> >> Indika
>> >>
>> >> On Sat, Jun 20, 2009 at 9:40 PM, Saliya Ekanayake <es...@gmail.com>
>> wrote:
>> >>>
>> >>> Hi,
>> >>>
>> >>> Um, I am not really clarified with the problem here. I agree that the
>> full tree should be built before we can evaluate XPath. Adding the element
>> to a new OMDocument, however, just to get this done seems not right.
>> Additionally, the original OMDocument created by the builder will be there
>> even if you detach the element. Detach will only remove the element from the
>> tree to which it belongs. To check this, you can get the builder from the
>> detached element and ask for the OMDocument.  IMHO, we can call
>> result.build() if necessary.
>> >>>
>> >>> Btw. I am not clear why XPath doesn't work on the detached element. I
>> did a simple test as follows and XPath worked, may be I have missed
>> something (please let me know if so).
>> >>>
>> >>>     public static void main(String[] args) throws XMLStreamException,
>> JaxenException {
>> >>>         String str = "<hello><something>wow
>> nice</something><anotherthing><insideanother>great</insideanother></anotherthing></hello>";
>> >>>         StAXOMBuilder builder = new StAXOMBuilder(new
>> ByteArrayInputStream(str.getBytes()));
>> >>>         OMElement root = builder.getDocumentElement();
>> >>>
>> >>>         OMDocument doc = builder.getDocument();
>> >>>         System.out.println(doc == null);
>> >>>
>> >>>         OMElement anotherthing = root.getFirstChildWithName(new
>> QName("anotherthing"));
>> >>>         anotherthing.detach();
>> >>>
>> >>>         doc =
>> ((StAXOMBuilder)anotherthing.getBuilder()).getDocument();
>> >>>         System.out.println(doc == null);
>> >>>
>> >>>         AXIOMXPath xpath = new AXIOMXPath("//insideanother");
>> >>>         OMElement node = (OMElement)
>> xpath.selectSingleNode(anotherthing);
>> >>>         System.out.println(node.getText());
>> >>>     }
>> >>>
>> >>> Thanks,
>> >>> Saliya
>> >>>
>> >>> On Sat, Jun 20, 2009 at 4:45 AM, Andreas Veithen <
>> andreas.veithen@gmail.com> wrote:
>> >>>>
>> >>>> StAXOMBuilder actually already creates an OMDocument (which can be
>> >>>> retrieved by the getDocument method). The important thing is that we
>> >>>> need to make sure that the Axiom tree is fully built before closing
>> >>>> the input stream. I guess that the detach method is used because it
>> >>>> has the side effect of fully building the element and because
>> >>>> OMDocument has no method to build the entire tree (see
>> WSCOMMONS-479).
>> >>>>
>> >>>> This gives us two solutions:
>> >>>>
>> >>>> - Use StAXOMBuilder#getDocument and iterate over its children to make
>> >>>> sure the document is fully built.
>> >>>> - Continue to use "detach" and add the element to a new document, as
>> >>>> you suggested. Note that you should not use OMDocumentImpl directly,
>> >>>> but create it using the OMFactory.
>> >>>>
>> >>>> Andreas
>> >>>>
>> >>>> On Fri, Jun 19, 2009 at 09:30, indika kumara<in...@gmail.com>
>> wrote:
>> >>>> > Devs
>> >>>> >
>> >>>> > $subject is due to we do  'detach()'  on picked resource OMElement
>> .
>> >>>> > If I add detached element to a OMDocument as a child, it works
>> >>>> >
>> >>>> > Existing code  SImpleURLRegistry
>> >>>> >
>> >>>> > result.detach();
>> >>>> > inputStream.close();
>> >>>> >
>> >>>> >
>> >>>> > Modified code
>> >>>> >
>> >>>> > result.detach();
>> >>>> > OMDocumentImpl omDocument = new OMDocumentImpl();
>> >>>> > omDocument.addChild(result);
>> >>>> > inputStream.close();
>> >>>> >
>> >>>> >
>> >>>> > Are there any best solution other than what I did ?  I haven't deep
>> >>>> > AXIOM knowledge?  Could anyone help me?
>> >>>> >
>> >>>> > Thanks
>> >>>> > Indika
>> >>>> >
>> >>>> >
>> ---------------------------------------------------------------------
>> >>>> > To unsubscribe, e-mail: dev-unsubscribe@synapse.apache.org
>> >>>> > For additional commands, e-mail: dev-help@synapse.apache.org
>> >>>> >
>> >>>> >
>> >>>>
>> >>>> ---------------------------------------------------------------------
>> >>>> To unsubscribe, e-mail: dev-unsubscribe@synapse.apache.org
>> >>>> For additional commands, e-mail: dev-help@synapse.apache.org
>> >>>>
>> >>>
>> >>>
>> >>>
>> >>> --
>> >>> Saliya Ekanayake
>> >>> http://www.esaliya.blogspot.com
>> >>> http://www.esaliya.wordpress.com
>> >>
>> >
>> >
>> >
>> > --
>> > Saliya Ekanayake
>> > http://www.esaliya.blogspot.com
>> > http://www.esaliya.wordpress.com
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: dev-unsubscribe@synapse.apache.org
>> For additional commands, e-mail: dev-help@synapse.apache.org
>>
>>
>

Re: XPath evaluation doesn't work on resources picked from registry

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

I'm not sure but I believe something has broken with using xpath expressions
in a log mediator possibly related to your recent changes.  I think this was
working until I downloaded yesterday's snapshot I was using a 3-week old
snapshot).

Here's the code from my my mediator file:

<!-- If there's a sessionID attribute in the message this must be a
response to a Login -->
<filter xpath="boolean(//cfl:LoginResponse/cfl:LoginResponseData/@sessionID)"
xmlns:cfl="http://www.harts.com/cfl" >
     <log level="custom">
         <property name="sessID"
expression="//cfl:LoginResponse/cfl:LoginResponseData/@sessionID"
xmlns:cfl="http://www.harts.com/cfl"/>
     </log>

     <!-- Other logic goes here -->
</filter>

It passes the filter test but the log mediator just displays "sessID=".
Since the expressions in the filter and log mediators are the same I don't
think this should happen.

Bill

On Sun, Jun 21, 2009 at 1:11 PM, indika kumara <in...@gmail.com>wrote:

> Hi Saliya
>
> This Use case scenario is related with XPath evaluation on the
> resources picked from the registry. After reading the resource we
> close input stream as it is needed.
>
> In this use case, parent is always an OMDocument.
>
> For both following code, you get ‘org.apache.axiom.om.OMException:
> com.ctc.wstx.exc.WstxIOException: Stream closed’.
>
> 1)     remove result.detach()
>
> 2)     replace result.detach() with  result.build()
>
> (Please refers SimpleURLRegistry.java)
>
> Note that here ‘result = builder.getDocumentElement();’ and it is not
> builder.getDocument(). If It is possible to call build() method on
> OMDocument this issue (‘Stream closed’) may not be occurred (I didn’t
> look at AXIOM code).  As Andreas pointed out ‘OMDocument has no method
> to build the entire tree and detach() do that as a side effect”.
>
> I didn't look at deep but feel current possible solutions are what
> Andreas suggested.
>
> Thanks
> Indika
>
> On Sun, Jun 21, 2009 at 5:31 PM, Saliya Ekanayake <es...@gmail.com>
> wrote:
> >
> > Hi Indika,
> >
> > I tested your point and found the cause. Simply, in the second case there
> is no parent for the root element. Therefore, evaluating an XPath containing
> <hello> element will cause an exception. But if you evaluate an XPath like,
> //anotherthing/insideanother, you will get the desired result.
> >
> > So the solution I would like to suggest in this case is to first check
> the parent of the element. If the parent is an instance of OMDocument then
> we need not detach (if you need to build then just use OMNode#build()). If
> the parent is an instance of OMElement then you need to detach since you
> want the element to be isolated from the connecting tree.
> >
> > Thanks,
> > Saliya
> >
> > On Sun, Jun 21, 2009 at 11:06 AM, indika kumara <in...@gmail.com>
> wrote:
> >>
> >>         Hi Saliya
> >>
> >>         Following shown my scenarios.
> >>
> >>
> >>        Scenario 1  - without detach on root element
> >>
> >>         String str = "<hello><something>wow
> nice</something><anotherthing><insideanother>great</insideanother></anotherthing></hello>";
> >>         XMLStreamReader parser = XMLInputFactory.newInstance().
> >>                 createXMLStreamReader(new
> ByteArrayInputStream(str.getBytes()));
> >>         StAXOMBuilder builder = new StAXOMBuilder(parser);
> >>         OMElement root = builder.getDocumentElement();
> >> //        root.detach();
> >>
> >>         AXIOMXPath xpath = new AXIOMXPath("//hello/something");
> >>         OMElement node = (OMElement) xpath.selectSingleNode(root);
> >>         System.out.println(node == null);
> >>         if (node != null) {
> >>             System.out.println(node.getText());
> >>         }
> >>
> >>
> >>       Out put :
> >>
> >>        false
> >>        wow nice
> >>
> >>
> >>        Scenario 2 - with  detach on root element
> >>
> >>         String str = "<hello><something>wow
> nice</something><anotherthing><insideanother>great</insideanother></anotherthing></hello>";
> >>         XMLStreamReader parser = XMLInputFactory.newInstance().
> >>                 createXMLStreamReader(new
> ByteArrayInputStream(str.getBytes()));
> >>         StAXOMBuilder builder = new StAXOMBuilder(parser);
> >>         OMElement root = builder.getDocumentElement();
> >>         root.detach();
> >>
> >>         AXIOMXPath xpath = new AXIOMXPath("//hello/something");
> >>         OMElement node = (OMElement) xpath.selectSingleNode(root);
> >>         System.out.println(node == null);
> >>         if (node != null) {
> >>             System.out.println(node.getText());
> >>         }
> >>
> >>        Output
> >>
> >>        true
> >>
> >>
> >>    In second case , XPath  have not been evaluated correctly.
> >>
> >> Thanks
> >> Indika
> >>
> >> On Sat, Jun 20, 2009 at 9:40 PM, Saliya Ekanayake <es...@gmail.com>
> wrote:
> >>>
> >>> Hi,
> >>>
> >>> Um, I am not really clarified with the problem here. I agree that the
> full tree should be built before we can evaluate XPath. Adding the element
> to a new OMDocument, however, just to get this done seems not right.
> Additionally, the original OMDocument created by the builder will be there
> even if you detach the element. Detach will only remove the element from the
> tree to which it belongs. To check this, you can get the builder from the
> detached element and ask for the OMDocument.  IMHO, we can call
> result.build() if necessary.
> >>>
> >>> Btw. I am not clear why XPath doesn't work on the detached element. I
> did a simple test as follows and XPath worked, may be I have missed
> something (please let me know if so).
> >>>
> >>>     public static void main(String[] args) throws XMLStreamException,
> JaxenException {
> >>>         String str = "<hello><something>wow
> nice</something><anotherthing><insideanother>great</insideanother></anotherthing></hello>";
> >>>         StAXOMBuilder builder = new StAXOMBuilder(new
> ByteArrayInputStream(str.getBytes()));
> >>>         OMElement root = builder.getDocumentElement();
> >>>
> >>>         OMDocument doc = builder.getDocument();
> >>>         System.out.println(doc == null);
> >>>
> >>>         OMElement anotherthing = root.getFirstChildWithName(new
> QName("anotherthing"));
> >>>         anotherthing.detach();
> >>>
> >>>         doc = ((StAXOMBuilder)anotherthing.getBuilder()).getDocument();
> >>>         System.out.println(doc == null);
> >>>
> >>>         AXIOMXPath xpath = new AXIOMXPath("//insideanother");
> >>>         OMElement node = (OMElement)
> xpath.selectSingleNode(anotherthing);
> >>>         System.out.println(node.getText());
> >>>     }
> >>>
> >>> Thanks,
> >>> Saliya
> >>>
> >>> On Sat, Jun 20, 2009 at 4:45 AM, Andreas Veithen <
> andreas.veithen@gmail.com> wrote:
> >>>>
> >>>> StAXOMBuilder actually already creates an OMDocument (which can be
> >>>> retrieved by the getDocument method). The important thing is that we
> >>>> need to make sure that the Axiom tree is fully built before closing
> >>>> the input stream. I guess that the detach method is used because it
> >>>> has the side effect of fully building the element and because
> >>>> OMDocument has no method to build the entire tree (see WSCOMMONS-479).
> >>>>
> >>>> This gives us two solutions:
> >>>>
> >>>> - Use StAXOMBuilder#getDocument and iterate over its children to make
> >>>> sure the document is fully built.
> >>>> - Continue to use "detach" and add the element to a new document, as
> >>>> you suggested. Note that you should not use OMDocumentImpl directly,
> >>>> but create it using the OMFactory.
> >>>>
> >>>> Andreas
> >>>>
> >>>> On Fri, Jun 19, 2009 at 09:30, indika kumara<in...@gmail.com>
> wrote:
> >>>> > Devs
> >>>> >
> >>>> > $subject is due to we do  'detach()'  on picked resource OMElement .
> >>>> > If I add detached element to a OMDocument as a child, it works
> >>>> >
> >>>> > Existing code  SImpleURLRegistry
> >>>> >
> >>>> > result.detach();
> >>>> > inputStream.close();
> >>>> >
> >>>> >
> >>>> > Modified code
> >>>> >
> >>>> > result.detach();
> >>>> > OMDocumentImpl omDocument = new OMDocumentImpl();
> >>>> > omDocument.addChild(result);
> >>>> > inputStream.close();
> >>>> >
> >>>> >
> >>>> > Are there any best solution other than what I did ?  I haven't deep
> >>>> > AXIOM knowledge?  Could anyone help me?
> >>>> >
> >>>> > Thanks
> >>>> > Indika
> >>>> >
> >>>> >
> ---------------------------------------------------------------------
> >>>> > To unsubscribe, e-mail: dev-unsubscribe@synapse.apache.org
> >>>> > For additional commands, e-mail: dev-help@synapse.apache.org
> >>>> >
> >>>> >
> >>>>
> >>>> ---------------------------------------------------------------------
> >>>> To unsubscribe, e-mail: dev-unsubscribe@synapse.apache.org
> >>>> For additional commands, e-mail: dev-help@synapse.apache.org
> >>>>
> >>>
> >>>
> >>>
> >>> --
> >>> Saliya Ekanayake
> >>> http://www.esaliya.blogspot.com
> >>> http://www.esaliya.wordpress.com
> >>
> >
> >
> >
> > --
> > Saliya Ekanayake
> > http://www.esaliya.blogspot.com
> > http://www.esaliya.wordpress.com
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@synapse.apache.org
> For additional commands, e-mail: dev-help@synapse.apache.org
>
>

Re: XPath evaluation doesn't work on resources picked from registry

Posted by Andreas Veithen <an...@gmail.com>.
Yes, I think that is the best solution.

Andreas

On Mon, Jun 22, 2009 at 12:14, indika kumara<in...@gmail.com> wrote:
> I will use the second option and add TODO as a reminder for do correct
> change when we are moving to 1.2.9-SNAPSHOT
>
> Indika
>
>
> On Sun, Jun 21, 2009 at 10:59 PM, Andreas Veithen
> <an...@gmail.com> wrote:
>>
>> OMDocument didn't have a build() method. I fixed this (see
>> WSCOMMONS-479), but we can't upgrade to 1.2.9-SNAPSHOT right now. The
>> workaround is to loop over the children of the OMDocument to make sure
>> it is entirely built.
>>
>> Andreas
>>
>> On Sun, Jun 21, 2009 at 19:11, indika kumara<in...@gmail.com> wrote:
>> > Hi Saliya
>> >
>> > This Use case scenario is related with XPath evaluation on the
>> > resources picked from the registry. After reading the resource we
>> > close input stream as it is needed.
>> >
>> > In this use case, parent is always an OMDocument.
>> >
>> > For both following code, you get ‘org.apache.axiom.om.OMException:
>> > com.ctc.wstx.exc.WstxIOException: Stream closed’.
>> >
>> > 1)     remove result.detach()
>> >
>> > 2)     replace result.detach() with  result.build()
>> >
>> > (Please refers SimpleURLRegistry.java)
>> >
>> > Note that here ‘result = builder.getDocumentElement();’ and it is not
>> > builder.getDocument(). If It is possible to call build() method on
>> > OMDocument this issue (‘Stream closed’) may not be occurred (I didn’t
>> > look at AXIOM code).  As Andreas pointed out ‘OMDocument has no method
>> > to build the entire tree and detach() do that as a side effect”.
>> >
>> > I didn't look at deep but feel current possible solutions are what
>> > Andreas suggested.
>> >
>> > Thanks
>> > Indika
>> >
>> > On Sun, Jun 21, 2009 at 5:31 PM, Saliya Ekanayake <es...@gmail.com>
>> > wrote:
>> >>
>> >> Hi Indika,
>> >>
>> >> I tested your point and found the cause. Simply, in the second case
>> >> there is no parent for the root element. Therefore, evaluating an XPath
>> >> containing <hello> element will cause an exception. But if you evaluate an
>> >> XPath like, //anotherthing/insideanother, you will get the desired result.
>> >>
>> >> So the solution I would like to suggest in this case is to first check
>> >> the parent of the element. If the parent is an instance of OMDocument then
>> >> we need not detach (if you need to build then just use OMNode#build()). If
>> >> the parent is an instance of OMElement then you need to detach since you
>> >> want the element to be isolated from the connecting tree.
>> >>
>> >> Thanks,
>> >> Saliya
>> >>
>> >> On Sun, Jun 21, 2009 at 11:06 AM, indika kumara <in...@gmail.com>
>> >> wrote:
>> >>>
>> >>>         Hi Saliya
>> >>>
>> >>>         Following shown my scenarios.
>> >>>
>> >>>
>> >>>        Scenario 1  - without detach on root element
>> >>>
>> >>>         String str = "<hello><something>wow
>> >>> nice</something><anotherthing><insideanother>great</insideanother></anotherthing></hello>";
>> >>>         XMLStreamReader parser = XMLInputFactory.newInstance().
>> >>>                 createXMLStreamReader(new
>> >>> ByteArrayInputStream(str.getBytes()));
>> >>>         StAXOMBuilder builder = new StAXOMBuilder(parser);
>> >>>         OMElement root = builder.getDocumentElement();
>> >>> //        root.detach();
>> >>>
>> >>>         AXIOMXPath xpath = new AXIOMXPath("//hello/something");
>> >>>         OMElement node = (OMElement) xpath.selectSingleNode(root);
>> >>>         System.out.println(node == null);
>> >>>         if (node != null) {
>> >>>             System.out.println(node.getText());
>> >>>         }
>> >>>
>> >>>
>> >>>       Out put :
>> >>>
>> >>>        false
>> >>>        wow nice
>> >>>
>> >>>
>> >>>        Scenario 2 - with  detach on root element
>> >>>
>> >>>         String str = "<hello><something>wow
>> >>> nice</something><anotherthing><insideanother>great</insideanother></anotherthing></hello>";
>> >>>         XMLStreamReader parser = XMLInputFactory.newInstance().
>> >>>                 createXMLStreamReader(new
>> >>> ByteArrayInputStream(str.getBytes()));
>> >>>         StAXOMBuilder builder = new StAXOMBuilder(parser);
>> >>>         OMElement root = builder.getDocumentElement();
>> >>>         root.detach();
>> >>>
>> >>>         AXIOMXPath xpath = new AXIOMXPath("//hello/something");
>> >>>         OMElement node = (OMElement) xpath.selectSingleNode(root);
>> >>>         System.out.println(node == null);
>> >>>         if (node != null) {
>> >>>             System.out.println(node.getText());
>> >>>         }
>> >>>
>> >>>        Output
>> >>>
>> >>>        true
>> >>>
>> >>>
>> >>>    In second case , XPath  have not been evaluated correctly.
>> >>>
>> >>> Thanks
>> >>> Indika
>> >>>
>> >>> On Sat, Jun 20, 2009 at 9:40 PM, Saliya Ekanayake <es...@gmail.com>
>> >>> wrote:
>> >>>>
>> >>>> Hi,
>> >>>>
>> >>>> Um, I am not really clarified with the problem here. I agree that the
>> >>>> full tree should be built before we can evaluate XPath. Adding the element
>> >>>> to a new OMDocument, however, just to get this done seems not right.
>> >>>> Additionally, the original OMDocument created by the builder will be there
>> >>>> even if you detach the element. Detach will only remove the element from the
>> >>>> tree to which it belongs. To check this, you can get the builder from the
>> >>>> detached element and ask for the OMDocument.  IMHO, we can call
>> >>>> result.build() if necessary.
>> >>>>
>> >>>> Btw. I am not clear why XPath doesn't work on the detached element. I
>> >>>> did a simple test as follows and XPath worked, may be I have missed
>> >>>> something (please let me know if so).
>> >>>>
>> >>>>     public static void main(String[] args) throws XMLStreamException,
>> >>>> JaxenException {
>> >>>>         String str = "<hello><something>wow
>> >>>> nice</something><anotherthing><insideanother>great</insideanother></anotherthing></hello>";
>> >>>>         StAXOMBuilder builder = new StAXOMBuilder(new
>> >>>> ByteArrayInputStream(str.getBytes()));
>> >>>>         OMElement root = builder.getDocumentElement();
>> >>>>
>> >>>>         OMDocument doc = builder.getDocument();
>> >>>>         System.out.println(doc == null);
>> >>>>
>> >>>>         OMElement anotherthing = root.getFirstChildWithName(new
>> >>>> QName("anotherthing"));
>> >>>>         anotherthing.detach();
>> >>>>
>> >>>>         doc =
>> >>>> ((StAXOMBuilder)anotherthing.getBuilder()).getDocument();
>> >>>>         System.out.println(doc == null);
>> >>>>
>> >>>>         AXIOMXPath xpath = new AXIOMXPath("//insideanother");
>> >>>>         OMElement node = (OMElement)
>> >>>> xpath.selectSingleNode(anotherthing);
>> >>>>         System.out.println(node.getText());
>> >>>>     }
>> >>>>
>> >>>> Thanks,
>> >>>> Saliya
>> >>>>
>> >>>> On Sat, Jun 20, 2009 at 4:45 AM, Andreas Veithen
>> >>>> <an...@gmail.com> wrote:
>> >>>>>
>> >>>>> StAXOMBuilder actually already creates an OMDocument (which can be
>> >>>>> retrieved by the getDocument method). The important thing is that we
>> >>>>> need to make sure that the Axiom tree is fully built before closing
>> >>>>> the input stream. I guess that the detach method is used because it
>> >>>>> has the side effect of fully building the element and because
>> >>>>> OMDocument has no method to build the entire tree (see
>> >>>>> WSCOMMONS-479).
>> >>>>>
>> >>>>> This gives us two solutions:
>> >>>>>
>> >>>>> - Use StAXOMBuilder#getDocument and iterate over its children to
>> >>>>> make
>> >>>>> sure the document is fully built.
>> >>>>> - Continue to use "detach" and add the element to a new document, as
>> >>>>> you suggested. Note that you should not use OMDocumentImpl directly,
>> >>>>> but create it using the OMFactory.
>> >>>>>
>> >>>>> Andreas
>> >>>>>
>> >>>>> On Fri, Jun 19, 2009 at 09:30, indika kumara<in...@gmail.com>
>> >>>>> wrote:
>> >>>>> > Devs
>> >>>>> >
>> >>>>> > $subject is due to we do  'detach()'  on picked resource OMElement
>> >>>>> > .
>> >>>>> > If I add detached element to a OMDocument as a child, it works
>> >>>>> >
>> >>>>> > Existing code  SImpleURLRegistry
>> >>>>> >
>> >>>>> > result.detach();
>> >>>>> > inputStream.close();
>> >>>>> >
>> >>>>> >
>> >>>>> > Modified code
>> >>>>> >
>> >>>>> > result.detach();
>> >>>>> > OMDocumentImpl omDocument = new OMDocumentImpl();
>> >>>>> > omDocument.addChild(result);
>> >>>>> > inputStream.close();
>> >>>>> >
>> >>>>> >
>> >>>>> > Are there any best solution other than what I did ?  I haven't
>> >>>>> > deep
>> >>>>> > AXIOM knowledge?  Could anyone help me?
>> >>>>> >
>> >>>>> > Thanks
>> >>>>> > Indika
>> >>>>> >
>> >>>>> >
>> >>>>> > ---------------------------------------------------------------------
>> >>>>> > To unsubscribe, e-mail: dev-unsubscribe@synapse.apache.org
>> >>>>> > For additional commands, e-mail: dev-help@synapse.apache.org
>> >>>>> >
>> >>>>> >
>> >>>>>
>> >>>>>
>> >>>>> ---------------------------------------------------------------------
>> >>>>> To unsubscribe, e-mail: dev-unsubscribe@synapse.apache.org
>> >>>>> For additional commands, e-mail: dev-help@synapse.apache.org
>> >>>>>
>> >>>>
>> >>>>
>> >>>>
>> >>>> --
>> >>>> Saliya Ekanayake
>> >>>> http://www.esaliya.blogspot.com
>> >>>> http://www.esaliya.wordpress.com
>> >>>
>> >>
>> >>
>> >>
>> >> --
>> >> Saliya Ekanayake
>> >> http://www.esaliya.blogspot.com
>> >> http://www.esaliya.wordpress.com
>> >
>> > ---------------------------------------------------------------------
>> > To unsubscribe, e-mail: dev-unsubscribe@synapse.apache.org
>> > For additional commands, e-mail: dev-help@synapse.apache.org
>> >
>> >
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: dev-unsubscribe@synapse.apache.org
>> For additional commands, e-mail: dev-help@synapse.apache.org
>>
>
>

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


Re: XPath evaluation doesn't work on resources picked from registry

Posted by indika kumara <in...@gmail.com>.
I will use the second option and add TODO as a reminder for do correct
change when we are moving to 1.2.9-SNAPSHOT

Indika


On Sun, Jun 21, 2009 at 10:59 PM, Andreas Veithen <andreas.veithen@gmail.com
> wrote:

> OMDocument didn't have a build() method. I fixed this (see
> WSCOMMONS-479), but we can't upgrade to 1.2.9-SNAPSHOT right now. The
> workaround is to loop over the children of the OMDocument to make sure
> it is entirely built.
>
> Andreas
>
> On Sun, Jun 21, 2009 at 19:11, indika kumara<in...@gmail.com> wrote:
> > Hi Saliya
> >
> > This Use case scenario is related with XPath evaluation on the
> > resources picked from the registry. After reading the resource we
> > close input stream as it is needed.
> >
> > In this use case, parent is always an OMDocument.
> >
> > For both following code, you get ‘org.apache.axiom.om.OMException:
> > com.ctc.wstx.exc.WstxIOException: Stream closed’.
> >
> > 1)     remove result.detach()
> >
> > 2)     replace result.detach() with  result.build()
> >
> > (Please refers SimpleURLRegistry.java)
> >
> > Note that here ‘result = builder.getDocumentElement();’ and it is not
> > builder.getDocument(). If It is possible to call build() method on
> > OMDocument this issue (‘Stream closed’) may not be occurred (I didn’t
> > look at AXIOM code).  As Andreas pointed out ‘OMDocument has no method
> > to build the entire tree and detach() do that as a side effect”.
> >
> > I didn't look at deep but feel current possible solutions are what
> > Andreas suggested.
> >
> > Thanks
> > Indika
> >
> > On Sun, Jun 21, 2009 at 5:31 PM, Saliya Ekanayake <es...@gmail.com>
> wrote:
> >>
> >> Hi Indika,
> >>
> >> I tested your point and found the cause. Simply, in the second case
> there is no parent for the root element. Therefore, evaluating an XPath
> containing <hello> element will cause an exception. But if you evaluate an
> XPath like, //anotherthing/insideanother, you will get the desired result.
> >>
> >> So the solution I would like to suggest in this case is to first check
> the parent of the element. If the parent is an instance of OMDocument then
> we need not detach (if you need to build then just use OMNode#build()). If
> the parent is an instance of OMElement then you need to detach since you
> want the element to be isolated from the connecting tree.
> >>
> >> Thanks,
> >> Saliya
> >>
> >> On Sun, Jun 21, 2009 at 11:06 AM, indika kumara <in...@gmail.com>
> wrote:
> >>>
> >>>         Hi Saliya
> >>>
> >>>         Following shown my scenarios.
> >>>
> >>>
> >>>        Scenario 1  - without detach on root element
> >>>
> >>>         String str = "<hello><something>wow
> nice</something><anotherthing><insideanother>great</insideanother></anotherthing></hello>";
> >>>         XMLStreamReader parser = XMLInputFactory.newInstance().
> >>>                 createXMLStreamReader(new
> ByteArrayInputStream(str.getBytes()));
> >>>         StAXOMBuilder builder = new StAXOMBuilder(parser);
> >>>         OMElement root = builder.getDocumentElement();
> >>> //        root.detach();
> >>>
> >>>         AXIOMXPath xpath = new AXIOMXPath("//hello/something");
> >>>         OMElement node = (OMElement) xpath.selectSingleNode(root);
> >>>         System.out.println(node == null);
> >>>         if (node != null) {
> >>>             System.out.println(node.getText());
> >>>         }
> >>>
> >>>
> >>>       Out put :
> >>>
> >>>        false
> >>>        wow nice
> >>>
> >>>
> >>>        Scenario 2 - with  detach on root element
> >>>
> >>>         String str = "<hello><something>wow
> nice</something><anotherthing><insideanother>great</insideanother></anotherthing></hello>";
> >>>         XMLStreamReader parser = XMLInputFactory.newInstance().
> >>>                 createXMLStreamReader(new
> ByteArrayInputStream(str.getBytes()));
> >>>         StAXOMBuilder builder = new StAXOMBuilder(parser);
> >>>         OMElement root = builder.getDocumentElement();
> >>>         root.detach();
> >>>
> >>>         AXIOMXPath xpath = new AXIOMXPath("//hello/something");
> >>>         OMElement node = (OMElement) xpath.selectSingleNode(root);
> >>>         System.out.println(node == null);
> >>>         if (node != null) {
> >>>             System.out.println(node.getText());
> >>>         }
> >>>
> >>>        Output
> >>>
> >>>        true
> >>>
> >>>
> >>>    In second case , XPath  have not been evaluated correctly.
> >>>
> >>> Thanks
> >>> Indika
> >>>
> >>> On Sat, Jun 20, 2009 at 9:40 PM, Saliya Ekanayake <es...@gmail.com>
> wrote:
> >>>>
> >>>> Hi,
> >>>>
> >>>> Um, I am not really clarified with the problem here. I agree that the
> full tree should be built before we can evaluate XPath. Adding the element
> to a new OMDocument, however, just to get this done seems not right.
> Additionally, the original OMDocument created by the builder will be there
> even if you detach the element. Detach will only remove the element from the
> tree to which it belongs. To check this, you can get the builder from the
> detached element and ask for the OMDocument.  IMHO, we can call
> result.build() if necessary.
> >>>>
> >>>> Btw. I am not clear why XPath doesn't work on the detached element. I
> did a simple test as follows and XPath worked, may be I have missed
> something (please let me know if so).
> >>>>
> >>>>     public static void main(String[] args) throws XMLStreamException,
> JaxenException {
> >>>>         String str = "<hello><something>wow
> nice</something><anotherthing><insideanother>great</insideanother></anotherthing></hello>";
> >>>>         StAXOMBuilder builder = new StAXOMBuilder(new
> ByteArrayInputStream(str.getBytes()));
> >>>>         OMElement root = builder.getDocumentElement();
> >>>>
> >>>>         OMDocument doc = builder.getDocument();
> >>>>         System.out.println(doc == null);
> >>>>
> >>>>         OMElement anotherthing = root.getFirstChildWithName(new
> QName("anotherthing"));
> >>>>         anotherthing.detach();
> >>>>
> >>>>         doc =
> ((StAXOMBuilder)anotherthing.getBuilder()).getDocument();
> >>>>         System.out.println(doc == null);
> >>>>
> >>>>         AXIOMXPath xpath = new AXIOMXPath("//insideanother");
> >>>>         OMElement node = (OMElement)
> xpath.selectSingleNode(anotherthing);
> >>>>         System.out.println(node.getText());
> >>>>     }
> >>>>
> >>>> Thanks,
> >>>> Saliya
> >>>>
> >>>> On Sat, Jun 20, 2009 at 4:45 AM, Andreas Veithen <
> andreas.veithen@gmail.com> wrote:
> >>>>>
> >>>>> StAXOMBuilder actually already creates an OMDocument (which can be
> >>>>> retrieved by the getDocument method). The important thing is that we
> >>>>> need to make sure that the Axiom tree is fully built before closing
> >>>>> the input stream. I guess that the detach method is used because it
> >>>>> has the side effect of fully building the element and because
> >>>>> OMDocument has no method to build the entire tree (see
> WSCOMMONS-479).
> >>>>>
> >>>>> This gives us two solutions:
> >>>>>
> >>>>> - Use StAXOMBuilder#getDocument and iterate over its children to make
> >>>>> sure the document is fully built.
> >>>>> - Continue to use "detach" and add the element to a new document, as
> >>>>> you suggested. Note that you should not use OMDocumentImpl directly,
> >>>>> but create it using the OMFactory.
> >>>>>
> >>>>> Andreas
> >>>>>
> >>>>> On Fri, Jun 19, 2009 at 09:30, indika kumara<in...@gmail.com>
> wrote:
> >>>>> > Devs
> >>>>> >
> >>>>> > $subject is due to we do  'detach()'  on picked resource OMElement
> .
> >>>>> > If I add detached element to a OMDocument as a child, it works
> >>>>> >
> >>>>> > Existing code  SImpleURLRegistry
> >>>>> >
> >>>>> > result.detach();
> >>>>> > inputStream.close();
> >>>>> >
> >>>>> >
> >>>>> > Modified code
> >>>>> >
> >>>>> > result.detach();
> >>>>> > OMDocumentImpl omDocument = new OMDocumentImpl();
> >>>>> > omDocument.addChild(result);
> >>>>> > inputStream.close();
> >>>>> >
> >>>>> >
> >>>>> > Are there any best solution other than what I did ?  I haven't deep
> >>>>> > AXIOM knowledge?  Could anyone help me?
> >>>>> >
> >>>>> > Thanks
> >>>>> > Indika
> >>>>> >
> >>>>> >
> ---------------------------------------------------------------------
> >>>>> > To unsubscribe, e-mail: dev-unsubscribe@synapse.apache.org
> >>>>> > For additional commands, e-mail: dev-help@synapse.apache.org
> >>>>> >
> >>>>> >
> >>>>>
> >>>>> ---------------------------------------------------------------------
> >>>>> To unsubscribe, e-mail: dev-unsubscribe@synapse.apache.org
> >>>>> For additional commands, e-mail: dev-help@synapse.apache.org
> >>>>>
> >>>>
> >>>>
> >>>>
> >>>> --
> >>>> Saliya Ekanayake
> >>>> http://www.esaliya.blogspot.com
> >>>> http://www.esaliya.wordpress.com
> >>>
> >>
> >>
> >>
> >> --
> >> Saliya Ekanayake
> >> http://www.esaliya.blogspot.com
> >> http://www.esaliya.wordpress.com
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: dev-unsubscribe@synapse.apache.org
> > For additional commands, e-mail: dev-help@synapse.apache.org
> >
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@synapse.apache.org
> For additional commands, e-mail: dev-help@synapse.apache.org
>
>

Re: XPath evaluation doesn't work on resources picked from registry

Posted by Andreas Veithen <an...@gmail.com>.
OMDocument didn't have a build() method. I fixed this (see
WSCOMMONS-479), but we can't upgrade to 1.2.9-SNAPSHOT right now. The
workaround is to loop over the children of the OMDocument to make sure
it is entirely built.

Andreas

On Sun, Jun 21, 2009 at 19:11, indika kumara<in...@gmail.com> wrote:
> Hi Saliya
>
> This Use case scenario is related with XPath evaluation on the
> resources picked from the registry. After reading the resource we
> close input stream as it is needed.
>
> In this use case, parent is always an OMDocument.
>
> For both following code, you get ‘org.apache.axiom.om.OMException:
> com.ctc.wstx.exc.WstxIOException: Stream closed’.
>
> 1)     remove result.detach()
>
> 2)     replace result.detach() with  result.build()
>
> (Please refers SimpleURLRegistry.java)
>
> Note that here ‘result = builder.getDocumentElement();’ and it is not
> builder.getDocument(). If It is possible to call build() method on
> OMDocument this issue (‘Stream closed’) may not be occurred (I didn’t
> look at AXIOM code).  As Andreas pointed out ‘OMDocument has no method
> to build the entire tree and detach() do that as a side effect”.
>
> I didn't look at deep but feel current possible solutions are what
> Andreas suggested.
>
> Thanks
> Indika
>
> On Sun, Jun 21, 2009 at 5:31 PM, Saliya Ekanayake <es...@gmail.com> wrote:
>>
>> Hi Indika,
>>
>> I tested your point and found the cause. Simply, in the second case there is no parent for the root element. Therefore, evaluating an XPath containing <hello> element will cause an exception. But if you evaluate an XPath like, //anotherthing/insideanother, you will get the desired result.
>>
>> So the solution I would like to suggest in this case is to first check the parent of the element. If the parent is an instance of OMDocument then we need not detach (if you need to build then just use OMNode#build()). If the parent is an instance of OMElement then you need to detach since you want the element to be isolated from the connecting tree.
>>
>> Thanks,
>> Saliya
>>
>> On Sun, Jun 21, 2009 at 11:06 AM, indika kumara <in...@gmail.com> wrote:
>>>
>>>         Hi Saliya
>>>
>>>         Following shown my scenarios.
>>>
>>>
>>>        Scenario 1  - without detach on root element
>>>
>>>         String str = "<hello><something>wow nice</something><anotherthing><insideanother>great</insideanother></anotherthing></hello>";
>>>         XMLStreamReader parser = XMLInputFactory.newInstance().
>>>                 createXMLStreamReader(new ByteArrayInputStream(str.getBytes()));
>>>         StAXOMBuilder builder = new StAXOMBuilder(parser);
>>>         OMElement root = builder.getDocumentElement();
>>> //        root.detach();
>>>
>>>         AXIOMXPath xpath = new AXIOMXPath("//hello/something");
>>>         OMElement node = (OMElement) xpath.selectSingleNode(root);
>>>         System.out.println(node == null);
>>>         if (node != null) {
>>>             System.out.println(node.getText());
>>>         }
>>>
>>>
>>>       Out put :
>>>
>>>        false
>>>        wow nice
>>>
>>>
>>>        Scenario 2 - with  detach on root element
>>>
>>>         String str = "<hello><something>wow nice</something><anotherthing><insideanother>great</insideanother></anotherthing></hello>";
>>>         XMLStreamReader parser = XMLInputFactory.newInstance().
>>>                 createXMLStreamReader(new ByteArrayInputStream(str.getBytes()));
>>>         StAXOMBuilder builder = new StAXOMBuilder(parser);
>>>         OMElement root = builder.getDocumentElement();
>>>         root.detach();
>>>
>>>         AXIOMXPath xpath = new AXIOMXPath("//hello/something");
>>>         OMElement node = (OMElement) xpath.selectSingleNode(root);
>>>         System.out.println(node == null);
>>>         if (node != null) {
>>>             System.out.println(node.getText());
>>>         }
>>>
>>>        Output
>>>
>>>        true
>>>
>>>
>>>    In second case , XPath  have not been evaluated correctly.
>>>
>>> Thanks
>>> Indika
>>>
>>> On Sat, Jun 20, 2009 at 9:40 PM, Saliya Ekanayake <es...@gmail.com> wrote:
>>>>
>>>> Hi,
>>>>
>>>> Um, I am not really clarified with the problem here. I agree that the full tree should be built before we can evaluate XPath. Adding the element to a new OMDocument, however, just to get this done seems not right. Additionally, the original OMDocument created by the builder will be there even if you detach the element. Detach will only remove the element from the tree to which it belongs. To check this, you can get the builder from the detached element and ask for the OMDocument.  IMHO, we can call result.build() if necessary.
>>>>
>>>> Btw. I am not clear why XPath doesn't work on the detached element. I did a simple test as follows and XPath worked, may be I have missed something (please let me know if so).
>>>>
>>>>     public static void main(String[] args) throws XMLStreamException, JaxenException {
>>>>         String str = "<hello><something>wow nice</something><anotherthing><insideanother>great</insideanother></anotherthing></hello>";
>>>>         StAXOMBuilder builder = new StAXOMBuilder(new ByteArrayInputStream(str.getBytes()));
>>>>         OMElement root = builder.getDocumentElement();
>>>>
>>>>         OMDocument doc = builder.getDocument();
>>>>         System.out.println(doc == null);
>>>>
>>>>         OMElement anotherthing = root.getFirstChildWithName(new QName("anotherthing"));
>>>>         anotherthing.detach();
>>>>
>>>>         doc = ((StAXOMBuilder)anotherthing.getBuilder()).getDocument();
>>>>         System.out.println(doc == null);
>>>>
>>>>         AXIOMXPath xpath = new AXIOMXPath("//insideanother");
>>>>         OMElement node = (OMElement) xpath.selectSingleNode(anotherthing);
>>>>         System.out.println(node.getText());
>>>>     }
>>>>
>>>> Thanks,
>>>> Saliya
>>>>
>>>> On Sat, Jun 20, 2009 at 4:45 AM, Andreas Veithen <an...@gmail.com> wrote:
>>>>>
>>>>> StAXOMBuilder actually already creates an OMDocument (which can be
>>>>> retrieved by the getDocument method). The important thing is that we
>>>>> need to make sure that the Axiom tree is fully built before closing
>>>>> the input stream. I guess that the detach method is used because it
>>>>> has the side effect of fully building the element and because
>>>>> OMDocument has no method to build the entire tree (see WSCOMMONS-479).
>>>>>
>>>>> This gives us two solutions:
>>>>>
>>>>> - Use StAXOMBuilder#getDocument and iterate over its children to make
>>>>> sure the document is fully built.
>>>>> - Continue to use "detach" and add the element to a new document, as
>>>>> you suggested. Note that you should not use OMDocumentImpl directly,
>>>>> but create it using the OMFactory.
>>>>>
>>>>> Andreas
>>>>>
>>>>> On Fri, Jun 19, 2009 at 09:30, indika kumara<in...@gmail.com> wrote:
>>>>> > Devs
>>>>> >
>>>>> > $subject is due to we do  'detach()'  on picked resource OMElement .
>>>>> > If I add detached element to a OMDocument as a child, it works
>>>>> >
>>>>> > Existing code  SImpleURLRegistry
>>>>> >
>>>>> > result.detach();
>>>>> > inputStream.close();
>>>>> >
>>>>> >
>>>>> > Modified code
>>>>> >
>>>>> > result.detach();
>>>>> > OMDocumentImpl omDocument = new OMDocumentImpl();
>>>>> > omDocument.addChild(result);
>>>>> > inputStream.close();
>>>>> >
>>>>> >
>>>>> > Are there any best solution other than what I did ?  I haven't deep
>>>>> > AXIOM knowledge?  Could anyone help me?
>>>>> >
>>>>> > Thanks
>>>>> > Indika
>>>>> >
>>>>> > ---------------------------------------------------------------------
>>>>> > To unsubscribe, e-mail: dev-unsubscribe@synapse.apache.org
>>>>> > For additional commands, e-mail: dev-help@synapse.apache.org
>>>>> >
>>>>> >
>>>>>
>>>>> ---------------------------------------------------------------------
>>>>> To unsubscribe, e-mail: dev-unsubscribe@synapse.apache.org
>>>>> For additional commands, e-mail: dev-help@synapse.apache.org
>>>>>
>>>>
>>>>
>>>>
>>>> --
>>>> Saliya Ekanayake
>>>> http://www.esaliya.blogspot.com
>>>> http://www.esaliya.wordpress.com
>>>
>>
>>
>>
>> --
>> Saliya Ekanayake
>> http://www.esaliya.blogspot.com
>> http://www.esaliya.wordpress.com
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@synapse.apache.org
> For additional commands, e-mail: dev-help@synapse.apache.org
>
>

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


Re: XPath evaluation doesn't work on resources picked from registry

Posted by indika kumara <in...@gmail.com>.
Hi Saliya

This Use case scenario is related with XPath evaluation on the
resources picked from the registry. After reading the resource we
close input stream as it is needed.

In this use case, parent is always an OMDocument.

For both following code, you get ‘org.apache.axiom.om.OMException:
com.ctc.wstx.exc.WstxIOException: Stream closed’.

1)     remove result.detach()

2)     replace result.detach() with  result.build()

(Please refers SimpleURLRegistry.java)

Note that here ‘result = builder.getDocumentElement();’ and it is not
builder.getDocument(). If It is possible to call build() method on
OMDocument this issue (‘Stream closed’) may not be occurred (I didn’t
look at AXIOM code).  As Andreas pointed out ‘OMDocument has no method
to build the entire tree and detach() do that as a side effect”.

I didn't look at deep but feel current possible solutions are what
Andreas suggested.

Thanks
Indika

On Sun, Jun 21, 2009 at 5:31 PM, Saliya Ekanayake <es...@gmail.com> wrote:
>
> Hi Indika,
>
> I tested your point and found the cause. Simply, in the second case there is no parent for the root element. Therefore, evaluating an XPath containing <hello> element will cause an exception. But if you evaluate an XPath like, //anotherthing/insideanother, you will get the desired result.
>
> So the solution I would like to suggest in this case is to first check the parent of the element. If the parent is an instance of OMDocument then we need not detach (if you need to build then just use OMNode#build()). If the parent is an instance of OMElement then you need to detach since you want the element to be isolated from the connecting tree.
>
> Thanks,
> Saliya
>
> On Sun, Jun 21, 2009 at 11:06 AM, indika kumara <in...@gmail.com> wrote:
>>
>>         Hi Saliya
>>
>>         Following shown my scenarios.
>>
>>
>>        Scenario 1  - without detach on root element
>>
>>         String str = "<hello><something>wow nice</something><anotherthing><insideanother>great</insideanother></anotherthing></hello>";
>>         XMLStreamReader parser = XMLInputFactory.newInstance().
>>                 createXMLStreamReader(new ByteArrayInputStream(str.getBytes()));
>>         StAXOMBuilder builder = new StAXOMBuilder(parser);
>>         OMElement root = builder.getDocumentElement();
>> //        root.detach();
>>
>>         AXIOMXPath xpath = new AXIOMXPath("//hello/something");
>>         OMElement node = (OMElement) xpath.selectSingleNode(root);
>>         System.out.println(node == null);
>>         if (node != null) {
>>             System.out.println(node.getText());
>>         }
>>
>>
>>       Out put :
>>
>>        false
>>        wow nice
>>
>>
>>        Scenario 2 - with  detach on root element
>>
>>         String str = "<hello><something>wow nice</something><anotherthing><insideanother>great</insideanother></anotherthing></hello>";
>>         XMLStreamReader parser = XMLInputFactory.newInstance().
>>                 createXMLStreamReader(new ByteArrayInputStream(str.getBytes()));
>>         StAXOMBuilder builder = new StAXOMBuilder(parser);
>>         OMElement root = builder.getDocumentElement();
>>         root.detach();
>>
>>         AXIOMXPath xpath = new AXIOMXPath("//hello/something");
>>         OMElement node = (OMElement) xpath.selectSingleNode(root);
>>         System.out.println(node == null);
>>         if (node != null) {
>>             System.out.println(node.getText());
>>         }
>>
>>        Output
>>
>>        true
>>
>>
>>    In second case , XPath  have not been evaluated correctly.
>>
>> Thanks
>> Indika
>>
>> On Sat, Jun 20, 2009 at 9:40 PM, Saliya Ekanayake <es...@gmail.com> wrote:
>>>
>>> Hi,
>>>
>>> Um, I am not really clarified with the problem here. I agree that the full tree should be built before we can evaluate XPath. Adding the element to a new OMDocument, however, just to get this done seems not right. Additionally, the original OMDocument created by the builder will be there even if you detach the element. Detach will only remove the element from the tree to which it belongs. To check this, you can get the builder from the detached element and ask for the OMDocument.  IMHO, we can call result.build() if necessary.
>>>
>>> Btw. I am not clear why XPath doesn't work on the detached element. I did a simple test as follows and XPath worked, may be I have missed something (please let me know if so).
>>>
>>>     public static void main(String[] args) throws XMLStreamException, JaxenException {
>>>         String str = "<hello><something>wow nice</something><anotherthing><insideanother>great</insideanother></anotherthing></hello>";
>>>         StAXOMBuilder builder = new StAXOMBuilder(new ByteArrayInputStream(str.getBytes()));
>>>         OMElement root = builder.getDocumentElement();
>>>
>>>         OMDocument doc = builder.getDocument();
>>>         System.out.println(doc == null);
>>>
>>>         OMElement anotherthing = root.getFirstChildWithName(new QName("anotherthing"));
>>>         anotherthing.detach();
>>>
>>>         doc = ((StAXOMBuilder)anotherthing.getBuilder()).getDocument();
>>>         System.out.println(doc == null);
>>>
>>>         AXIOMXPath xpath = new AXIOMXPath("//insideanother");
>>>         OMElement node = (OMElement) xpath.selectSingleNode(anotherthing);
>>>         System.out.println(node.getText());
>>>     }
>>>
>>> Thanks,
>>> Saliya
>>>
>>> On Sat, Jun 20, 2009 at 4:45 AM, Andreas Veithen <an...@gmail.com> wrote:
>>>>
>>>> StAXOMBuilder actually already creates an OMDocument (which can be
>>>> retrieved by the getDocument method). The important thing is that we
>>>> need to make sure that the Axiom tree is fully built before closing
>>>> the input stream. I guess that the detach method is used because it
>>>> has the side effect of fully building the element and because
>>>> OMDocument has no method to build the entire tree (see WSCOMMONS-479).
>>>>
>>>> This gives us two solutions:
>>>>
>>>> - Use StAXOMBuilder#getDocument and iterate over its children to make
>>>> sure the document is fully built.
>>>> - Continue to use "detach" and add the element to a new document, as
>>>> you suggested. Note that you should not use OMDocumentImpl directly,
>>>> but create it using the OMFactory.
>>>>
>>>> Andreas
>>>>
>>>> On Fri, Jun 19, 2009 at 09:30, indika kumara<in...@gmail.com> wrote:
>>>> > Devs
>>>> >
>>>> > $subject is due to we do  'detach()'  on picked resource OMElement .
>>>> > If I add detached element to a OMDocument as a child, it works
>>>> >
>>>> > Existing code  SImpleURLRegistry
>>>> >
>>>> > result.detach();
>>>> > inputStream.close();
>>>> >
>>>> >
>>>> > Modified code
>>>> >
>>>> > result.detach();
>>>> > OMDocumentImpl omDocument = new OMDocumentImpl();
>>>> > omDocument.addChild(result);
>>>> > inputStream.close();
>>>> >
>>>> >
>>>> > Are there any best solution other than what I did ?  I haven't deep
>>>> > AXIOM knowledge?  Could anyone help me?
>>>> >
>>>> > Thanks
>>>> > Indika
>>>> >
>>>> > ---------------------------------------------------------------------
>>>> > To unsubscribe, e-mail: dev-unsubscribe@synapse.apache.org
>>>> > For additional commands, e-mail: dev-help@synapse.apache.org
>>>> >
>>>> >
>>>>
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: dev-unsubscribe@synapse.apache.org
>>>> For additional commands, e-mail: dev-help@synapse.apache.org
>>>>
>>>
>>>
>>>
>>> --
>>> Saliya Ekanayake
>>> http://www.esaliya.blogspot.com
>>> http://www.esaliya.wordpress.com
>>
>
>
>
> --
> Saliya Ekanayake
> http://www.esaliya.blogspot.com
> http://www.esaliya.wordpress.com

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


Re: XPath evaluation doesn't work on resources picked from registry

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

I tested your point and found the cause. Simply, in the second case there is
no parent for the root element. Therefore, evaluating an XPath containing
<hello> element will cause an exception. But if you evaluate an XPath like,
//anotherthing/insideanother, you will get the desired result.

So the solution I would like to suggest in this case is to first check the
parent of the element. If the parent is an instance of OMDocument then we
need not detach (if you need to build then just use OMNode#build()). If the
parent is an instance of OMElement then you need to detach since you want
the element to be isolated from the connecting tree.

Thanks,
Saliya

On Sun, Jun 21, 2009 at 11:06 AM, indika kumara <in...@gmail.com>wrote:

>         Hi Saliya
>
>         Following shown my scenarios.
>
>
>        Scenario 1  - without detach on root element
>
>         String str = "<hello><something>wow
> nice</something><anotherthing><insideanother>great</insideanother></anotherthing></hello>";
>         XMLStreamReader parser = XMLInputFactory.newInstance().
>                 createXMLStreamReader(new
> ByteArrayInputStream(str.getBytes()));
>         StAXOMBuilder builder = new StAXOMBuilder(parser);
>         OMElement root = builder.getDocumentElement();
> *//        root.detach();*
>
>         AXIOMXPath xpath = new AXIOMXPath("//hello/something");
>         OMElement node = (OMElement) xpath.selectSingleNode(root);
>         System.out.println(node == null);
>         if (node != null) {
>             System.out.println(node.getText());
>         }
>
>
>       Out put :
>
>        false
>       * wow nice*
>
>
>        Scenario 2 - with  detach on root element
>
>         String str = "<hello><something>wow
> nice</something><anotherthing><insideanother>great</insideanother></anotherthing></hello>";
>         XMLStreamReader parser = XMLInputFactory.newInstance().
>                 createXMLStreamReader(new
> ByteArrayInputStream(str.getBytes()));
>         StAXOMBuilder builder = new StAXOMBuilder(parser);
>         OMElement root = builder.getDocumentElement();
>       *  root.detach();*
>
>         AXIOMXPath xpath = new AXIOMXPath("//hello/something");
>         OMElement node = (OMElement) xpath.selectSingleNode(root);
>         System.out.println(node == null);
>         if (node != null) {
>             System.out.println(node.getText());
>         }
>
>        Output
>
>        true
>
>
>    In second case , XPath  have not been evaluated correctly.
>
> Thanks
> Indika
>
> On Sat, Jun 20, 2009 at 9:40 PM, Saliya Ekanayake <es...@gmail.com>wrote:
>
>> Hi,
>>
>> Um, I am not really clarified with the problem here. I agree that the full
>> tree should be built before we can evaluate XPath. Adding the element to a
>> new OMDocument, however, just to get this done seems not right.
>> Additionally, the original OMDocument created by the builder will be there
>> even if you detach the element. Detach will only remove the element from the
>> tree to which it belongs. To check this, you can get the builder from the
>> detached element and ask for the OMDocument.  IMHO, we can call
>> result.build() if necessary.
>>
>> Btw. I am not clear why XPath doesn't work on the detached element. I did
>> a simple test as follows and XPath worked, may be I have missed something
>> (please let me know if so).
>>
>>     public static void main(String[] args) throws XMLStreamException,
>> JaxenException {
>>         String str = "<hello><something>wow
>> nice</something><anotherthing><insideanother>great</insideanother></anotherthing></hello>";
>>         StAXOMBuilder builder = new StAXOMBuilder(new
>> ByteArrayInputStream(str.getBytes()));
>>         OMElement root = builder.getDocumentElement();
>>
>>         OMDocument doc = builder.getDocument();
>>         System.out.println(doc == null);
>>
>>         OMElement anotherthing = root.getFirstChildWithName(new
>> QName("anotherthing"));
>>         anotherthing.detach();
>>
>>         doc = ((StAXOMBuilder)anotherthing.getBuilder()).getDocument();
>>         System.out.println(doc == null);
>>
>>         AXIOMXPath xpath = new AXIOMXPath("//insideanother");
>>         OMElement node = (OMElement) xpath.selectSingleNode(anotherthing);
>>         System.out.println(node.getText());
>>     }
>>
>> Thanks,
>> Saliya
>>
>> On Sat, Jun 20, 2009 at 4:45 AM, Andreas Veithen <
>> andreas.veithen@gmail.com> wrote:
>>
>>> StAXOMBuilder actually already creates an OMDocument (which can be
>>> retrieved by the getDocument method). The important thing is that we
>>> need to make sure that the Axiom tree is fully built before closing
>>> the input stream. I guess that the detach method is used because it
>>> has the side effect of fully building the element and because
>>> OMDocument has no method to build the entire tree (see WSCOMMONS-479).
>>>
>>> This gives us two solutions:
>>>
>>> - Use StAXOMBuilder#getDocument and iterate over its children to make
>>> sure the document is fully built.
>>> - Continue to use "detach" and add the element to a new document, as
>>> you suggested. Note that you should not use OMDocumentImpl directly,
>>> but create it using the OMFactory.
>>>
>>> Andreas
>>>
>>> On Fri, Jun 19, 2009 at 09:30, indika kumara<in...@gmail.com>
>>> wrote:
>>> > Devs
>>> >
>>> > $subject is due to we do  'detach()'  on picked resource OMElement .
>>> > If I add detached element to a OMDocument as a child, it works
>>> >
>>> > Existing code  SImpleURLRegistry
>>> >
>>> > result.detach();
>>> > inputStream.close();
>>> >
>>> >
>>> > Modified code
>>> >
>>> > result.detach();
>>> > OMDocumentImpl omDocument = new OMDocumentImpl();
>>> > omDocument.addChild(result);
>>> > inputStream.close();
>>> >
>>> >
>>> > Are there any best solution other than what I did ?  I haven't deep
>>> > AXIOM knowledge?  Could anyone help me?
>>> >
>>> > Thanks
>>> > Indika
>>> >
>>> > ---------------------------------------------------------------------
>>> > To unsubscribe, e-mail: dev-unsubscribe@synapse.apache.org
>>> > For additional commands, e-mail: dev-help@synapse.apache.org
>>> >
>>> >
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: dev-unsubscribe@synapse.apache.org
>>> For additional commands, e-mail: dev-help@synapse.apache.org
>>>
>>>
>>
>>
>> --
>> 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 evaluation doesn't work on resources picked from registry

Posted by indika kumara <in...@gmail.com>.
        Hi Saliya

        Following shown my scenarios.


       Scenario 1  - without detach on root element

        String str = "<hello><something>wow
nice</something><anotherthing><insideanother>great</insideanother></anotherthing></hello>";
        XMLStreamReader parser = XMLInputFactory.newInstance().
                createXMLStreamReader(new
ByteArrayInputStream(str.getBytes()));
        StAXOMBuilder builder = new StAXOMBuilder(parser);
        OMElement root = builder.getDocumentElement();
*//        root.detach();*

        AXIOMXPath xpath = new AXIOMXPath("//hello/something");
        OMElement node = (OMElement) xpath.selectSingleNode(root);
        System.out.println(node == null);
        if (node != null) {
            System.out.println(node.getText());
        }


      Out put :

       false
      * wow nice*


       Scenario 2 - with  detach on root element

        String str = "<hello><something>wow
nice</something><anotherthing><insideanother>great</insideanother></anotherthing></hello>";
        XMLStreamReader parser = XMLInputFactory.newInstance().
                createXMLStreamReader(new
ByteArrayInputStream(str.getBytes()));
        StAXOMBuilder builder = new StAXOMBuilder(parser);
        OMElement root = builder.getDocumentElement();
      *  root.detach();*

        AXIOMXPath xpath = new AXIOMXPath("//hello/something");
        OMElement node = (OMElement) xpath.selectSingleNode(root);
        System.out.println(node == null);
        if (node != null) {
            System.out.println(node.getText());
        }

       Output

       true


   In second case , XPath  have not been evaluated correctly.

Thanks
Indika

On Sat, Jun 20, 2009 at 9:40 PM, Saliya Ekanayake <es...@gmail.com> wrote:

> Hi,
>
> Um, I am not really clarified with the problem here. I agree that the full
> tree should be built before we can evaluate XPath. Adding the element to a
> new OMDocument, however, just to get this done seems not right.
> Additionally, the original OMDocument created by the builder will be there
> even if you detach the element. Detach will only remove the element from the
> tree to which it belongs. To check this, you can get the builder from the
> detached element and ask for the OMDocument.  IMHO, we can call
> result.build() if necessary.
>
> Btw. I am not clear why XPath doesn't work on the detached element. I did a
> simple test as follows and XPath worked, may be I have missed something
> (please let me know if so).
>
>     public static void main(String[] args) throws XMLStreamException,
> JaxenException {
>         String str = "<hello><something>wow
> nice</something><anotherthing><insideanother>great</insideanother></anotherthing></hello>";
>         StAXOMBuilder builder = new StAXOMBuilder(new
> ByteArrayInputStream(str.getBytes()));
>         OMElement root = builder.getDocumentElement();
>
>         OMDocument doc = builder.getDocument();
>         System.out.println(doc == null);
>
>         OMElement anotherthing = root.getFirstChildWithName(new
> QName("anotherthing"));
>         anotherthing.detach();
>
>         doc = ((StAXOMBuilder)anotherthing.getBuilder()).getDocument();
>         System.out.println(doc == null);
>
>         AXIOMXPath xpath = new AXIOMXPath("//insideanother");
>         OMElement node = (OMElement) xpath.selectSingleNode(anotherthing);
>         System.out.println(node.getText());
>     }
>
> Thanks,
> Saliya
>
> On Sat, Jun 20, 2009 at 4:45 AM, Andreas Veithen <
> andreas.veithen@gmail.com> wrote:
>
>> StAXOMBuilder actually already creates an OMDocument (which can be
>> retrieved by the getDocument method). The important thing is that we
>> need to make sure that the Axiom tree is fully built before closing
>> the input stream. I guess that the detach method is used because it
>> has the side effect of fully building the element and because
>> OMDocument has no method to build the entire tree (see WSCOMMONS-479).
>>
>> This gives us two solutions:
>>
>> - Use StAXOMBuilder#getDocument and iterate over its children to make
>> sure the document is fully built.
>> - Continue to use "detach" and add the element to a new document, as
>> you suggested. Note that you should not use OMDocumentImpl directly,
>> but create it using the OMFactory.
>>
>> Andreas
>>
>> On Fri, Jun 19, 2009 at 09:30, indika kumara<in...@gmail.com>
>> wrote:
>> > Devs
>> >
>> > $subject is due to we do  'detach()'  on picked resource OMElement .
>> > If I add detached element to a OMDocument as a child, it works
>> >
>> > Existing code  SImpleURLRegistry
>> >
>> > result.detach();
>> > inputStream.close();
>> >
>> >
>> > Modified code
>> >
>> > result.detach();
>> > OMDocumentImpl omDocument = new OMDocumentImpl();
>> > omDocument.addChild(result);
>> > inputStream.close();
>> >
>> >
>> > Are there any best solution other than what I did ?  I haven't deep
>> > AXIOM knowledge?  Could anyone help me?
>> >
>> > Thanks
>> > Indika
>> >
>> > ---------------------------------------------------------------------
>> > To unsubscribe, e-mail: dev-unsubscribe@synapse.apache.org
>> > For additional commands, e-mail: dev-help@synapse.apache.org
>> >
>> >
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: dev-unsubscribe@synapse.apache.org
>> For additional commands, e-mail: dev-help@synapse.apache.org
>>
>>
>
>
> --
> Saliya Ekanayake
> http://www.esaliya.blogspot.com
> http://www.esaliya.wordpress.com
>

Re: XPath evaluation doesn't work on resources picked from registry

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

Um, I am not really clarified with the problem here. I agree that the full
tree should be built before we can evaluate XPath. Adding the element to a
new OMDocument, however, just to get this done seems not right.
Additionally, the original OMDocument created by the builder will be there
even if you detach the element. Detach will only remove the element from the
tree to which it belongs. To check this, you can get the builder from the
detached element and ask for the OMDocument.  IMHO, we can call
result.build() if necessary.

Btw. I am not clear why XPath doesn't work on the detached element. I did a
simple test as follows and XPath worked, may be I have missed something
(please let me know if so).

    public static void main(String[] args) throws XMLStreamException,
JaxenException {
        String str = "<hello><something>wow
nice</something><anotherthing><insideanother>great</insideanother></anotherthing></hello>";
        StAXOMBuilder builder = new StAXOMBuilder(new
ByteArrayInputStream(str.getBytes()));
        OMElement root = builder.getDocumentElement();

        OMDocument doc = builder.getDocument();
        System.out.println(doc == null);

        OMElement anotherthing = root.getFirstChildWithName(new
QName("anotherthing"));
        anotherthing.detach();

        doc = ((StAXOMBuilder)anotherthing.getBuilder()).getDocument();
        System.out.println(doc == null);

        AXIOMXPath xpath = new AXIOMXPath("//insideanother");
        OMElement node = (OMElement) xpath.selectSingleNode(anotherthing);
        System.out.println(node.getText());
    }

Thanks,
Saliya

On Sat, Jun 20, 2009 at 4:45 AM, Andreas Veithen
<an...@gmail.com>wrote:

> StAXOMBuilder actually already creates an OMDocument (which can be
> retrieved by the getDocument method). The important thing is that we
> need to make sure that the Axiom tree is fully built before closing
> the input stream. I guess that the detach method is used because it
> has the side effect of fully building the element and because
> OMDocument has no method to build the entire tree (see WSCOMMONS-479).
>
> This gives us two solutions:
>
> - Use StAXOMBuilder#getDocument and iterate over its children to make
> sure the document is fully built.
> - Continue to use "detach" and add the element to a new document, as
> you suggested. Note that you should not use OMDocumentImpl directly,
> but create it using the OMFactory.
>
> Andreas
>
> On Fri, Jun 19, 2009 at 09:30, indika kumara<in...@gmail.com> wrote:
> > Devs
> >
> > $subject is due to we do  'detach()'  on picked resource OMElement .
> > If I add detached element to a OMDocument as a child, it works
> >
> > Existing code  SImpleURLRegistry
> >
> > result.detach();
> > inputStream.close();
> >
> >
> > Modified code
> >
> > result.detach();
> > OMDocumentImpl omDocument = new OMDocumentImpl();
> > omDocument.addChild(result);
> > inputStream.close();
> >
> >
> > Are there any best solution other than what I did ?  I haven't deep
> > AXIOM knowledge?  Could anyone help me?
> >
> > Thanks
> > Indika
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: dev-unsubscribe@synapse.apache.org
> > For additional commands, e-mail: dev-help@synapse.apache.org
> >
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@synapse.apache.org
> For additional commands, e-mail: dev-help@synapse.apache.org
>
>


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

Re: XPath evaluation doesn't work on resources picked from registry

Posted by indika kumara <in...@gmail.com>.
Thanks All

I will modify what I did based on Andreas's second option.

Thanks
Indika

On Sat, Jun 20, 2009 at 4:45 AM, Andreas Veithen
<an...@gmail.com>wrote:

> StAXOMBuilder actually already creates an OMDocument (which can be
> retrieved by the getDocument method). The important thing is that we
> need to make sure that the Axiom tree is fully built before closing
> the input stream. I guess that the detach method is used because it
> has the side effect of fully building the element and because
> OMDocument has no method to build the entire tree (see WSCOMMONS-479).
>
> This gives us two solutions:
>
> - Use StAXOMBuilder#getDocument and iterate over its children to make
> sure the document is fully built.
> - Continue to use "detach" and add the element to a new document, as
> you suggested. Note that you should not use OMDocumentImpl directly,
> but create it using the OMFactory.
>
> Andreas
>
> On Fri, Jun 19, 2009 at 09:30, indika kumara<in...@gmail.com> wrote:
> > Devs
> >
> > $subject is due to we do  'detach()'  on picked resource OMElement .
> > If I add detached element to a OMDocument as a child, it works
> >
> > Existing code  SImpleURLRegistry
> >
> > result.detach();
> > inputStream.close();
> >
> >
> > Modified code
> >
> > result.detach();
> > OMDocumentImpl omDocument = new OMDocumentImpl();
> > omDocument.addChild(result);
> > inputStream.close();
> >
> >
> > Are there any best solution other than what I did ?  I haven't deep
> > AXIOM knowledge?  Could anyone help me?
> >
> > Thanks
> > Indika
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: dev-unsubscribe@synapse.apache.org
> > For additional commands, e-mail: dev-help@synapse.apache.org
> >
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@synapse.apache.org
> For additional commands, e-mail: dev-help@synapse.apache.org
>
>

Re: XPath evaluation doesn't work on resources picked from registry

Posted by Hiranya Jayathilaka <hi...@gmail.com>.
On Sat, Jun 20, 2009 at 4:45 AM, Andreas Veithen
<an...@gmail.com>wrote:

> StAXOMBuilder actually already creates an OMDocument (which can be
> retrieved by the getDocument method). The important thing is that we
> need to make sure that the Axiom tree is fully built before closing
> the input stream. I guess that the detach method is used because it
> has the side effect of fully building the element and because
> OMDocument has no method to build the entire tree (see WSCOMMONS-479).
>
> This gives us two solutions:
>
> - Use StAXOMBuilder#getDocument and iterate over its children to make
> sure the document is fully built.
> - Continue to use "detach" and add the element to a new document, as
> you suggested. Note that you should not use OMDocumentImpl directly,
> but create it using the OMFactory.


+1  to the option #2. This seems to be  the most trivial solution right now.

Thanks,
Hiranya


>
>
> Andreas
>
> On Fri, Jun 19, 2009 at 09:30, indika kumara<in...@gmail.com> wrote:
> > Devs
> >
> > $subject is due to we do  'detach()'  on picked resource OMElement .
> > If I add detached element to a OMDocument as a child, it works
> >
> > Existing code  SImpleURLRegistry
> >
> > result.detach();
> > inputStream.close();
> >
> >
> > Modified code
> >
> > result.detach();
> > OMDocumentImpl omDocument = new OMDocumentImpl();
> > omDocument.addChild(result);
> > inputStream.close();
> >
> >
> > Are there any best solution other than what I did ?  I haven't deep
> > AXIOM knowledge?  Could anyone help me?
> >
> > Thanks
> > Indika
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: dev-unsubscribe@synapse.apache.org
> > For additional commands, e-mail: dev-help@synapse.apache.org
> >
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@synapse.apache.org
> For additional commands, e-mail: dev-help@synapse.apache.org
>
>


-- 
Hiranya Jayathilaka
Software Engineer;
WSO2 Inc.;  http://wso2.org
E-mail: hiranya@wso2.com;  Mobile: +94 77 633 3491
Blog: http://techfeast-hiranya.blogspot.com

Re: XPath evaluation doesn't work on resources picked from registry

Posted by Ruwan Linton <ru...@gmail.com>.
On Sat, Jun 20, 2009 at 4:45 AM, Andreas Veithen
<an...@gmail.com>wrote:

> StAXOMBuilder actually already creates an OMDocument (which can be
> retrieved by the getDocument method). The important thing is that we
> need to make sure that the Axiom tree is fully built before closing
> the input stream. I guess that the detach method is used because it
> has the side effect of fully building the element and because
> OMDocument has no method to build the entire tree (see WSCOMMONS-479).
>
> This gives us two solutions:
>
> - Use StAXOMBuilder#getDocument and iterate over its children to make
> sure the document is fully built.
> - Continue to use "detach" and add the element to a new document, as
> you suggested. Note that you should not use OMDocumentImpl directly,
> but create it using the OMFactory.


+1 for this second approach.

Ruwan

>
>
> Andreas
>
> On Fri, Jun 19, 2009 at 09:30, indika kumara<in...@gmail.com> wrote:
> > Devs
> >
> > $subject is due to we do  'detach()'  on picked resource OMElement .
> > If I add detached element to a OMDocument as a child, it works
> >
> > Existing code  SImpleURLRegistry
> >
> > result.detach();
> > inputStream.close();
> >
> >
> > Modified code
> >
> > result.detach();
> > OMDocumentImpl omDocument = new OMDocumentImpl();
> > omDocument.addChild(result);
> > inputStream.close();
> >
> >
> > Are there any best solution other than what I did ?  I haven't deep
> > AXIOM knowledge?  Could anyone help me?
> >
> > Thanks
> > Indika
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: dev-unsubscribe@synapse.apache.org
> > For additional commands, e-mail: dev-help@synapse.apache.org
> >
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@synapse.apache.org
> For additional commands, e-mail: dev-help@synapse.apache.org
>
>


-- 
Ruwan Linton
Senior Software Engineer & Product Manager; WSO2 ESB; http://wso2.org/esb
WSO2 Inc.; http://wso2.org
email: ruwan@wso2.com; cell: +94 77 341 3097
blog: http://ruwansblog.blogspot.com

Re: XPath evaluation doesn't work on resources picked from registry

Posted by Andreas Veithen <an...@gmail.com>.
StAXOMBuilder actually already creates an OMDocument (which can be
retrieved by the getDocument method). The important thing is that we
need to make sure that the Axiom tree is fully built before closing
the input stream. I guess that the detach method is used because it
has the side effect of fully building the element and because
OMDocument has no method to build the entire tree (see WSCOMMONS-479).

This gives us two solutions:

- Use StAXOMBuilder#getDocument and iterate over its children to make
sure the document is fully built.
- Continue to use "detach" and add the element to a new document, as
you suggested. Note that you should not use OMDocumentImpl directly,
but create it using the OMFactory.

Andreas

On Fri, Jun 19, 2009 at 09:30, indika kumara<in...@gmail.com> wrote:
> Devs
>
> $subject is due to we do  'detach()'  on picked resource OMElement .
> If I add detached element to a OMDocument as a child, it works
>
> Existing code  SImpleURLRegistry
>
> result.detach();
> inputStream.close();
>
>
> Modified code
>
> result.detach();
> OMDocumentImpl omDocument = new OMDocumentImpl();
> omDocument.addChild(result);
> inputStream.close();
>
>
> Are there any best solution other than what I did ?  I haven't deep
> AXIOM knowledge?  Could anyone help me?
>
> Thanks
> Indika
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@synapse.apache.org
> For additional commands, e-mail: dev-help@synapse.apache.org
>
>

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