Customized 200 level response status codes

2008-12-09 Thread postmaster
I define a customized status code(299) to handle the case of a success request 
with no data found. I tried two different ways to set this status code(see 
below), but the status code client receives is 404, not 299. There's no place 
in my codes to set status to 404, so this 404 must be generated by Resetlet 
automatically. 

If I change 299 to any 400-level or 500-level code, for example, 499, then it 
works fine. Does anyone know why?

If there any way I can set a status of 299?

Thanks.



// somewhere define my customized status
public static Status SUCCESS_NO_DATA = new Status(299);
//
public Representation represent(Variant variant) throws ResourceException
{
  try {
// ...
  } catch (Exception e) {

// OPTION getResponse().setStatus(SUCCESS_NO_DATA, "No Data");


// OR
// OPTION 2
throw new ResourceException(SUCCESS_NO_DATA, "No Data", e);
  }
}


--
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=981976


Re: Customized 200 level response status codes

2008-12-09 Thread Erik Beeson
I know this doesn't answer your question, but doesn't 204 do what you want
already?
--Erik


On Tue, Dec 9, 2008 at 6:58 PM, <[EMAIL PROTECTED]> wrote:

> I define a customized status code(299) to handle the case of a success
> request with no data found. I tried two different ways to set this status
> code(see below), but the status code client receives is 404, not 299.
> There's no place in my codes to set status to 404, so this 404 must be
> generated by Resetlet automatically.
>
> If I change 299 to any 400-level or 500-level code, for example, 499, then
> it works fine. Does anyone know why?
>
> If there any way I can set a status of 299?
>
> Thanks.
>
>
> 
> // somewhere define my customized status
> public static Status SUCCESS_NO_DATA = new Status(299);
> //
> public Representation represent(Variant variant) throws ResourceException
> {
>  try {
>// ...
>  } catch (Exception e) {
>
>// OPTION getResponse().setStatus(SUCCESS_NO_DATA, "No Data");
>
>
>// OR
>// OPTION 2
>throw new ResourceException(SUCCESS_NO_DATA, "No Data", e);
>  }
> }
> 
>
> --
>
> http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=981976
>

--
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=981980

Re: Customized 200 level response status codes

2008-12-09 Thread Rob Heittman
For pragmatic reasons, unless your application only operates over a network
you configure and control, with clients you configure and control, I'd avoid
customizing status codes.  Browsers, HTTP libraries, proxies, and
higher-layer switches may behave in undefined ways when they encounter
non-standard codes -- even though they really should behave politely and
largely respect the first digit of the code.
Here, I would either return 204 as Erik suggests, or return 200 with an
empty entity, e.g. an empty document or textual message.  Probably the
latter, as 204 still confuses some browser-based client libraries and I get
a bit tired of explaining what 204 does.
That all said, I think what you did should have worked.  So I wonder if you
didn't hit one of these undefined intermediary behavior issues, and/or maybe
a Restlet bug.  Which HTTP server connector are you using, and which client
are you using to test?  Then I can set it up to verify.

On Tue, Dec 9, 2008 at 9:58 PM, <[EMAIL PROTECTED]> wrote:

> If I change 299 to any 400-level or 500-level code, for example, 499, then
> it works fine. Does anyone know why?
>

--
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=981982

Re: Customized 200 level response status codes

2008-12-10 Thread Thierry Boileau
Hello all,

from what I see in the code of the "Resource" class, when a resource 
does not return a representation (ie null, not empty) and returns a 2** 
status (except 204), then a 404 status is automatically returned.
That is to say, at this moment, you can associate a 204 status and a 
null representation.

best regards,
Thierry Boileau

> For pragmatic reasons, unless your application only operates over a 
> network you configure and control, with clients you configure and 
> control, I'd avoid customizing status codes.  Browsers, HTTP 
> libraries, proxies, and higher-layer switches may behave in undefined 
> ways when they encounter non-standard codes -- even though they really 
> should behave politely and largely respect the first digit of the code.
>
> Here, I would either return 204 as Erik suggests, or return 200 with 
> an empty entity, e.g. an empty document or textual message.  Probably 
> the latter, as 204 still confuses some browser-based client libraries 
> and I get a bit tired of explaining what 204 does.
>
> That all said, I think what you did should have worked.  So I wonder 
> if you didn't hit one of these undefined intermediary behavior issues, 
> and/or maybe a Restlet bug.  Which HTTP server connector are you 
> using, and which client are you using to test?  Then I can set it up 
> to verify.
>
> On Tue, Dec 9, 2008 at 9:58 PM, <[EMAIL PROTECTED] 
> > wrote:
>
> If I change 299 to any 400-level or 500-level code, for example,
> 499, then it works fine. Does anyone know why?
>
>

--
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=982125


RE: Re: Customized 200 level response status codes

2008-12-10 Thread postmaster
Even I use 204 status (Status.SUCCESS_NO_CONTENT)and return a null 
representation, the response status code that the client receives is still 404. 

> which HTTP server connector are you
> using, and which client are you using to test? Then I can set it up to verify.

I use Simple Server connector, Apache HTTP Client connector. The protocol is 
HTTP. The application is authenticated by HTTP Digest.

--
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=982523


RE: Re: Customized 200 level response status codes

2008-12-10 Thread postmaster
Finally I get it working. I have to associate a 2** code with a bogus empty 
representaton (null representation doesn't work). Is this a bug in restlet?


// inside my resource class
getResponse().setStatus(Status.SUCCESS_NO_CONTENT, "No Data");
return new StringRepresentation("", MediaType.ALL);


BTW, I can use 204 or my customized 299. 

Thanks again.

--
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=982610