Strange behaviour on db:add inside restxq

Monday, 21 December 2015 · 7 messages · last reply 11 Jan 2016
ML
Marco Lettere21 Dec 2015 16:32 #
Hi all, We've run into a strange issue that we never experienced beforehand even if it's something we should have done thousands of time. Consider storing a resource sent through a RestXQ POST directly to a database. The restxq module module namespace o = "test";
(:sendMessage:  Send a new message:)
declare
%rest:path('test/savemsg')
%rest:POST('{$body}')
%rest:consumes("application/xml")
function o:save-message($body as document-node()) {
  db:add('hereiam', $body, 'saved.xml')
};
The client request:
http:send-request(
  <http:request method="POST" href="http://localhost:8984/test/savemsg">
    <http:body media-type="application/xml">
      <a>
         <b/>
      </a>
    </http:body>
  </http:request>
)
The resource gets stored into the DB with all the extra text nodes containing white spaces (codepoints 10 and 32) something like:
<a>

  <b/>

</a>
That's pretty strange because if I PUT the resource through Basex REST interface it doesn't create the spaces and the same if I directly db:add the resource. We noticed this oddity on BaseX 8.3.1 and could verify it on a Basex 8.2 and 8.1.1 as well. It works neatly on an older 7.9 version we still have around The applies same if the resource is sent through curl or Chrome Postman. What are we doing wrong? Thanks. Marco.
CG
Christian Grün22 Dec 2015 16:35 #
Hi Marco, I agree that this behavior is contra-intuitive. It may have been triggered by our gradual attempts to push back the default chopping of whitespaces [1]. What happens if you remove the whitespaces in your requests?
http:send-request(
  <http:request method="POST" href="http://localhost:8984/test/savemsg">
    <http:body media-type="application/xml"><a><b/></a></http:body>
  </http:request>
)
Quoted text · Marco Lettere · 55 lines
On Mon, Dec 21, 2015 at 4:32 PM, Marco Lettere <marco.lettere at dedalus.eu> wrote: > Hi all, > > We've run into a strange issue that we never experienced beforehand even if > it's something we should have done thousands of time. > > Consider storing a resource sent through a RestXQ POST directly to a > database. > > The restxq module > > > module namespace o = "test"; > > (:sendMessage: Send a new message:) > declare > %rest:path('test/savemsg') > %rest:POST('{$body}') > %rest:consumes("application/xml") > function o:save-message($body as document-node()) { > db:add('hereiam', $body, 'saved.xml') > }; > > The client request: > > http:send-request( > <http:request method="POST" href="http://localhost:8984/test/savemsg"> > <http:body media-type="application/xml"> > <a> > <b/> > </a> > </http:body> > </http:request> > ) > > The resource gets stored into the DB with all the extra text nodes > containing white spaces (codepoints 10 and 32) something like: > > <a> > > <b/> > > </a> > > That's pretty strange because if I PUT the resource through Basex REST > interface it doesn't create the spaces and the same if I directly db:add the > resource. > We noticed this oddity on BaseX 8.3.1 and could verify it on a Basex 8.2 and > 8.1.1 as well. > It works neatly on an older 7.9 version we still have around > The applies same if the resource is sent through curl or Chrome Postman. > What are we doing wrong? > Thanks. > Marco. >
ML
Marco Lettere22 Dec 2015 16:58 #
Hi Christian, the same. Even if putting the xml body on one single line with no spaces at all, exactly the three codepoints 10, 32, 32 are somehow added in the stored version of the document. :-( M.
Quoted text · Christian Grün · 72 lines
From: Christian Grün <christian.gruen at gmail.com> Sent: Tuesday, December 22, 2015 4:35 PM To: Marco Lettere Cc: BaseX Subject: Re: [basex-talk] Strange behaviour on db:add inside restxq Hi Marco, I agree that this behavior is contra-intuitive. It may have been triggered by our gradual attempts to push back the default chopping of whitespaces [1]. What happens if you remove the whitespaces in your requests? http:send-request( <http:request method="POST" href="http://localhost:8984/test/savemsg"> <http:body media-type="application/xml"><a><b/></a></http:body> </http:request> ) Christian [1] https://github.com/BaseXdb/basex/issues/913 On Mon, Dec 21, 2015 at 4:32 PM, Marco Lettere <marco.lettere at dedalus.eu> wrote: > Hi all, > > We've run into a strange issue that we never experienced beforehand even if > it's something we should have done thousands of time. > > Consider storing a resource sent through a RestXQ POST directly to a > database. > > The restxq module > > > module namespace o = "test"; > > (:sendMessage: Send a new message:) > declare > %rest:path('test/savemsg') > %rest:POST('{$body}') > %rest:consumes("application/xml") > function o:save-message($body as document-node()) { > db:add('hereiam', $body, 'saved.xml') > }; > > The client request: > > http:send-request( > <http:request method="POST" href="http://localhost:8984/test/savemsg"> > <http:body media-type="application/xml"> > <a> > <b/> > </a> > </http:body> > </http:request> > ) > > The resource gets stored into the DB with all the extra text nodes > containing white spaces (codepoints 10 and 32) something like: > > <a> > > <b/> > > </a> > > That's pretty strange because if I PUT the resource through Basex REST > interface it doesn't create the spaces and the same if I directly db:add the > resource. > We noticed this oddity on BaseX 8.3.1 and could verify it on a Basex 8.2 and > 8.1.1 as well. > It works neatly on an older 7.9 version we still have around > The applies same if the resource is sent through curl or Chrome Postman. > What are we doing wrong? > Thanks. > Marco. >
CG
Christian Grün22 Dec 2015 16:59 #
Ok, I’ll have a look at it. Might take some time, though!
Quoted text · Marco Lettere · 87 lines
On Tue, Dec 22, 2015 at 4:58 PM, Marco Lettere <marco.lettere at dedalus.eu> wrote: > Hi Christian, > the same. Even if putting the xml body on one single line with no spaces at all, exactly the three codepoints 10, 32, 32 are somehow added in the stored version of the document. :-( > M. > > ________________________________________ > From: Christian Grün <christian.gruen at gmail.com> > Sent: Tuesday, December 22, 2015 4:35 PM > To: Marco Lettere > Cc: BaseX > Subject: Re: [basex-talk] Strange behaviour on db:add inside restxq > > Hi Marco, > > I agree that this behavior is contra-intuitive. It may have been > triggered by our gradual attempts to push back the default chopping of > whitespaces [1]. > > What happens if you remove the whitespaces in your requests? > > http:send-request( > <http:request method="POST" href="http://localhost:8984/test/savemsg"> > <http:body media-type="application/xml"><a><b/></a></http:body> > </http:request> > ) > > Christian > > [1] https://github.com/BaseXdb/basex/issues/913 > > > > On Mon, Dec 21, 2015 at 4:32 PM, Marco Lettere <marco.lettere at dedalus.eu> wrote: >> Hi all, >> >> We've run into a strange issue that we never experienced beforehand even if >> it's something we should have done thousands of time. >> >> Consider storing a resource sent through a RestXQ POST directly to a >> database. >> >> The restxq module >> >> >> module namespace o = "test"; >> >> (:sendMessage: Send a new message:) >> declare >> %rest:path('test/savemsg') >> %rest:POST('{$body}') >> %rest:consumes("application/xml") >> function o:save-message($body as document-node()) { >> db:add('hereiam', $body, 'saved.xml') >> }; >> >> The client request: >> >> http:send-request( >> <http:request method="POST" href="http://localhost:8984/test/savemsg"> >> <http:body media-type="application/xml"> >> <a> >> <b/> >> </a> >> </http:body> >> </http:request> >> ) >> >> The resource gets stored into the DB with all the extra text nodes >> containing white spaces (codepoints 10 and 32) something like: >> >> <a> >> >> <b/> >> >> </a> >> >> That's pretty strange because if I PUT the resource through Basex REST >> interface it doesn't create the spaces and the same if I directly db:add the >> resource. >> We noticed this oddity on BaseX 8.3.1 and could verify it on a Basex 8.2 and >> 8.1.1 as well. >> It works neatly on an older 7.9 version we still have around >> The applies same if the resource is sent through curl or Chrome Postman. >> What are we doing wrong? >> Thanks. >> Marco. >>
ML
Marco Lettere23 Dec 2015 09:08 #
Take your time Christian and have nice Christmas holidays as I wish to everyone on the list! Ciao, Marco.
Quoted text · Christian Grün · 93 lines
From: Christian Grün <christian.gruen at gmail.com> Sent: Tuesday, December 22, 2015 4:59 PM To: Marco Lettere Cc: BaseX Subject: Re: [basex-talk] Strange behaviour on db:add inside restxq Ok, I’ll have a look at it. Might take some time, though! On Tue, Dec 22, 2015 at 4:58 PM, Marco Lettere <marco.lettere at dedalus.eu> wrote: > Hi Christian, > the same. Even if putting the xml body on one single line with no spaces at all, exactly the three codepoints 10, 32, 32 are somehow added in the stored version of the document. :-( > M. > > ________________________________________ > From: Christian Grün <christian.gruen at gmail.com> > Sent: Tuesday, December 22, 2015 4:35 PM > To: Marco Lettere > Cc: BaseX > Subject: Re: [basex-talk] Strange behaviour on db:add inside restxq > > Hi Marco, > > I agree that this behavior is contra-intuitive. It may have been > triggered by our gradual attempts to push back the default chopping of > whitespaces [1]. > > What happens if you remove the whitespaces in your requests? > > http:send-request( > <http:request method="POST" href="http://localhost:8984/test/savemsg"> > <http:body media-type="application/xml"><a><b/></a></http:body> > </http:request> > ) > > Christian > > [1] https://github.com/BaseXdb/basex/issues/913 > > > > On Mon, Dec 21, 2015 at 4:32 PM, Marco Lettere <marco.lettere at dedalus.eu> wrote: >> Hi all, >> >> We've run into a strange issue that we never experienced beforehand even if >> it's something we should have done thousands of time. >> >> Consider storing a resource sent through a RestXQ POST directly to a >> database. >> >> The restxq module >> >> >> module namespace o = "test"; >> >> (:sendMessage: Send a new message:) >> declare >> %rest:path('test/savemsg') >> %rest:POST('{$body}') >> %rest:consumes("application/xml") >> function o:save-message($body as document-node()) { >> db:add('hereiam', $body, 'saved.xml') >> }; >> >> The client request: >> >> http:send-request( >> <http:request method="POST" href="http://localhost:8984/test/savemsg"> >> <http:body media-type="application/xml"> >> <a> >> <b/> >> </a> >> </http:body> >> </http:request> >> ) >> >> The resource gets stored into the DB with all the extra text nodes >> containing white spaces (codepoints 10 and 32) something like: >> >> <a> >> >> <b/> >> >> </a> >> >> That's pretty strange because if I PUT the resource through Basex REST >> interface it doesn't create the spaces and the same if I directly db:add the >> resource. >> We noticed this oddity on BaseX 8.3.1 and could verify it on a Basex 8.2 and >> 8.1.1 as well. >> It works neatly on an older 7.9 version we still have around >> The applies same if the resource is sent through curl or Chrome Postman. >> What are we doing wrong? >> Thanks. >> Marco. >>
CG
Christian Grünin reply to Marco Lettere, 22 Dec 2015, 16:585 Jan 2016 13:44 #
Hi Marco, With the latest snapshot [1], XML bodies of http:send-request() arguments won’t be indented anymore. You can enforce this behaviour in all BaseX versions by adding the http:indent='no' option in the body element:
  http:send-request(
    <http:request method="POST" href="http://localhost:8984/test/savemsg">
      <http:body http:indent='no' media-type="application/xml">
        <a>
           <b/>
        </a>
      </http:body>
    </http:request>
  )
Hope this helps, Christian [1] http://files.basex.org/releases/latest/
Quoted text · Marco Lettere · 87 lines
On Tue, Dec 22, 2015 at 4:58 PM, Marco Lettere <marco.lettere at dedalus.eu> wrote: > Hi Christian, > the same. Even if putting the xml body on one single line with no spaces at all, exactly the three codepoints 10, 32, 32 are somehow added in the stored version of the document. :-( > M. > > ________________________________________ > From: Christian Grün <christian.gruen at gmail.com> > Sent: Tuesday, December 22, 2015 4:35 PM > To: Marco Lettere > Cc: BaseX > Subject: Re: [basex-talk] Strange behaviour on db:add inside restxq > > Hi Marco, > > I agree that this behavior is contra-intuitive. It may have been > triggered by our gradual attempts to push back the default chopping of > whitespaces [1]. > > What happens if you remove the whitespaces in your requests? > > http:send-request( > <http:request method="POST" href="http://localhost:8984/test/savemsg"> > <http:body media-type="application/xml"><a><b/></a></http:body> > </http:request> > ) > > Christian > > [1] https://github.com/BaseXdb/basex/issues/913 > > > > On Mon, Dec 21, 2015 at 4:32 PM, Marco Lettere <marco.lettere at dedalus.eu> wrote: >> Hi all, >> >> We've run into a strange issue that we never experienced beforehand even if >> it's something we should have done thousands of time. >> >> Consider storing a resource sent through a RestXQ POST directly to a >> database. >> >> The restxq module >> >> >> module namespace o = "test"; >> >> (:sendMessage: Send a new message:) >> declare >> %rest:path('test/savemsg') >> %rest:POST('{$body}') >> %rest:consumes("application/xml") >> function o:save-message($body as document-node()) { >> db:add('hereiam', $body, 'saved.xml') >> }; >> >> The client request: >> >> http:send-request( >> <http:request method="POST" href="http://localhost:8984/test/savemsg"> >> <http:body media-type="application/xml"> >> <a> >> <b/> >> </a> >> </http:body> >> </http:request> >> ) >> >> The resource gets stored into the DB with all the extra text nodes >> containing white spaces (codepoints 10 and 32) something like: >> >> <a> >> >> <b/> >> >> </a> >> >> That's pretty strange because if I PUT the resource through Basex REST >> interface it doesn't create the spaces and the same if I directly db:add the >> resource. >> We noticed this oddity on BaseX 8.3.1 and could verify it on a Basex 8.2 and >> 8.1.1 as well. >> It works neatly on an older 7.9 version we still have around >> The applies same if the resource is sent through curl or Chrome Postman. >> What are we doing wrong? >> Thanks. >> Marco. >>
ML
Marco Lettere11 Jan 2016 09:56 #
Hi Christian, thanks a lot for this! We'll give it a try soon. BR, M.
Quoted text · Christian Grün · 111 lines
On 05/01/2016 13:44, Christian Grün wrote: > Hi Marco, > > With the latest snapshot [1], XML bodies of http:send-request() > arguments won’t be indented anymore. You can enforce this behaviour in > all BaseX versions by adding the http:indent='no' option in the body > element: > > http:send-request( > <http:request method="POST" href="http://localhost:8984/test/savemsg"> > <http:body http:indent='no' media-type="application/xml"> > <a> > <b/> > </a> > </http:body> > </http:request> > ) > > Hope this helps, > Christian > > [1] http://files.basex.org/releases/latest/ > > > On Tue, Dec 22, 2015 at 4:58 PM, Marco Lettere <marco.lettere at dedalus.eu> wrote: >> Hi Christian, >> the same. Even if putting the xml body on one single line with no spaces at all, exactly the three codepoints 10, 32, 32 are somehow added in the stored version of the document. :-( >> M. >> >> ________________________________________ >> From: Christian Grün <christian.gruen at gmail.com> >> Sent: Tuesday, December 22, 2015 4:35 PM >> To: Marco Lettere >> Cc: BaseX >> Subject: Re: [basex-talk] Strange behaviour on db:add inside restxq >> >> Hi Marco, >> >> I agree that this behavior is contra-intuitive. It may have been >> triggered by our gradual attempts to push back the default chopping of >> whitespaces [1]. >> >> What happens if you remove the whitespaces in your requests? >> >> http:send-request( >> <http:request method="POST" href="http://localhost:8984/test/savemsg"> >> <http:body media-type="application/xml"><a><b/></a></http:body> >> </http:request> >> ) >> >> Christian >> >> [1] https://github.com/BaseXdb/basex/issues/913 >> >> >> >> On Mon, Dec 21, 2015 at 4:32 PM, Marco Lettere <marco.lettere at dedalus.eu> wrote: >>> Hi all, >>> >>> We've run into a strange issue that we never experienced beforehand even if >>> it's something we should have done thousands of time. >>> >>> Consider storing a resource sent through a RestXQ POST directly to a >>> database. >>> >>> The restxq module >>> >>> >>> module namespace o = "test"; >>> >>> (:sendMessage: Send a new message:) >>> declare >>> %rest:path('test/savemsg') >>> %rest:POST('{$body}') >>> %rest:consumes("application/xml") >>> function o:save-message($body as document-node()) { >>> db:add('hereiam', $body, 'saved.xml') >>> }; >>> >>> The client request: >>> >>> http:send-request( >>> <http:request method="POST" href="http://localhost:8984/test/savemsg"> >>> <http:body media-type="application/xml"> >>> <a> >>> <b/> >>> </a> >>> </http:body> >>> </http:request> >>> ) >>> >>> The resource gets stored into the DB with all the extra text nodes >>> containing white spaces (codepoints 10 and 32) something like: >>> >>> <a> >>> >>> <b/> >>> >>> </a> >>> >>> That's pretty strange because if I PUT the resource through Basex REST >>> interface it doesn't create the spaces and the same if I directly db:add the >>> resource. >>> We noticed this oddity on BaseX 8.3.1 and could verify it on a Basex 8.2 and >>> 8.1.1 as well. >>> It works neatly on an older 7.9 version we still have around >>> The applies same if the resource is sent through curl or Chrome Postman. >>> What are we doing wrong? >>> Thanks. >>> Marco. >>>

⚡Generated with XQuery