[basex-talk] ODP: - unclear strategy of setting header during serialization

2018-07-14 Thread Bogdan Bogucki
Hello CHristian,

 

Thank you for help. Understood. 

Structure  was serialized to empty string. Now It is clear for 
me why data is lost. 

 

Best Regards
Bogdan Bogucki

 

 

Od: Christian Grün [mailto:christian.gr...@gmail.com] 
Wysłano: 14 lipca 2018 13:25
Do: Bogdan Bogucki
DW: BaseX
Temat: Re: [basex-talk]  - unclear strategy of setting header 
during serialization

 

If you change the return type of an XQuery function to xs:string, your nodes 
will be implicitly converted to strings.

This is the standard behavior of XQuery and no particular feature of RESTXQ. 
Play around with the query that I presented in my previous answer.

 

You need to remove the xs:string* return typeb you can replace it with item()*.

 

 



[basex-talk] ODP: - unclear strategy of setting header during serialization

2018-07-14 Thread Bogdan Bogucki
Hello,

 

declare

  %rest:POST("{$json}")

  %rest:path("/drpg/ping")

function drpg:ping(

$json as xs:string

) as xs:string* {

  



  

  



  , 

  let $p := json:parse($json)

  return ($p/json/data/_/_/_)[last()]

};

 

Element was converted to string but header is overwritten. 

 

Response header:

 

Content-Length: 6

Content-Type: application/xml; charset=UTF-8

Date: Sat, 14 Jul 2018 11:14:32 GMT

Server: Jetty(9.4.9.v20180320)

 

How can I set  ?

 

Why when return type is element() header is set correctly ?

 

Access-Control-Allow-Origin : *

Content-Length: 11

Content-Type: text/plain;charset=utf-8

Date:  Sat, 14 Jul 2018 11:18:43 GMT

Server: Jetty(9.4.9.v20180320)

 







Pozdrawiam
Bogdan Bogucki

 

HUSSAR SYSTEMS

 

NIP: 532-170-12-00 

Regon: 142624070

 

e-mail:   bbogu...@hussar.pl
tel. kom.: +48 607 409 301
www:   www.hussar.pl

 

Od: Christian Grün [mailto:christian.gr...@gmail.com] 
Wysłano: 14 lipca 2018 11:45
Do: Bogdan Bogucki
DW: BaseX
Temat: Re: [basex-talk]  - unclear strategy of setting header 
during serialization

 

Hi Bogdan,

 

If you change the return type of an XQuery function to xs:string, your nodes 
will be implicitly converted to strings:

 

  declare function local:f() as xs:string {

X

  };

  (: will result in 'X' :)

  local:f()

 

The string conversion of your http:response element yields an empty string, so 
it does not matter what you specify as attribute values.

 

If you want to return text/plain, you’ll have to change your content type from 
text/html to to text/plain:

 

  

Best,
Christian

 

 

On Sat, Jul 14, 2018 at 11:30 AM Bogdan Bogucki  wrote:

Hello,

 

I encountered strange behavior during HTTP response.

 

I need to set custom header Access-Control-Allow-Origin:*.

 

To do that I am using custom response.

 

Following code is working and set required header:

 

declare

  %rest:POST("{$json}")

  %rest:path("/ping")

function drpg:ping(

$json as xs:string

) as element()* {

​​

  



  

​​

  



  ,  

  let $p := json:parse($json)

  return ($p/json/data/_/_/_)[last()]

};

 

Response header:


Access-Control-Allow-Origin

*

 


Content-Length

11


Content-Type

text/html;charset=utf-8


Date

Sat, 14 Jul 2018 09:17:18 GMT


Server

Jetty(9.4.9.v20180320)

 

I want to return plain text, so when I change return parameter to xs:string* 
and add data function header from  is overwritten. 

 

Response header:


Content-Length

6

 


Content-Type

application/xml; charset=UTF-8


Date

Sat, 14 Jul 2018 09:26:59 GMT


Server

Jetty(9.4.9.v20180320)

 

Example code:

declare

  %rest:POST("{$json}")

  %rest:path("/drpg/ping")

function drpg:ping(

$json as xs:string

) as xs:string* {

  



  

  



  ,  

  let $p := json:parse($json)

  return data(($p/json/data/_/_/_)[last()])

};

 

Why does header is overwritten ?  I think if header is set explicitly it 
shouldn't be overwritten. 

 

Best Regards
Bogdan Bogucki