[basex-talk] rest:response and status 400/404

Marco Lettere marco.lettere at dedalus.eu
Fri Apr 11 17:19:03 CEST 2014


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




More information about the BaseX-Talk mailing list