You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by scouredimage <sc...@gmail.com> on 2008/05/15 18:04:50 UTC

JAX-RS Return type

Hi All,

Looking at the JAX-RS 0.6 spec for Return Type (Section 2.2.2):
Other: Results in an entity body mapped from the return type. If the return
value is not null a 200 status 26 
code is used, a null return value results in a 204 status code.

However, I don't see this working on 2.1. Either that, or I am doing
something stupid.

@Path("/users/")
Public class UserService {
  @GET
  @Path("{id}")
  public Server getUser(@PathParam("id") Integer id) {
    ...
    if(notFound) {
      return null;
    }
    return user;
  }
}

Any pointers?

Thanks in advance.
-- 
View this message in context: http://www.nabble.com/JAX-RS-Return-type-tp17256757p17256757.html
Sent from the cxf-user mailing list archive at Nabble.com.


Re: JAX-RS Return type

Posted by scouredimage <sc...@gmail.com>.
123 is an invalid user id

curl --include http://localhost:9090/testService/users/123
HTTP/1.1 200 OK
Content-Type: text/xml
Content-Length: 0
Server: Jetty(6.1.8)


scouredimage wrote:
> 
> Hi All,
> 
> Looking at the JAX-RS 0.6 spec for Return Type (Section 2.2.2):
> Other: Results in an entity body mapped from the return type. If the
> return value is not null a 200 status 26 
> code is used, a null return value results in a 204 status code.
> 
> However, I don't see this working on 2.1. Either that, or I am doing
> something stupid.
> 
> @Path("/users/")
> Public class UserService {
>   @GET
>   @Path("{id}")
>   public User getUser(@PathParam("id") Integer id) {
>     ...
>     if(notFound) {
>       return null;
>     }
>     return user;
>   }
> }
> 
> Any pointers?
> 
> Thanks in advance.
> 

-- 
View this message in context: http://www.nabble.com/JAX-RS-Return-type-tp17256757p17257245.html
Sent from the cxf-user mailing list archive at Nabble.com.


Re: JAX-RS Return type

Posted by Sergey Beryozkin <se...@iona.com>.
Not at all, WebApplicationException is part of jsr-311 api...Returning null should work too it's just it's not supported...

Cheers, Sergey

----- Original Message ----- 
From: "scouredimage" <sc...@gmail.com>
To: <us...@cxf.apache.org>
Sent: Thursday, May 15, 2008 5:52 PM
Subject: Re: JAX-RS Return type


> 
> Hi Sergey,
> 
> Thanks for the reply.
> 
> I will change my resource methods as you described. However isn't this
> behavior of cxf deviating from the jax-rs specs?
> 
> 
> Sergey Beryozkin wrote:
>> 
>> Hi
>> 
>> Try to do
>> 
>>>    if(notFound) {
>>>      throw new WebApplicationException(204);
>>>   }
>> 
>> this way you can also add some more description to the response body
>> like "throw new
>> WebApplicationException(Response.status(204).entity(errorDescriptionObject).build());"
>> 
>>> 
>>> Hi All,
>>> 
>>> Looking at the JAX-RS 0.6 spec for Return Type (Section 2.2.2):
>>> Other: Results in an entity body mapped from the return type. If the
>>> return
>>> value is not null a 200 status 26 
>>> code is used, a null return value results in a 204 status code.
>> 
>> This needs to be fixed...
>> 
>> Cheers, Sergey
>> 
>> 
>>> 
>>> However, I don't see this working on 2.1. Either that, or I am doing
>>> something stupid.
>>> 
>>> @Path("/users/")
>>> Public class UserService {
>>>  @GET
>>>  @Path("{id}")
>>>  public User getUser(@PathParam("id") Integer id) {
>>>    ...
>>>    if(notFound) {
>>>      return null;
>>>    }
>>>    return user;
>>>  }
>>> }
>>> 
>>> Any pointers?
>>> 
>>> Thanks in advance.
>>> -- 
>>> View this message in context:
>>> http://www.nabble.com/JAX-RS-Return-type-tp17256757p17256757.html
>>> Sent from the cxf-user mailing list archive at Nabble.com.
>> 
>> ----------------------------
>> IONA Technologies PLC (registered in Ireland)
>> Registered Number: 171387
>> Registered Address: The IONA Building, Shelbourne Road, Dublin 4, Ireland
>> 
>> 
> 
> -- 
> View this message in context: http://www.nabble.com/JAX-RS-Return-type-tp17256757p17257701.html
> Sent from the cxf-user mailing list archive at Nabble.com.

