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. > -- 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

