Serialization issue with HTTP response

Tuesday, 15 January 2019 · 6 messages · last reply 8 Mar 2019
ML
Marco Lettere15 Jan 2019 11:35 #
Hi all, we have to deal with a third-party REST service which in case of error conditions returns this mime type: /*application/problem+json; charset=utf-8*/. I wrote this RestXQ [1] to mock it. Just copy it into restxq.xqm... When I call it like [2] I get /*[XPTY0004] Cannot convert xs:base64Binary to xs:string: "IntcImFcIjpcImJcIn0i"*/. This is because the response is seen as a binary and this can be double checked calling with [3]. I felt (maybe wrongly) that specializations of the mimetype had been faced in BaseX implementation of http:request somewhere back in time but I couldn't find anything in the mail archives. The strange thing however is that I get the same error when calling like [4] with override-mime-type set to text/json or application/json which instead I was expecting to work. Is the behaviour in this scenario expected or does this hide some inconsistency? Thanks, as usual, for the support. Regards, Marco.
[1]
declare%rest:path("mc/dummy")
%rest:GET
%output:method("json")
function page:dummy() {
   <rest:response>
     <http:response status="400">
       <http:header name="Content-Type" value="application/problem+json;
charset=utf-8"/>
     </http:response>
   </rest:response>,
   '{"a":"b"}'
};

[2]
json:parse(
   http:send-request(<http:request
method="get"/>,"http://localhost:8984/mc/dummy")[2]
)

[3]
json:parse(
   convert:binary-to-string(
     http:send-request(<http:request
method="get"/>,"http://localhost:8984/mc/dummy")[2]
   )
)

