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<[email protected]> 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 <[email protected]> > 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 <[email protected]> >> 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 <[email protected]> >> > 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 <[email protected]> >> >> 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 >> >>> <[email protected]> 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<[email protected]> >> >>>> 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: [email protected] >> >>>> > For additional commands, e-mail: [email protected] >> >>>> > >> >>>> > >> >>>> >> >>>> --------------------------------------------------------------------- >> >>>> To unsubscribe, e-mail: [email protected] >> >>>> For additional commands, e-mail: [email protected] >> >>>> >> >>> >> >>> >> >>> >> >>> -- >> >>> 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: [email protected] >> For additional commands, e-mail: [email protected] >> > > --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
