From: Adam R. <ad...@ex...> - 2013-11-09 13:40:39
|
The process for extracting incoming request bodies is currently - 1) Get the Internet Media Type of the Request body from the HTTP Content-Type header from the incoming HTTP Request 2) Lookup the Internet Media Type in eXist's mime-types.xml database. 3) If the Internet Media Type is a known Binary type, extract as xs:Base64Binary 4) Else, try and parse the Request body as an XML Document, if this succeeds extract as a document() node. 5) Else, fallback to returning the Request body extracted as an xs:string The code is well annotated, so if you want to see the exact logic in detail, then you can look in: org.exist.extensions.exquery.restxq.impl.RestXqServiceImpl#extractRequestBody(HttpRequest) at line 125 of RestXqServiceImpl.java Basically the consumes annotation does not control the parsing of the request body, rather it set's a contract that it will only match the function against HTTP Requests with a HTTP Content-Type header which matches the declared Internet Media Type. As "application/json" exists in eXist's mime-types.xml database as a "binary" type, the request body will be given to you as an xs:base64Binary value. If you wish to get it into a decoded string for further processing, you can use the util:base64-decode function. Cheers Adam. On 8 November 2013 15:22, Misztur, Chris <CMi...@ma...> wrote: > With annotation %rest:consumes("application/json"), should I be able to convert base64String to xs:string? > > > > Chris Misztur | Engineer, Business Systems > 1000 Allanson Rd, Mundelein, IL 60060 (Map) > Office +1 847 837-3729 | Cell +1 312 504-0681 > www.macleanfoggcs.com > > -----Original Message----- > From: Adam Retter [mailto:ad...@ex...] > Sent: Friday, November 08, 2013 8:07 AM > To: Misztur, Chris > Cc: exi...@li... > Subject: Re: [Exist-open] restXQ and consumes JSON > > Hi Chris, > > I am not sure what you mean by "parse it into json", there is no auto-parsing for turning request bodies into JSON, it could be added in future if we could agree on a format. > > On 5 November 2013 19:55, Misztur, Chris <CMi...@ma...> wrote: >> Hi Adam. >> >> >> >> What is the appropriate handling of the $body variable to parse it >> into JSON? >> >> >> >> declare >> >> %rest:PUT("{$body}") >> >> %rest:path("/mf/08/inventory/raw") >> >> %rest:consumes("application/json") >> >> function raw:insert-tag-rq($body as xs:base64Binary) >> >> { >> >> ??? >> >> }; >> >> >> >> I am finding that I have to do this instead: >> >> >> >> declare >> >> %rest:PUT("{$body}") >> >> %rest:path("/mf/08/inventory/raw") >> >> %rest:consumes("text/html ") >> >> function raw:insert-tag-rq($body as xs:string) >> >> { >> >> Xqjson:parse-json($body) >> >> }; >> >> >> >> >> ________________________________ >> >> The contents of this message may be privileged and confidential. >> Therefore, if this message has been received in error, please delete >> it without reading it. Your receipt of this message is not intended to >> waive any applicable privilege. Please do not disseminate this message >> without the permission of the author. >> >> Please consider the environment before printing this e-mail >> >> >> ---------------------------------------------------------------------- >> -------- November Webinars for C, C++, Fortran Developers Accelerate >> application performance with scalable programming models. Explore >> techniques for threading, error checking, porting, and tuning. Get the >> most from the latest Intel processors and coprocessors. See abstracts >> and register >> http://pubads.g.doubleclick.net/gampad/clk?id=60136231&iu=/4140/ostg.c >> lktrk _______________________________________________ >> Exist-open mailing list >> Exi...@li... >> https://lists.sourceforge.net/lists/listinfo/exist-open >> > > > > -- > Adam Retter > > eXist Developer > { United Kingdom } > ad...@ex... > irc://irc.freenode.net/existdb > > ________________________________ > > The contents of this message may be privileged and confidential. Therefore, if this message has been received in error, please delete it without reading it. Your receipt of this message is not intended to waive any applicable privilege. Please do not disseminate this message without the permission of the author. > > Please consider the environment before printing this e-mail > -- Adam Retter eXist Developer { United Kingdom } ad...@ex... irc://irc.freenode.net/existdb |