[4]
json:parse(
   http:send-request(<http:request method="get"
override-media-type="application/json"/>,"http://localhost:8984/mc/dummy")[2]
)
CG
Christian Grün16 Jan 2019 16:27 #
I hope I’ll be able to test this tomorrow. And your mail is yet another motivation to get the upcoming version 2 of the HTTP Client finished (http://expath.github.io/expath-cg/specs/http-client-2).
Quoted text · Marco Lettere · 49 lines
On Tue, Jan 15, 2019 at 11:35 AM Marco Lettere <m.lettere at gmail.com> wrote: > > Hi all, > we have to deal with a third-party REST service which in case of error conditions returns this mime type: application/problem+json; charset=utf-8. > > I wrote this RestXQ [1] to mock it. Just copy it into restxq.xqm... > > When I call it like [2] I get [XPTY0004] Cannot convert xs:base64Binary to xs:string: "IntcImFcIjpcImJcIn0i". This is because the response is seen as a binary and this can be double checked calling with [3]. > I felt (maybe wrongly) that specializations of the mimetype had been faced in BaseX implementation of http:request somewhere back in time but I couldn't find anything in the mail archives. > > The strange thing however is that I get the same error when calling like [4] with override-mime-type set to text/json or application/json which instead I was expecting to work. > > Is the behaviour in this scenario expected or does this hide some inconsistency? > > Thanks, as usual, for the support. > > Regards, > > Marco. > > [1] > declare%rest:path("mc/dummy") > %rest:GET > %output:method("json") > function page:dummy() { > <rest:response> > <http:response status="400"> > <http:header name="Content-Type" value="application/problem+json; charset=utf-8"/> > </http:response> > </rest:response>, > '{"a":"b"}' > }; > > [2] > json:parse( > http:send-request(<http:request method="get"/>,"http://localhost:8984/mc/dummy")[2] > ) > > [3] > json:parse( > convert:binary-to-string( > http:send-request(<http:request method="get"/>,"http://localhost:8984/mc/dummy")[2] > ) > ) > > [4] > json:parse( > http:send-request(<http:request method="get" override-media-type="application/json"/>,"http://localhost:8984/mc/dummy")[2] > )
ML
Marco Lettere16 Jan 2019 16:36 #
Just WoW! Looks great! M.
Quoted text · Christian Grün · 55 lines
On 16/01/19 16:27, Christian Grün wrote: > I hope I’ll be able to test this tomorrow. And your mail is yet > another motivation to get the upcoming version 2 of the HTTP Client > finished (http://expath.github.io/expath-cg/specs/http-client-2). > > > > On Tue, Jan 15, 2019 at 11:35 AM Marco Lettere <m.lettere at gmail.com> wrote: >> Hi all, >> we have to deal with a third-party REST service which in case of error conditions returns this mime type: application/problem+json; charset=utf-8. >> >> I wrote this RestXQ [1] to mock it. Just copy it into restxq.xqm... >> >> When I call it like [2] I get [XPTY0004] Cannot convert xs:base64Binary to xs:string: "IntcImFcIjpcImJcIn0i". This is because the response is seen as a binary and this can be double checked calling with [3]. >> I felt (maybe wrongly) that specializations of the mimetype had been faced in BaseX implementation of http:request somewhere back in time but I couldn't find anything in the mail archives. >> >> The strange thing however is that I get the same error when calling like [4] with override-mime-type set to text/json or application/json which instead I was expecting to work. >> >> Is the behaviour in this scenario expected or does this hide some inconsistency? >> >> Thanks, as usual, for the support. >> >> Regards, >> >> Marco. >> >> [1] >> declare%rest:path("mc/dummy") >> %rest:GET >> %output:method("json") >> function page:dummy() { >> <rest:response> >> <http:response status="400"> >> <http:header name="Content-Type" value="application/problem+json; charset=utf-8"/> >> </http:response> >> </rest:response>, >> '{"a":"b"}' >> }; >> >> [2] >> json:parse( >> http:send-request(<http:request method="get"/>,"http://localhost:8984/mc/dummy")[2] >> ) >> >> [3] >> json:parse( >> convert:binary-to-string( >> http:send-request(<http:request method="get"/>,"http://localhost:8984/mc/dummy")[2] >> ) >> ) >> >> [4] >> json:parse( >> http:send-request(<http:request method="get" override-media-type="application/json"/>,"http://localhost:8984/mc/dummy")[2] >> )
ML
Marco Letterein reply to Christian Grün, 16 Jan 2019, 16:276 Mar 2019 10:39 #
Hi Christian, I'd like to kindly ask whether there has been some follow-up on this matter... Thanks, M.
Quoted text · Christian Grün · 55 lines
On 16/01/19 16:27, Christian Grün wrote: > I hope I’ll be able to test this tomorrow. And your mail is yet > another motivation to get the upcoming version 2 of the HTTP Client > finished (http://expath.github.io/expath-cg/specs/http-client-2). > > > > On Tue, Jan 15, 2019 at 11:35 AM Marco Lettere <m.lettere at gmail.com> wrote: >> Hi all, >> we have to deal with a third-party REST service which in case of error conditions returns this mime type: application/problem+json; charset=utf-8. >> >> I wrote this RestXQ [1] to mock it. Just copy it into restxq.xqm... >> >> When I call it like [2] I get [XPTY0004] Cannot convert xs:base64Binary to xs:string: "IntcImFcIjpcImJcIn0i". This is because the response is seen as a binary and this can be double checked calling with [3]. >> I felt (maybe wrongly) that specializations of the mimetype had been faced in BaseX implementation of http:request somewhere back in time but I couldn't find anything in the mail archives. >> >> The strange thing however is that I get the same error when calling like [4] with override-mime-type set to text/json or application/json which instead I was expecting to work. >> >> Is the behaviour in this scenario expected or does this hide some inconsistency? >> >> Thanks, as usual, for the support. >> >> Regards, >> >> Marco. >> >> [1] >> declare%rest:path("mc/dummy") >> %rest:GET >> %output:method("json") >> function page:dummy() { >> <rest:response> >> <http:response status="400"> >> <http:header name="Content-Type" value="application/problem+json; charset=utf-8"/> >> </http:response> >> </rest:response>, >> '{"a":"b"}' >> }; >> >> [2] >> json:parse( >> http:send-request(<http:request method="get"/>,"http://localhost:8984/mc/dummy")[2] >> ) >> >> [3] >> json:parse( >> convert:binary-to-string( >> http:send-request(<http:request method="get"/>,"http://localhost:8984/mc/dummy")[2] >> ) >> ) >> >> [4] >> json:parse( >> http:send-request(<http:request method="get" override-media-type="application/json"/>,"http://localhost:8984/mc/dummy")[2] >> )
CG
Christian Grünin reply to Marco Lettere, 15 Jan 2019, 11:358 Mar 2019 13:16 #
Hi Marco, Sorry for letting you wait. Specializations of the json mimetype will now be detected as well [1,2]. Cheers, Christian [1] https://github.com/BaseXdb/basex/commit/a18a092b11a5240075b081ffd301014f0dc00edf [2] http://files.basex.org/releases/latest/
Quoted text · Marco Lettere · 49 lines
On Tue, Jan 15, 2019 at 11:35 AM Marco Lettere <m.lettere at gmail.com> wrote: > > Hi all, > we have to deal with a third-party REST service which in case of error conditions returns this mime type: application/problem+json; charset=utf-8. > > I wrote this RestXQ [1] to mock it. Just copy it into restxq.xqm... > > When I call it like [2] I get [XPTY0004] Cannot convert xs:base64Binary to xs:string: "IntcImFcIjpcImJcIn0i". This is because the response is seen as a binary and this can be double checked calling with [3]. > I felt (maybe wrongly) that specializations of the mimetype had been faced in BaseX implementation of http:request somewhere back in time but I couldn't find anything in the mail archives. > > The strange thing however is that I get the same error when calling like [4] with override-mime-type set to text/json or application/json which instead I was expecting to work. > > Is the behaviour in this scenario expected or does this hide some inconsistency? > > Thanks, as usual, for the support. > > Regards, > > Marco. > > [1] > declare%rest:path("mc/dummy") > %rest:GET > %output:method("json") > function page:dummy() { > <rest:response> > <http:response status="400"> > <http:header name="Content-Type" value="application/problem+json; charset=utf-8"/> > </http:response> > </rest:response>, > '{"a":"b"}' > }; > > [2] > json:parse( > http:send-request(<http:request method="get"/>,"http://localhost:8984/mc/dummy")[2] > ) > > [3] > json:parse( > convert:binary-to-string( > http:send-request(<http:request method="get"/>,"http://localhost:8984/mc/dummy")[2] > ) > ) > > [4] > json:parse( > http:send-request(<http:request method="get" override-media-type="application/json"/>,"http://localhost:8984/mc/dummy")[2] > )
ML
Marco Lettere8 Mar 2019 15:14 #
Great! Thanks!
Quoted text · Christian Grün · 61 lines
On 08/03/19 13:16, Christian Grün wrote: > Hi Marco, > > Sorry for letting you wait. Specializations of the json mimetype will > now be detected as well [1,2]. > > Cheers, > Christian > > [1] https://github.com/BaseXdb/basex/commit/a18a092b11a5240075b081ffd301014f0dc00edf > [2] http://files.basex.org/releases/latest/ > > > On Tue, Jan 15, 2019 at 11:35 AM Marco Lettere <m.lettere at gmail.com> wrote: >> Hi all, >> we have to deal with a third-party REST service which in case of error conditions returns this mime type: application/problem+json; charset=utf-8. >> >> I wrote this RestXQ [1] to mock it. Just copy it into restxq.xqm... >> >> When I call it like [2] I get [XPTY0004] Cannot convert xs:base64Binary to xs:string: "IntcImFcIjpcImJcIn0i". This is because the response is seen as a binary and this can be double checked calling with [3]. >> I felt (maybe wrongly) that specializations of the mimetype had been faced in BaseX implementation of http:request somewhere back in time but I couldn't find anything in the mail archives. >> >> The strange thing however is that I get the same error when calling like [4] with override-mime-type set to text/json or application/json which instead I was expecting to work. >> >> Is the behaviour in this scenario expected or does this hide some inconsistency? >> >> Thanks, as usual, for the support. >> >> Regards, >> >> Marco. >> >> [1] >> declare%rest:path("mc/dummy") >> %rest:GET >> %output:method("json") >> function page:dummy() { >> <rest:response> >> <http:response status="400"> >> <http:header name="Content-Type" value="application/problem+json; charset=utf-8"/> >> </http:response> >> </rest:response>, >> '{"a":"b"}' >> }; >> >> [2] >> json:parse( >> http:send-request(<http:request method="get"/>,"http://localhost:8984/mc/dummy")[2] >> ) >> >> [3] >> json:parse( >> convert:binary-to-string( >> http:send-request(<http:request method="get"/>,"http://localhost:8984/mc/dummy")[2] >> ) >> ) >> >> [4] >> json:parse( >> http:send-request(<http:request method="get" override-media-type="application/json"/>,"http://localhost:8984/mc/dummy")[2] >> )

⚡Generated with XQuery