Hi Chris,

I appreciate your accurate comments. As a lot is going on in your
query example, however, it made it difficult for me to strip it down
to the basic problem(s) you’ve been encountering. If I get it right;
for example, I didn’t understand why the request to example.org is
wrapped with db:output, what it is doing, etc.

Do you think it’s possible to simplify the example a little? The
shorter, the better ;)

Thanks in advance
Christian



On Wed, Sep 14, 2016 at 1:35 PM, chrisis <chrisisa...@gmail.com> wrote:
> I'm using BaseX 8.4 but have recreated the issue with 8.5.4 beta 8d90b66
>
> I'm POSTing xml files to a RESTXQ function using the following script
>
> let $fpath := 'C:\incoming\SAQD\mo'
> let $targetBasex := 'http://localhost:8984/saqd/mo/'
> let $list :=  sort(file:list($fpath), function($fname)
> {fn:analyze-string($fname,'.*_(.*?)\.xml$')/fn:match/fn:group[@nr="1"]/string()})
> for $file in $list
> let $abspath := $fpath||'\'||$file
> let $body := try {fetch:xml($abspath, map { 'chop': true() }) }
>              catch * {()}
>
> return if ( not(empty($body)) ) then (http:send-request(<http:request
> href="{$targetBasex||$file}"
> method='POST'>
>     <http:body media-type="text/xml">{$body}</http:body>
>     </http:request>), file:move($abspath,$fpath||'\processed\'||$file) )
>     else ()
>
> The XML file has no namespace declarations.
> The RESTXQ function does a db:update using the body received and the
> http-client namespace has been added to the root node.
>
> If I POST to the same function using curl the stored document is unchanged.
> The function is as follows.
>
> declare
> %rest:path("/saqd/mo/{$fname}")
> (: %rest:consumes("application/xml", "text/xml") :)
> %rest:POST("{$body}")
> %updating
> function saqd:mo($fname, $body as document-node())
> {
>  try {(db:replace('SAQD', '/MO/'||$fname, $body ),
>    db:output(http:send-request(<http:request
> href="{'http://example.org:8082/home/VALIDSCHEMA/xml/current/Metoffice_Data/'||$fname}"
> method='PUT' username='validuser' password='validpassword'
> send-authorization='true'>
>     <http:body media-type='text/xml'>{$body}</http:body>
>     </http:request>))
>  )
> }
> catch * {db:output(
> <rest:response>
> <http:response status="500" message="{$err:code||' : '||$err:description}">
>   </http:response>
> </rest:response>)}
> };
>
>
>  The file PUT inside the db:output statement also gets the namespace added
> i.e. it happens even when the file was POSTed with curl so the recieved
> document still had no namespaces.
>
> Is this expected behaviour, a bug, or am I using http:send-request
> incorrectly?
>
> Regards,
>
> chris sweeney
>

Reply via email to