----------------------------
IONA Technologies PLC (registered in Ireland)
Registered Number: 171387
Registered Address: The IONA Building, Shelbourne Road, Dublin 4, Ireland

Re: JAX-RS Return type

Posted by scouredimage <sc...@gmail.com>.
Hi Sergey,

Thanks for the reply.

I will change my resource methods as you described. However isn't this
behavior of cxf deviating from the jax-rs specs?


Sergey Beryozkin wrote:
> 
> Hi
> 
> Try to do
> 
>>    if(notFound) {
>>      throw new WebApplicationException(204);
>>   }
> 
> this way you can also add some more description to the response body
> like "throw new
> WebApplicationException(Response.status(204).entity(errorDescriptionObject).build());"
> 
>> 
>> Hi All,
>> 
>> Looking at the JAX-RS 0.6 spec for Return Type (Section 2.2.2):
>> Other: Results in an entity body mapped from the return type. If the
>> return
>> value is not null a 200 status 26 
>> code is used, a null return value results in a 204 status code.
> 
> This needs to be fixed...
> 
> Cheers, Sergey
> 
> 
>> 
>> However, I don't see this working on 2.1. Either that, or I am doing
>> something stupid.
>> 
>> @Path("/users/")
>> Public class UserService {
>>  @GET
>>  @Path("{id}")
>>  public User getUser(@PathParam("id") Integer id) {
>>    ...
>>    if(notFound) {
>>      return null;
>>    }
>>    return user;
>>  }
>> }
>> 
>> Any pointers?
>> 
>> Thanks in advance.
>> -- 
>> View this message in context:
>> http://www.nabble.com/JAX-RS-Return-type-tp17256757p17256757.html
>> Sent from the cxf-user mailing list archive at Nabble.com.
> 
> ----------------------------
> IONA Technologies PLC (registered in Ireland)
> Registered Number: 171387
> Registered Address: The IONA Building, Shelbourne Road, Dublin 4, Ireland
> 
> 

-- 
View this message in context: http://www.nabble.com/JAX-RS-Return-type-tp17256757p17257701.html
Sent from the cxf-user mailing list archive at Nabble.com.


Re: JAX-RS Return type

Posted by Sergey Beryozkin <se...@iona.com>.
Hi

Try to do

>    if(notFound) {
>      throw new WebApplicationException(204);
>   }

this way you can also add some more description to the response body
like "throw new WebApplicationException(Response.status(204).entity(errorDescriptionObject).build());"

> 
> Hi All,
> 
> Looking at the JAX-RS 0.6 spec for Return Type (Section 2.2.2):
> Other: Results in an entity body mapped from the return type. If the return
> value is not null a 200 status 26 
> code is used, a null return value results in a 204 status code.

This needs to be fixed...

Cheers, Sergey


> 
> However, I don't see this working on 2.1. Either that, or I am doing
> something stupid.
> 
> @Path("/users/")
> Public class UserService {
>  @GET
>  @Path("{id}")
>  public User getUser(@PathParam("id") Integer id) {
>    ...
>    if(notFound) {
>      return null;
>    }
>    return user;
>  }
> }
> 
> Any pointers?
> 
> Thanks in advance.
> -- 
> View this message in context: http://www.nabble.com/JAX-RS-Return-type-tp17256757p17256757.html
> Sent from the cxf-user mailing list archive at Nabble.com.

----------------------------
IONA Technologies PLC (registered in Ireland)
Registered Number: 171387
Registered Address: The IONA Building, Shelbourne Road, Dublin 4, Ireland