rest:response and status 400/404

Friday, 11 April 2014 · 9 messages · last reply 16 Apr 2014
ML
Marco Lettere11 Apr 2014 16:34 #
I've the following simplified RESTXQ code snippet that I use with basex 7.8. declare %rest:path("/exists") %rest:HEAD %rest:form-param("message","{$message}") function page:exist( $message as xs:string) {
   try{
       if  ($message = 'yes') then ()
       else error(xs:QName("err:ERR"), "Message wasn't yes!")

   } catch * {
      <rest:response>
         <http:response status="404" reason="{$err:description}">
             <http:header name="DBG" value="{'message was '|| $message}"/>
         </http:response>
      </rest:response>
   }
};
This is always returning HTTP status 404 with reason "No function found that matches the request". This happens only for the 400 status code. Any other status code I use to set behaves as expected including 404 itself. Any hints? Thank you. Regards, Marco.
ML
Marco Lettere11 Apr 2014 16:38 #
Sorry for forgetting the greetings because of a misclick. ;-) Dear all, ...
Quoted text · Marco Lettere · 34 lines
> I've the following simplified RESTXQ code snippet that I use with > basex 7.8. > > declare > %rest:path("/exists") > %rest:HEAD > %rest:form-param("message","{$message}") > function page:exist( > $message as xs:string) > { > > try{ > if ($message = 'yes') then () > else error(xs:QName("err:ERR"), "Message wasn't yes!") > > } catch * { > <rest:response> > <http:response status="404" reason="{$err:description}"> > <http:header name="DBG" value="{'message was '|| $message}"/> > </http:response> > </rest:response> > } > }; > > > This is always returning HTTP status 404 with reason "No function > found that matches the request". > This happens only for the 400 status code. Any other status code I use > to set behaves as expected including 404 itself. > Any hints? > Thank you. > Regards, > Marco. >
DK
Dirk Kirstenin reply to Marco Lettere, 11 Apr 2014, 16:3411 Apr 2014 16:51 #
Hello Marco, I can't really follow. What 400 status code are you talking about, because I can't really see one in the code. I couldn't really test it because I didn't manage to tell curl to send form data and using HEAD at the same time (something like curl -I -F message=yes ... didn't work, help appreciated). But your if statement (returning the empty sequence) will result in the following error: [BASX0003] HEAD method must return a single 'restxq:response' element. Although I didn't test in in the combination, if I either use HEAD or the form param it worked. So could you please clarify in which case this code did work and what error you are experiencing? Cheers, Dirk
Quoted text · Marco Lettere · 34 lines
On 11/04/14 16:34, Marco Lettere wrote: > I've the following simplified RESTXQ code snippet that I use with basex > 7.8. > > declare > %rest:path("/exists") > %rest:HEAD > %rest:form-param("message","{$message}") > function page:exist( > $message as xs:string) > { > > try{ > if ($message = 'yes') then () > else error(xs:QName("err:ERR"), "Message wasn't yes!") > > } catch * { > <rest:response> > <http:response status="404" reason="{$err:description}"> > <http:header name="DBG" value="{'message was '|| $message}"/> > </http:response> > </rest:response> > } > }; > > > This is always returning HTTP status 404 with reason "No function found > that matches the request". > This happens only for the 400 status code. Any other status code I use > to set behaves as expected including 404 itself. > Any hints? > Thank you. > Regards, > Marco.
-- Dirk Kirsten, BaseX GmbH, http://basex.org |-- Firmensitz: Blarerstrasse 56, 78462 Konstanz |-- Registergericht Freiburg, HRB: 708285, Geschäftsführer: | Dr. Christian Grün, Dr. Alexander Holupirek, Michael Seiferle `-- Phone: 0049 7531 28 28 676, Fax: 0049 7531 20 05 22
ML
Marco Lettere11 Apr 2014 17:19 #
Sorry Dirk, I should never write mails while in a hurry. I'll try to restate my question. This is the code snippet I wanted to use: declare %rest:path("/exists") %rest:HEAD %rest:query-param("message","{$message}") function page:exist( $message as xs:string) {
   try{
       if  ($message = 'yes') then ()
       else error(xs:QName("err:ERR"), "Message wasn't yes!")

   } catch * {
      <rest:response>
         <http:response status="400" reason="{$err:description}">
             <http:header name="DBG" value="{'message was '|| $message}"/>
         </http:response>
      </rest:response>
   }
};
It should return a 400 (Invalid request) whenever an exception is raised in the implementation of the function. I understand for empty sequences but it should not impact on the test now. The point is that if I change the 400 into any other status code I get a proper response. With 400 (as it's correctly written in the code now) I get always "404 No function found that matches the request" as the response. I'm sending my requests with Firefox Poster and they look just like this: "http://localhost:8984/exists?message=vvv". For these requests I'm getting the stacktrace and the responses you can see at the end of the email. If I rewrite my query to return for instance 404 or 500 (instead of 400) I get the same stacktrace but a correct HTTP response "HTTP/1.1 404 Message wasn't yes!". I hope I could express myself better this time. Thank you, M. org.basex.http.HTTPException: No function found that matches the request. at org.basex.http.HTTPCode.get(HTTPCode.java:55) at org.basex.http.restxq.RestXqServlet.run(RestXqServlet.java:28) at org.basex.http.BaseXServlet.service(BaseXServlet.java:58) [...] at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:608) at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:543) at java.lang.Thread.run(Thread.java:744) _ REQUEST _________________________________ [HEAD /exists?message=vvv]@4563057 org.eclipse.jetty.server.Request@45a071 - Host: localhost:8984 - Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 - Accept-Language: en-US,en;q=0.5 - Connection: keep-alive - User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:28.0) Gecko/20100101 Firefox/28.0 - Accept-Encoding: gzip, deflate _ RESPONSE ________________________________ HTTP/1.1 404 No function found that matches the request. DBG: message was vvv Content-Type: text/html;charset=ISO-8859-1 Cache-Control: must-revalidate,no-cache,no-store Content-Length: 1442 java.io.IOException: Closed at org.eclipse.jetty.server.HttpOutput.write(HttpOutput.java:140) at org.eclipse.jetty.server.HttpOutput.write(HttpOutput.java:117) [...] at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:543) at java.lang.Thread.run(Thread.java:744) java.lang.IllegalStateException: Committed at org.eclipse.jetty.server.Response.resetBuffer(Response.java:1154) at org.basex.http.HTTPContext.status(HTTPContext.java:229) at org.basex.http.BaseXServlet.service(BaseXServlet.java:65) [...] at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:608) at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:543) at java.lang.Thread.run(Thread.java:744) _ REQUEST _________________________________ (HEAD /exists?message=vvv)@4563057 org.eclipse.jetty.server.Request@45a071 - Host: localhost:8984 - Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 - Accept-Language: en-US,en;q=0.5 - Connection: keep-alive - User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:28.0) Gecko/20100101 Firefox/28.0 - Accept-Encoding: gzip, deflate _ RESPONSE ________________________________ HTTP/1.1 404 No function found that matches the request. DBG: message was vvv Content-Type: text/html;charset=ISO-8859-1 Cache-Control: must-revalidate,no-cache,no-store Content-Length: 1442
Quoted text · Dirk Kirsten · 55 lines
On 04/11/2014 04:51 PM, Dirk Kirsten wrote: > Hello Marco, > > I can't really follow. What 400 status code are you talking about, > because I can't really see one in the code. > I couldn't really test it because I didn't manage to tell curl to send > form data and using HEAD at the same time (something like curl -I -F > message=yes ... didn't work, help appreciated). > > But your if statement (returning the empty sequence) will result in the > following error: > > [BASX0003] HEAD method must return a single 'restxq:response' element. > > Although I didn't test in in the combination, if I either use HEAD or > the form param it worked. So could you please clarify in which case this > code did work and what error you are experiencing? > > Cheers, > Dirk > > On 11/04/14 16:34, Marco Lettere wrote: >> I've the following simplified RESTXQ code snippet that I use with basex >> 7.8. >> >> declare >> %rest:path("/exists") >> %rest:HEAD >> %rest:form-param("message","{$message}") >> function page:exist( >> $message as xs:string) >> { >> >> try{ >> if ($message = 'yes') then () >> else error(xs:QName("err:ERR"), "Message wasn't yes!") >> >> } catch * { >> <rest:response> >> <http:response status="404" reason="{$err:description}"> >> <http:header name="DBG" value="{'message was '|| $message}"/> >> </http:response> >> </rest:response> >> } >> }; >> >> >> This is always returning HTTP status 404 with reason "No function found >> that matches the request". >> This happens only for the 400 status code. Any other status code I use >> to set behaves as expected including 404 itself. >> Any hints? >> Thank you. >> Regards, >> Marco.
DK
Dirk Kirsten13 Apr 2014 13:22 #
Hallo Marco, I tried to reproduce this now, but couldn't manage to do so. curl shows curl -I http://localhost:8984/exists?message=vvv HTTP/1.1 400 Message wasn't yes! DBG: message was vvv Content-Type: text/html;charset=ISO-8859-1 Cache-Control: must-revalidate,no-cache,no-store Content-Length: 1391 Server: Jetty(8.1.14.v20131031) There was no difference when I used another response code (except of course it returned that return code then). Are you sure you are setting the correct HEAD request in this Firefox addon? Of course also this addon could do something incorrectly with the HEAD request, so you might want to try with another tool like curl or wget. If this doesn't help, did you try the latest snapshot (which I used now)? Cheers, Dirk
Quoted text · Marco Lettere · 175 lines
On 11/04/14 17:19, Marco Lettere wrote: > Sorry Dirk, > I should never write mails while in a hurry. > I'll try to restate my question. > > This is the code snippet I wanted to use: > > declare > %rest:path("/exists") > %rest:HEAD > %rest:query-param("message","{$message}") > function page:exist( > $message as xs:string) > { > > try{ > if ($message = 'yes') then () > else error(xs:QName("err:ERR"), "Message wasn't yes!") > > } catch * { > <rest:response> > <http:response status="400" reason="{$err:description}"> > <http:header name="DBG" value="{'message was '|| $message}"/> > </http:response> > </rest:response> > } > }; > > It should return a 400 (Invalid request) whenever an exception is raised > in the implementation of the function. I understand for empty sequences > but it should not impact on the test now. > The point is that if I change the 400 into any other status code I get a > proper response. > With 400 (as it's correctly written in the code now) I get always "404 > No function found that matches the request" as the response. > > I'm sending my requests with Firefox Poster and they look just like > this: "http://localhost:8984/exists?message=vvv". For these requests I'm > getting the stacktrace and the responses you can see at the end of the > email. > > If I rewrite my query to return for instance 404 or 500 (instead of 400) > I get the same stacktrace but a correct HTTP response "HTTP/1.1 404 > Message wasn't yes!". > > I hope I could express myself better this time. > Thank you, > M. > > > org.basex.http.HTTPException: No function found that matches the request. > at org.basex.http.HTTPCode.get(HTTPCode.java:55) > at org.basex.http.restxq.RestXqServlet.run(RestXqServlet.java:28) > at org.basex.http.BaseXServlet.service(BaseXServlet.java:58) > [...] > at > org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:608) > > at > org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:543) > > at java.lang.Thread.run(Thread.java:744) > _ REQUEST _________________________________ > [HEAD /exists?message=vvv]@4563057 org.eclipse.jetty.server.Request@45a071 > - Host: localhost:8984 > - Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 > - Accept-Language: en-US,en;q=0.5 > - Connection: keep-alive > - User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:28.0) > Gecko/20100101 Firefox/28.0 > - Accept-Encoding: gzip, deflate > _ RESPONSE ________________________________ > HTTP/1.1 404 No function found that matches the request. > DBG: message was vvv > Content-Type: text/html;charset=ISO-8859-1 > Cache-Control: must-revalidate,no-cache,no-store > Content-Length: 1442 > > java.io.IOException: Closed > at org.eclipse.jetty.server.HttpOutput.write(HttpOutput.java:140) > at org.eclipse.jetty.server.HttpOutput.write(HttpOutput.java:117) > [...] > at > org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:543) > > at java.lang.Thread.run(Thread.java:744) > java.lang.IllegalStateException: Committed > at org.eclipse.jetty.server.Response.resetBuffer(Response.java:1154) > at org.basex.http.HTTPContext.status(HTTPContext.java:229) > at org.basex.http.BaseXServlet.service(BaseXServlet.java:65) > [...] > at > org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:608) > > at > org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:543) > > at java.lang.Thread.run(Thread.java:744) > _ REQUEST _________________________________ > (HEAD /exists?message=vvv)@4563057 org.eclipse.jetty.server.Request@45a071 > - Host: localhost:8984 > - Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 > - Accept-Language: en-US,en;q=0.5 > - Connection: keep-alive > - User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:28.0) > Gecko/20100101 Firefox/28.0 > - Accept-Encoding: gzip, deflate > _ RESPONSE ________________________________ > HTTP/1.1 404 No function found that matches the request. > DBG: message was vvv > Content-Type: text/html;charset=ISO-8859-1 > Cache-Control: must-revalidate,no-cache,no-store > Content-Length: 1442 > > > > > > On 04/11/2014 04:51 PM, Dirk Kirsten wrote: >> Hello Marco, >> >> I can't really follow. What 400 status code are you talking about, >> because I can't really see one in the code. >> I couldn't really test it because I didn't manage to tell curl to send >> form data and using HEAD at the same time (something like curl -I -F >> message=yes ... didn't work, help appreciated). >> >> But your if statement (returning the empty sequence) will result in the >> following error: >> >> [BASX0003] HEAD method must return a single 'restxq:response' element. >> >> Although I didn't test in in the combination, if I either use HEAD or >> the form param it worked. So could you please clarify in which case this >> code did work and what error you are experiencing? >> >> Cheers, >> Dirk >> >> On 11/04/14 16:34, Marco Lettere wrote: >>> I've the following simplified RESTXQ code snippet that I use with basex >>> 7.8. >>> >>> declare >>> %rest:path("/exists") >>> %rest:HEAD >>> %rest:form-param("message","{$message}") >>> function page:exist( >>> $message as xs:string) >>> { >>> >>> try{ >>> if ($message = 'yes') then () >>> else error(xs:QName("err:ERR"), "Message wasn't yes!") >>> >>> } catch * { >>> <rest:response> >>> <http:response status="404" reason="{$err:description}"> >>> <http:header name="DBG" value="{'message was '|| >>> $message}"/> >>> </http:response> >>> </rest:response> >>> } >>> }; >>> >>> >>> This is always returning HTTP status 404 with reason "No function found >>> that matches the request". >>> This happens only for the 400 status code. Any other status code I use >>> to set behaves as expected including 404 itself. >>> Any hints? >>> Thank you. >>> Regards, >>> Marco. >
-- Dirk Kirsten, BaseX GmbH, http://basex.org |-- Firmensitz: Blarerstrasse 56, 78462 Konstanz |-- Registergericht Freiburg, HRB: 708285, Geschäftsführer: | Dr. Christian Grün, Dr. Alexander Holupirek, Michael Seiferle `-- Phone: 0049 7531 28 28 676, Fax: 0049 7531 20 05 22
ML
Marco Lettere15 Apr 2014 13:48 #
Hi Dirk, this is the output I get when using curl (same as Poster) with response status 400:
Quoted text · Dirk Kirsten · 1 line
> curl -I http://localhost:8984/exists?message=vvv
HTTP/1.1 404 No function found that matches the request. DBG: message was vvv Content-Type: text/html;charset=ISO-8859-1 Cache-Control: must-revalidate,no-cache,no-store Content-Length: 1442 Server: Jetty(8.1.14.v20131031) whereas if I change the return status to 500
Quoted text · Dirk Kirsten · 1 line
> curl -I http://localhost:8984/exists?message=vvv
HTTP/1.1 500 Message wasn't yes! DBG: message was vvv Content-Type: text/html;charset=ISO-8859-1 Cache-Control: must-revalidate,no-cache,no-store Content-Length: 1391 Server: Jetty(8.1.14.v20131031) Just in case the issue could be related to the combination OS/JAVA: I'm using Ubuntu "12.04.4 LTS, Precise Pangolin" and running Openjdk 7. Thanks again and regards, M.
Quoted text · Dirk Kirsten · 199 lines
On 04/13/2014 01:22 PM, Dirk Kirsten wrote: > Hallo Marco, > > I tried to reproduce this now, but couldn't manage to do so. curl shows > > curl -I http://localhost:8984/exists?message=vvv > HTTP/1.1 400 Message wasn't yes! > DBG: message was vvv > Content-Type: text/html;charset=ISO-8859-1 > Cache-Control: must-revalidate,no-cache,no-store > Content-Length: 1391 > Server: Jetty(8.1.14.v20131031) > > There was no difference when I used another response code (except of > course it returned that return code then). > > Are you sure you are setting the correct HEAD request in this Firefox > addon? Of course also this addon could do something incorrectly with the > HEAD request, so you might want to try with another tool like curl or wget. > > If this doesn't help, did you try the latest snapshot (which I used now)? > > Cheers, > Dirk > > On 11/04/14 17:19, Marco Lettere wrote: >> Sorry Dirk, >> I should never write mails while in a hurry. >> I'll try to restate my question. >> >> This is the code snippet I wanted to use: >> >> declare >> %rest:path("/exists") >> %rest:HEAD >> %rest:query-param("message","{$message}") >> function page:exist( >> $message as xs:string) >> { >> >> try{ >> if ($message = 'yes') then () >> else error(xs:QName("err:ERR"), "Message wasn't yes!") >> >> } catch * { >> <rest:response> >> <http:response status="400" reason="{$err:description}"> >> <http:header name="DBG" value="{'message was '|| $message}"/> >> </http:response> >> </rest:response> >> } >> }; >> >> It should return a 400 (Invalid request) whenever an exception is raised >> in the implementation of the function. I understand for empty sequences >> but it should not impact on the test now. >> The point is that if I change the 400 into any other status code I get a >> proper response. >> With 400 (as it's correctly written in the code now) I get always "404 >> No function found that matches the request" as the response. >> >> I'm sending my requests with Firefox Poster and they look just like >> this: "http://localhost:8984/exists?message=vvv". For these requests I'm >> getting the stacktrace and the responses you can see at the end of the >> email. >> >> If I rewrite my query to return for instance 404 or 500 (instead of 400) >> I get the same stacktrace but a correct HTTP response "HTTP/1.1 404 >> Message wasn't yes!". >> >> I hope I could express myself better this time. >> Thank you, >> M. >> >> >> org.basex.http.HTTPException: No function found that matches the request. >> at org.basex.http.HTTPCode.get(HTTPCode.java:55) >> at org.basex.http.restxq.RestXqServlet.run(RestXqServlet.java:28) >> at org.basex.http.BaseXServlet.service(BaseXServlet.java:58) >> [...] >> at >> org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:608) >> >> at >> org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:543) >> >> at java.lang.Thread.run(Thread.java:744) >> _ REQUEST _________________________________ >> [HEAD /exists?message=vvv]@4563057 org.eclipse.jetty.server.Request@45a071 >> - Host: localhost:8984 >> - Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 >> - Accept-Language: en-US,en;q=0.5 >> - Connection: keep-alive >> - User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:28.0) >> Gecko/20100101 Firefox/28.0 >> - Accept-Encoding: gzip, deflate >> _ RESPONSE ________________________________ >> HTTP/1.1 404 No function found that matches the request. >> DBG: message was vvv >> Content-Type: text/html;charset=ISO-8859-1 >> Cache-Control: must-revalidate,no-cache,no-store >> Content-Length: 1442 >> >> java.io.IOException: Closed >> at org.eclipse.jetty.server.HttpOutput.write(HttpOutput.java:140) >> at org.eclipse.jetty.server.HttpOutput.write(HttpOutput.java:117) >> [...] >> at >> org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:543) >> >> at java.lang.Thread.run(Thread.java:744) >> java.lang.IllegalStateException: Committed >> at org.eclipse.jetty.server.Response.resetBuffer(Response.java:1154) >> at org.basex.http.HTTPContext.status(HTTPContext.java:229) >> at org.basex.http.BaseXServlet.service(BaseXServlet.java:65) >> [...] >> at >> org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:608) >> >> at >> org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:543) >> >> at java.lang.Thread.run(Thread.java:744) >> _ REQUEST _________________________________ >> (HEAD /exists?message=vvv)@4563057 org.eclipse.jetty.server.Request@45a071 >> - Host: localhost:8984 >> - Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 >> - Accept-Language: en-US,en;q=0.5 >> - Connection: keep-alive >> - User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:28.0) >> Gecko/20100101 Firefox/28.0 >> - Accept-Encoding: gzip, deflate >> _ RESPONSE ________________________________ >> HTTP/1.1 404 No function found that matches the request. >> DBG: message was vvv >> Content-Type: text/html;charset=ISO-8859-1 >> Cache-Control: must-revalidate,no-cache,no-store >> Content-Length: 1442 >> >> >> >> >> >> On 04/11/2014 04:51 PM, Dirk Kirsten wrote: >>> Hello Marco, >>> >>> I can't really follow. What 400 status code are you talking about, >>> because I can't really see one in the code. >>> I couldn't really test it because I didn't manage to tell curl to send >>> form data and using HEAD at the same time (something like curl -I -F >>> message=yes ... didn't work, help appreciated). >>> >>> But your if statement (returning the empty sequence) will result in the >>> following error: >>> >>> [BASX0003] HEAD method must return a single 'restxq:response' element. >>> >>> Although I didn't test in in the combination, if I either use HEAD or >>> the form param it worked. So could you please clarify in which case this >>> code did work and what error you are experiencing? >>> >>> Cheers, >>> Dirk >>> >>> On 11/04/14 16:34, Marco Lettere wrote: >>>> I've the following simplified RESTXQ code snippet that I use with basex >>>> 7.8. >>>> >>>> declare >>>> %rest:path("/exists") >>>> %rest:HEAD >>>> %rest:form-param("message","{$message}") >>>> function page:exist( >>>> $message as xs:string) >>>> { >>>> >>>> try{ >>>> if ($message = 'yes') then () >>>> else error(xs:QName("err:ERR"), "Message wasn't yes!") >>>> >>>> } catch * { >>>> <rest:response> >>>> <http:response status="404" reason="{$err:description}"> >>>> <http:header name="DBG" value="{'message was '|| >>>> $message}"/> >>>> </http:response> >>>> </rest:response> >>>> } >>>> }; >>>> >>>> >>>> This is always returning HTTP status 404 with reason "No function found >>>> that matches the request". >>>> This happens only for the 400 status code. Any other status code I use >>>> to set behaves as expected including 404 itself. >>>> Any hints? >>>> Thank you. >>>> Regards, >>>> Marco.
DK
Dirk Kirsten15 Apr 2014 20:13 #
Hi Marco, what BaseX version are you using? Did you try with the latest snapshot? Cheers, Dirk
Quoted text · Marco Lettere · 247 lines
On 15/04/14 13:48, Marco Lettere wrote: > Hi Dirk, > this is the output I get when using curl (same as Poster) with response > status 400: > >> curl -I http://localhost:8984/exists?message=vvv > > HTTP/1.1 404 No function found that matches the request. > DBG: message was vvv > Content-Type: text/html;charset=ISO-8859-1 > Cache-Control: must-revalidate,no-cache,no-store > Content-Length: 1442 > Server: Jetty(8.1.14.v20131031) > > whereas if I change the return status to 500 > >> curl -I http://localhost:8984/exists?message=vvv > > HTTP/1.1 500 Message wasn't yes! > DBG: message was vvv > Content-Type: text/html;charset=ISO-8859-1 > Cache-Control: must-revalidate,no-cache,no-store > Content-Length: 1391 > Server: Jetty(8.1.14.v20131031) > > Just in case the issue could be related to the combination OS/JAVA: > I'm using Ubuntu "12.04.4 LTS, Precise Pangolin" and running Openjdk 7. > Thanks again and regards, > M. > > On 04/13/2014 01:22 PM, Dirk Kirsten wrote: >> Hallo Marco, >> >> I tried to reproduce this now, but couldn't manage to do so. curl shows >> >> curl -I http://localhost:8984/exists?message=vvv >> HTTP/1.1 400 Message wasn't yes! >> DBG: message was vvv >> Content-Type: text/html;charset=ISO-8859-1 >> Cache-Control: must-revalidate,no-cache,no-store >> Content-Length: 1391 >> Server: Jetty(8.1.14.v20131031) >> >> There was no difference when I used another response code (except of >> course it returned that return code then). >> >> Are you sure you are setting the correct HEAD request in this Firefox >> addon? Of course also this addon could do something incorrectly with the >> HEAD request, so you might want to try with another tool like curl or >> wget. >> >> If this doesn't help, did you try the latest snapshot (which I used now)? >> >> Cheers, >> Dirk >> >> On 11/04/14 17:19, Marco Lettere wrote: >>> Sorry Dirk, >>> I should never write mails while in a hurry. >>> I'll try to restate my question. >>> >>> This is the code snippet I wanted to use: >>> >>> declare >>> %rest:path("/exists") >>> %rest:HEAD >>> %rest:query-param("message","{$message}") >>> function page:exist( >>> $message as xs:string) >>> { >>> >>> try{ >>> if ($message = 'yes') then () >>> else error(xs:QName("err:ERR"), "Message wasn't yes!") >>> >>> } catch * { >>> <rest:response> >>> <http:response status="400" reason="{$err:description}"> >>> <http:header name="DBG" value="{'message was '|| >>> $message}"/> >>> </http:response> >>> </rest:response> >>> } >>> }; >>> >>> It should return a 400 (Invalid request) whenever an exception is raised >>> in the implementation of the function. I understand for empty sequences >>> but it should not impact on the test now. >>> The point is that if I change the 400 into any other status code I get a >>> proper response. >>> With 400 (as it's correctly written in the code now) I get always "404 >>> No function found that matches the request" as the response. >>> >>> I'm sending my requests with Firefox Poster and they look just like >>> this: "http://localhost:8984/exists?message=vvv". For these requests I'm >>> getting the stacktrace and the responses you can see at the end of the >>> email. >>> >>> If I rewrite my query to return for instance 404 or 500 (instead of 400) >>> I get the same stacktrace but a correct HTTP response "HTTP/1.1 404 >>> Message wasn't yes!". >>> >>> I hope I could express myself better this time. >>> Thank you, >>> M. >>> >>> >>> org.basex.http.HTTPException: No function found that matches the >>> request. >>> at org.basex.http.HTTPCode.get(HTTPCode.java:55) >>> at org.basex.http.restxq.RestXqServlet.run(RestXqServlet.java:28) >>> at org.basex.http.BaseXServlet.service(BaseXServlet.java:58) >>> [...] >>> at >>> org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:608) >>> >>> >>> at >>> org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:543) >>> >>> >>> at java.lang.Thread.run(Thread.java:744) >>> _ REQUEST _________________________________ >>> [HEAD /exists?message=vvv]@4563057 >>> org.eclipse.jetty.server.Request@45a071 >>> - Host: localhost:8984 >>> - Accept: >>> text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 >>> - Accept-Language: en-US,en;q=0.5 >>> - Connection: keep-alive >>> - User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:28.0) >>> Gecko/20100101 Firefox/28.0 >>> - Accept-Encoding: gzip, deflate >>> _ RESPONSE ________________________________ >>> HTTP/1.1 404 No function found that matches the request. >>> DBG: message was vvv >>> Content-Type: text/html;charset=ISO-8859-1 >>> Cache-Control: must-revalidate,no-cache,no-store >>> Content-Length: 1442 >>> >>> java.io.IOException: Closed >>> at org.eclipse.jetty.server.HttpOutput.write(HttpOutput.java:140) >>> at org.eclipse.jetty.server.HttpOutput.write(HttpOutput.java:117) >>> [...] >>> at >>> org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:543) >>> >>> >>> at java.lang.Thread.run(Thread.java:744) >>> java.lang.IllegalStateException: Committed >>> at >>> org.eclipse.jetty.server.Response.resetBuffer(Response.java:1154) >>> at org.basex.http.HTTPContext.status(HTTPContext.java:229) >>> at org.basex.http.BaseXServlet.service(BaseXServlet.java:65) >>> [...] >>> at >>> org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:608) >>> >>> >>> at >>> org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:543) >>> >>> >>> at java.lang.Thread.run(Thread.java:744) >>> _ REQUEST _________________________________ >>> (HEAD /exists?message=vvv)@4563057 >>> org.eclipse.jetty.server.Request@45a071 >>> - Host: localhost:8984 >>> - Accept: >>> text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 >>> - Accept-Language: en-US,en;q=0.5 >>> - Connection: keep-alive >>> - User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:28.0) >>> Gecko/20100101 Firefox/28.0 >>> - Accept-Encoding: gzip, deflate >>> _ RESPONSE ________________________________ >>> HTTP/1.1 404 No function found that matches the request. >>> DBG: message was vvv >>> Content-Type: text/html;charset=ISO-8859-1 >>> Cache-Control: must-revalidate,no-cache,no-store >>> Content-Length: 1442 >>> >>> >>> >>> >>> >>> On 04/11/2014 04:51 PM, Dirk Kirsten wrote: >>>> Hello Marco, >>>> >>>> I can't really follow. What 400 status code are you talking about, >>>> because I can't really see one in the code. >>>> I couldn't really test it because I didn't manage to tell curl to send >>>> form data and using HEAD at the same time (something like curl -I -F >>>> message=yes ... didn't work, help appreciated). >>>> >>>> But your if statement (returning the empty sequence) will result in the >>>> following error: >>>> >>>> [BASX0003] HEAD method must return a single 'restxq:response' >>>> element. >>>> >>>> Although I didn't test in in the combination, if I either use HEAD or >>>> the form param it worked. So could you please clarify in which case >>>> this >>>> code did work and what error you are experiencing? >>>> >>>> Cheers, >>>> Dirk >>>> >>>> On 11/04/14 16:34, Marco Lettere wrote: >>>>> I've the following simplified RESTXQ code snippet that I use with >>>>> basex >>>>> 7.8. >>>>> >>>>> declare >>>>> %rest:path("/exists") >>>>> %rest:HEAD >>>>> %rest:form-param("message","{$message}") >>>>> function page:exist( >>>>> $message as xs:string) >>>>> { >>>>> >>>>> try{ >>>>> if ($message = 'yes') then () >>>>> else error(xs:QName("err:ERR"), "Message wasn't yes!") >>>>> >>>>> } catch * { >>>>> <rest:response> >>>>> <http:response status="404" reason="{$err:description}"> >>>>> <http:header name="DBG" value="{'message was '|| >>>>> $message}"/> >>>>> </http:response> >>>>> </rest:response> >>>>> } >>>>> }; >>>>> >>>>> >>>>> This is always returning HTTP status 404 with reason "No function >>>>> found >>>>> that matches the request". >>>>> This happens only for the 400 status code. Any other status code I use >>>>> to set behaves as expected including 404 itself. >>>>> Any hints? >>>>> Thank you. >>>>> Regards, >>>>> Marco. >
-- Dirk Kirsten, BaseX GmbH, http://basex.org |-- Firmensitz: Blarerstrasse 56, 78462 Konstanz |-- Registergericht Freiburg, HRB: 708285, Geschäftsführer: | Dr. Christian Grün, Dr. Alexander Holupirek, Michael Seiferle `-- Phone: 0049 7531 28 28 676, Fax: 0049 7531 20 05 22
ML
Marco Lettere16 Apr 2014 13:47 #
Hi Dirk, 8.2. I'll try the latest. Thanks, M.
Quoted text · Dirk Kirsten · 252 lines
On 04/15/2014 08:13 PM, Dirk Kirsten wrote: > Hi Marco, > > what BaseX version are you using? Did you try with the latest snapshot? > > Cheers, > Dirk > > On 15/04/14 13:48, Marco Lettere wrote: >> Hi Dirk, >> this is the output I get when using curl (same as Poster) with response >> status 400: >> >>> curl -I http://localhost:8984/exists?message=vvv >> HTTP/1.1 404 No function found that matches the request. >> DBG: message was vvv >> Content-Type: text/html;charset=ISO-8859-1 >> Cache-Control: must-revalidate,no-cache,no-store >> Content-Length: 1442 >> Server: Jetty(8.1.14.v20131031) >> >> whereas if I change the return status to 500 >> >>> curl -I http://localhost:8984/exists?message=vvv >> HTTP/1.1 500 Message wasn't yes! >> DBG: message was vvv >> Content-Type: text/html;charset=ISO-8859-1 >> Cache-Control: must-revalidate,no-cache,no-store >> Content-Length: 1391 >> Server: Jetty(8.1.14.v20131031) >> >> Just in case the issue could be related to the combination OS/JAVA: >> I'm using Ubuntu "12.04.4 LTS, Precise Pangolin" and running Openjdk 7. >> Thanks again and regards, >> M. >> >> On 04/13/2014 01:22 PM, Dirk Kirsten wrote: >>> Hallo Marco, >>> >>> I tried to reproduce this now, but couldn't manage to do so. curl shows >>> >>> curl -I http://localhost:8984/exists?message=vvv >>> HTTP/1.1 400 Message wasn't yes! >>> DBG: message was vvv >>> Content-Type: text/html;charset=ISO-8859-1 >>> Cache-Control: must-revalidate,no-cache,no-store >>> Content-Length: 1391 >>> Server: Jetty(8.1.14.v20131031) >>> >>> There was no difference when I used another response code (except of >>> course it returned that return code then). >>> >>> Are you sure you are setting the correct HEAD request in this Firefox >>> addon? Of course also this addon could do something incorrectly with the >>> HEAD request, so you might want to try with another tool like curl or >>> wget. >>> >>> If this doesn't help, did you try the latest snapshot (which I used now)? >>> >>> Cheers, >>> Dirk >>> >>> On 11/04/14 17:19, Marco Lettere wrote: >>>> Sorry Dirk, >>>> I should never write mails while in a hurry. >>>> I'll try to restate my question. >>>> >>>> This is the code snippet I wanted to use: >>>> >>>> declare >>>> %rest:path("/exists") >>>> %rest:HEAD >>>> %rest:query-param("message","{$message}") >>>> function page:exist( >>>> $message as xs:string) >>>> { >>>> >>>> try{ >>>> if ($message = 'yes') then () >>>> else error(xs:QName("err:ERR"), "Message wasn't yes!") >>>> >>>> } catch * { >>>> <rest:response> >>>> <http:response status="400" reason="{$err:description}"> >>>> <http:header name="DBG" value="{'message was '|| >>>> $message}"/> >>>> </http:response> >>>> </rest:response> >>>> } >>>> }; >>>> >>>> It should return a 400 (Invalid request) whenever an exception is raised >>>> in the implementation of the function. I understand for empty sequences >>>> but it should not impact on the test now. >>>> The point is that if I change the 400 into any other status code I get a >>>> proper response. >>>> With 400 (as it's correctly written in the code now) I get always "404 >>>> No function found that matches the request" as the response. >>>> >>>> I'm sending my requests with Firefox Poster and they look just like >>>> this: "http://localhost:8984/exists?message=vvv". For these requests I'm >>>> getting the stacktrace and the responses you can see at the end of the >>>> email. >>>> >>>> If I rewrite my query to return for instance 404 or 500 (instead of 400) >>>> I get the same stacktrace but a correct HTTP response "HTTP/1.1 404 >>>> Message wasn't yes!". >>>> >>>> I hope I could express myself better this time. >>>> Thank you, >>>> M. >>>> >>>> >>>> org.basex.http.HTTPException: No function found that matches the >>>> request. >>>> at org.basex.http.HTTPCode.get(HTTPCode.java:55) >>>> at org.basex.http.restxq.RestXqServlet.run(RestXqServlet.java:28) >>>> at org.basex.http.BaseXServlet.service(BaseXServlet.java:58) >>>> [...] >>>> at >>>> org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:608) >>>> >>>> >>>> at >>>> org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:543) >>>> >>>> >>>> at java.lang.Thread.run(Thread.java:744) >>>> _ REQUEST _________________________________ >>>> [HEAD /exists?message=vvv]@4563057 >>>> org.eclipse.jetty.server.Request@45a071 >>>> - Host: localhost:8984 >>>> - Accept: >>>> text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 >>>> - Accept-Language: en-US,en;q=0.5 >>>> - Connection: keep-alive >>>> - User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:28.0) >>>> Gecko/20100101 Firefox/28.0 >>>> - Accept-Encoding: gzip, deflate >>>> _ RESPONSE ________________________________ >>>> HTTP/1.1 404 No function found that matches the request. >>>> DBG: message was vvv >>>> Content-Type: text/html;charset=ISO-8859-1 >>>> Cache-Control: must-revalidate,no-cache,no-store >>>> Content-Length: 1442 >>>> >>>> java.io.IOException: Closed >>>> at org.eclipse.jetty.server.HttpOutput.write(HttpOutput.java:140) >>>> at org.eclipse.jetty.server.HttpOutput.write(HttpOutput.java:117) >>>> [...] >>>> at >>>> org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:543) >>>> >>>> >>>> at java.lang.Thread.run(Thread.java:744) >>>> java.lang.IllegalStateException: Committed >>>> at >>>> org.eclipse.jetty.server.Response.resetBuffer(Response.java:1154) >>>> at org.basex.http.HTTPContext.status(HTTPContext.java:229) >>>> at org.basex.http.BaseXServlet.service(BaseXServlet.java:65) >>>> [...] >>>> at >>>> org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:608) >>>> >>>> >>>> at >>>> org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:543) >>>> >>>> >>>> at java.lang.Thread.run(Thread.java:744) >>>> _ REQUEST _________________________________ >>>> (HEAD /exists?message=vvv)@4563057 >>>> org.eclipse.jetty.server.Request@45a071 >>>> - Host: localhost:8984 >>>> - Accept: >>>> text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 >>>> - Accept-Language: en-US,en;q=0.5 >>>> - Connection: keep-alive >>>> - User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:28.0) >>>> Gecko/20100101 Firefox/28.0 >>>> - Accept-Encoding: gzip, deflate >>>> _ RESPONSE ________________________________ >>>> HTTP/1.1 404 No function found that matches the request. >>>> DBG: message was vvv >>>> Content-Type: text/html;charset=ISO-8859-1 >>>> Cache-Control: must-revalidate,no-cache,no-store >>>> Content-Length: 1442 >>>> >>>> >>>> >>>> >>>> >>>> On 04/11/2014 04:51 PM, Dirk Kirsten wrote: >>>>> Hello Marco, >>>>> >>>>> I can't really follow. What 400 status code are you talking about, >>>>> because I can't really see one in the code. >>>>> I couldn't really test it because I didn't manage to tell curl to send >>>>> form data and using HEAD at the same time (something like curl -I -F >>>>> message=yes ... didn't work, help appreciated). >>>>> >>>>> But your if statement (returning the empty sequence) will result in the >>>>> following error: >>>>> >>>>> [BASX0003] HEAD method must return a single 'restxq:response' >>>>> element. >>>>> >>>>> Although I didn't test in in the combination, if I either use HEAD or >>>>> the form param it worked. So could you please clarify in which case >>>>> this >>>>> code did work and what error you are experiencing? >>>>> >>>>> Cheers, >>>>> Dirk >>>>> >>>>> On 11/04/14 16:34, Marco Lettere wrote: >>>>>> I've the following simplified RESTXQ code snippet that I use with >>>>>> basex >>>>>> 7.8. >>>>>> >>>>>> declare >>>>>> %rest:path("/exists") >>>>>> %rest:HEAD >>>>>> %rest:form-param("message","{$message}") >>>>>> function page:exist( >>>>>> $message as xs:string) >>>>>> { >>>>>> >>>>>> try{ >>>>>> if ($message = 'yes') then () >>>>>> else error(xs:QName("err:ERR"), "Message wasn't yes!") >>>>>> >>>>>> } catch * { >>>>>> <rest:response> >>>>>> <http:response status="404" reason="{$err:description}"> >>>>>> <http:header name="DBG" value="{'message was '|| >>>>>> $message}"/> >>>>>> </http:response> >>>>>> </rest:response> >>>>>> } >>>>>> }; >>>>>> >>>>>> >>>>>> This is always returning HTTP status 404 with reason "No function >>>>>> found >>>>>> that matches the request". >>>>>> This happens only for the 400 status code. Any other status code I use >>>>>> to set behaves as expected including 404 itself. >>>>>> Any hints? >>>>>> Thank you. >>>>>> Regards, >>>>>> Marco.
ML
Marco Lettere16 Apr 2014 14:58 #
Hello again, of course I meant 7.8.2 and not 8.2 :-(. In the meanwhile I've discovered that when I override the rest:response with any status different from 20X, I always get the body as text/plain even if it's XML. Example code for a 500 response with a SOAP fault element:
local:errorHTTP($msg as node()) {
    <rest:response>
         <http:response status="500">
             <http:header name="Content-Type" value="text/xml" />
         </http:response>
    </rest:response>,
    $msg
};
Return:
<http:response
     xmlns:http="http://expath.org/ns/http-client" status="500"
message="Server Error">
     <http:header name="Content-Length" value="553"/>
     <http:header name="Content-Type" value="text/xml;charset=UTF-8"/>
     <http:header name="Server" value="Jetty(8.1.11.v20130520)"/>
     <http:body media-type="text/plain"/>
</http:response>&lt;soapenv:Envelope
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"&gt;&#xD;
   &lt;soapenv:Header/&gt;&#xD;
   &lt;soapenv:Body&gt;&#xD;
     &lt;soapenv:Fault&gt;&#xD;
&lt;faultcode&gt;soapenv:Client&lt;/faultcode&gt;&#xD;
       [...]
     &lt;/soapenv:Fault&gt;&#xD;
   &lt;/soapenv:Body&gt;&#xD;
&lt;/soapenv:Envelope&gt;
Is this expected? Thanks, Marco.
Quoted text · Marco Lettere · 285 lines
On 04/16/2014 01:47 PM, Marco Lettere wrote: > Hi Dirk, > > 8.2. > > I'll try the latest. > Thanks, > M. > > On 04/15/2014 08:13 PM, Dirk Kirsten wrote: >> Hi Marco, >> >> what BaseX version are you using? Did you try with the latest snapshot? >> >> Cheers, >> Dirk >> >> On 15/04/14 13:48, Marco Lettere wrote: >>> Hi Dirk, >>> this is the output I get when using curl (same as Poster) with response >>> status 400: >>> >>>> curl -I http://localhost:8984/exists?message=vvv >>> HTTP/1.1 404 No function found that matches the request. >>> DBG: message was vvv >>> Content-Type: text/html;charset=ISO-8859-1 >>> Cache-Control: must-revalidate,no-cache,no-store >>> Content-Length: 1442 >>> Server: Jetty(8.1.14.v20131031) >>> >>> whereas if I change the return status to 500 >>> >>>> curl -I http://localhost:8984/exists?message=vvv >>> HTTP/1.1 500 Message wasn't yes! >>> DBG: message was vvv >>> Content-Type: text/html;charset=ISO-8859-1 >>> Cache-Control: must-revalidate,no-cache,no-store >>> Content-Length: 1391 >>> Server: Jetty(8.1.14.v20131031) >>> >>> Just in case the issue could be related to the combination OS/JAVA: >>> I'm using Ubuntu "12.04.4 LTS, Precise Pangolin" and running Openjdk 7. >>> Thanks again and regards, >>> M. >>> >>> On 04/13/2014 01:22 PM, Dirk Kirsten wrote: >>>> Hallo Marco, >>>> >>>> I tried to reproduce this now, but couldn't manage to do so. curl >>>> shows >>>> >>>> curl -I http://localhost:8984/exists?message=vvv >>>> HTTP/1.1 400 Message wasn't yes! >>>> DBG: message was vvv >>>> Content-Type: text/html;charset=ISO-8859-1 >>>> Cache-Control: must-revalidate,no-cache,no-store >>>> Content-Length: 1391 >>>> Server: Jetty(8.1.14.v20131031) >>>> >>>> There was no difference when I used another response code (except of >>>> course it returned that return code then). >>>> >>>> Are you sure you are setting the correct HEAD request in this Firefox >>>> addon? Of course also this addon could do something incorrectly >>>> with the >>>> HEAD request, so you might want to try with another tool like curl or >>>> wget. >>>> >>>> If this doesn't help, did you try the latest snapshot (which I used >>>> now)? >>>> >>>> Cheers, >>>> Dirk >>>> >>>> On 11/04/14 17:19, Marco Lettere wrote: >>>>> Sorry Dirk, >>>>> I should never write mails while in a hurry. >>>>> I'll try to restate my question. >>>>> >>>>> This is the code snippet I wanted to use: >>>>> >>>>> declare >>>>> %rest:path("/exists") >>>>> %rest:HEAD >>>>> %rest:query-param("message","{$message}") >>>>> function page:exist( >>>>> $message as xs:string) >>>>> { >>>>> >>>>> try{ >>>>> if ($message = 'yes') then () >>>>> else error(xs:QName("err:ERR"), "Message wasn't yes!") >>>>> >>>>> } catch * { >>>>> <rest:response> >>>>> <http:response status="400" reason="{$err:description}"> >>>>> <http:header name="DBG" value="{'message was '|| >>>>> $message}"/> >>>>> </http:response> >>>>> </rest:response> >>>>> } >>>>> }; >>>>> >>>>> It should return a 400 (Invalid request) whenever an exception is >>>>> raised >>>>> in the implementation of the function. I understand for empty >>>>> sequences >>>>> but it should not impact on the test now. >>>>> The point is that if I change the 400 into any other status code I >>>>> get a >>>>> proper response. >>>>> With 400 (as it's correctly written in the code now) I get always >>>>> "404 >>>>> No function found that matches the request" as the response. >>>>> >>>>> I'm sending my requests with Firefox Poster and they look just like >>>>> this: "http://localhost:8984/exists?message=vvv". For these >>>>> requests I'm >>>>> getting the stacktrace and the responses you can see at the end of >>>>> the >>>>> email. >>>>> >>>>> If I rewrite my query to return for instance 404 or 500 (instead >>>>> of 400) >>>>> I get the same stacktrace but a correct HTTP response "HTTP/1.1 404 >>>>> Message wasn't yes!". >>>>> >>>>> I hope I could express myself better this time. >>>>> Thank you, >>>>> M. >>>>> >>>>> >>>>> org.basex.http.HTTPException: No function found that matches the >>>>> request. >>>>> at org.basex.http.HTTPCode.get(HTTPCode.java:55) >>>>> at >>>>> org.basex.http.restxq.RestXqServlet.run(RestXqServlet.java:28) >>>>> at org.basex.http.BaseXServlet.service(BaseXServlet.java:58) >>>>> [...] >>>>> at >>>>> org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:608) >>>>> >>>>> >>>>> >>>>> at >>>>> org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:543) >>>>> >>>>> >>>>> >>>>> at java.lang.Thread.run(Thread.java:744) >>>>> _ REQUEST _________________________________ >>>>> [HEAD /exists?message=vvv]@4563057 >>>>> org.eclipse.jetty.server.Request@45a071 >>>>> - Host: localhost:8984 >>>>> - Accept: >>>>> text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 >>>>> - Accept-Language: en-US,en;q=0.5 >>>>> - Connection: keep-alive >>>>> - User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:28.0) >>>>> Gecko/20100101 Firefox/28.0 >>>>> - Accept-Encoding: gzip, deflate >>>>> _ RESPONSE ________________________________ >>>>> HTTP/1.1 404 No function found that matches the request. >>>>> DBG: message was vvv >>>>> Content-Type: text/html;charset=ISO-8859-1 >>>>> Cache-Control: must-revalidate,no-cache,no-store >>>>> Content-Length: 1442 >>>>> >>>>> java.io.IOException: Closed >>>>> at >>>>> org.eclipse.jetty.server.HttpOutput.write(HttpOutput.java:140) >>>>> at >>>>> org.eclipse.jetty.server.HttpOutput.write(HttpOutput.java:117) >>>>> [...] >>>>> at >>>>> org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:543) >>>>> >>>>> >>>>> >>>>> at java.lang.Thread.run(Thread.java:744) >>>>> java.lang.IllegalStateException: Committed >>>>> at >>>>> org.eclipse.jetty.server.Response.resetBuffer(Response.java:1154) >>>>> at org.basex.http.HTTPContext.status(HTTPContext.java:229) >>>>> at org.basex.http.BaseXServlet.service(BaseXServlet.java:65) >>>>> [...] >>>>> at >>>>> org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:608) >>>>> >>>>> >>>>> >>>>> at >>>>> org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:543) >>>>> >>>>> >>>>> >>>>> at java.lang.Thread.run(Thread.java:744) >>>>> _ REQUEST _________________________________ >>>>> (HEAD /exists?message=vvv)@4563057 >>>>> org.eclipse.jetty.server.Request@45a071 >>>>> - Host: localhost:8984 >>>>> - Accept: >>>>> text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 >>>>> - Accept-Language: en-US,en;q=0.5 >>>>> - Connection: keep-alive >>>>> - User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:28.0) >>>>> Gecko/20100101 Firefox/28.0 >>>>> - Accept-Encoding: gzip, deflate >>>>> _ RESPONSE ________________________________ >>>>> HTTP/1.1 404 No function found that matches the request. >>>>> DBG: message was vvv >>>>> Content-Type: text/html;charset=ISO-8859-1 >>>>> Cache-Control: must-revalidate,no-cache,no-store >>>>> Content-Length: 1442 >>>>> >>>>> >>>>> >>>>> >>>>> >>>>> On 04/11/2014 04:51 PM, Dirk Kirsten wrote: >>>>>> Hello Marco, >>>>>> >>>>>> I can't really follow. What 400 status code are you talking about, >>>>>> because I can't really see one in the code. >>>>>> I couldn't really test it because I didn't manage to tell curl to >>>>>> send >>>>>> form data and using HEAD at the same time (something like curl -I -F >>>>>> message=yes ... didn't work, help appreciated). >>>>>> >>>>>> But your if statement (returning the empty sequence) will result >>>>>> in the >>>>>> following error: >>>>>> >>>>>> [BASX0003] HEAD method must return a single 'restxq:response' >>>>>> element. >>>>>> >>>>>> Although I didn't test in in the combination, if I either use >>>>>> HEAD or >>>>>> the form param it worked. So could you please clarify in which case >>>>>> this >>>>>> code did work and what error you are experiencing? >>>>>> >>>>>> Cheers, >>>>>> Dirk >>>>>> >>>>>> On 11/04/14 16:34, Marco Lettere wrote: >>>>>>> I've the following simplified RESTXQ code snippet that I use with >>>>>>> basex >>>>>>> 7.8. >>>>>>> >>>>>>> declare >>>>>>> %rest:path("/exists") >>>>>>> %rest:HEAD >>>>>>> %rest:form-param("message","{$message}") >>>>>>> function page:exist( >>>>>>> $message as xs:string) >>>>>>> { >>>>>>> >>>>>>> try{ >>>>>>> if ($message = 'yes') then () >>>>>>> else error(xs:QName("err:ERR"), "Message wasn't yes!") >>>>>>> >>>>>>> } catch * { >>>>>>> <rest:response> >>>>>>> <http:response status="404" reason="{$err:description}"> >>>>>>> <http:header name="DBG" value="{'message was '|| >>>>>>> $message}"/> >>>>>>> </http:response> >>>>>>> </rest:response> >>>>>>> } >>>>>>> }; >>>>>>> >>>>>>> >>>>>>> This is always returning HTTP status 404 with reason "No function >>>>>>> found >>>>>>> that matches the request". >>>>>>> This happens only for the 400 status code. Any other status code >>>>>>> I use >>>>>>> to set behaves as expected including 404 itself. >>>>>>> Any hints? >>>>>>> Thank you. >>>>>>> Regards, >>>>>>> Marco. > >

⚡Generated with XQuery