cxf-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Sergey Beryozkin" <sbery...@progress.com>
Subject Re: Inheriting methods
Date Thu, 14 May 2009 12:57:27 GMT
Hi Tom
I added this test code :

public class AbstractEntity<T> {
  private T entity;
  @POST
  public void postEntity(T object) {
     entity = object;
  }

  public T getEntity() {
    return entity;
  }
}

@Path("/books")
public class BookEntity extends AbstractEntity<Book> {
}

AbstractEntity#postEntity is being resolved for requests like "POST /books <Books/>"
in my test and a JAXB provider is invoked (I 
see a diff kind of issue there though), I'm setting text/xml as content type.
What am I missing ? I've seen your code implementing UserService - does it have JAX-RS methods
? I'm also seen in your post
Cheers, Sergey



> Hey Sergey,
>
> I do not know what the reason is, all I know is that if I have:
>
>    @POST public void add(User user) {...}
>
> In the regular class, it works, but if I move the code to the abstract class and make
it generic, like so:
>
>    @POST public void add(T user) {...}
>
> then I get the exception. But it works ok for @GET list(), or @GET find(long id).
>
> Tom
>
> PS: Please note my typo in the initial post that the abstract class does not know "User"
but only the generic "T".
>
>
>
>
> Sergey Beryozkin wrote:
>> Hi,
>>
>> So just to confirm, for the purpose of writing a test,
>>
>> @Path(...)
>> @Produces(...)
>> UserServiceImpl extends AbstractServiceImpl<User>
>> implements UserService
>> {
>> }
>>
>>
>> abstract class AbstractServiceImpl<T> {
>> {
>>    @POST
>>    public void add(User user) {...// reflection ...//}
>> }
>>
>> can not be matched with 'User' add parameter being confused for Object ?
>> If no then please correct me...
>> I'll do a test shortly
>>
>> Cheers, Sergey
>>
>>
>>
>>
>> ----- Original Message ----- From: "Tom" <tbee@tbee.org>
>> To: <users@cxf.apache.org>
>> Sent: Thursday, May 14, 2009 10:52 AM
>> Subject: Inheriting methods
>>
>>
>>> I have to implement basic CRUD operations on a serious number of Entities. The
to-be-executed code is identical for all classes, 
>>> except that different DAO implementating classes are involved. So I decided to
go for reflection, so instead of:
>>>
>>> /@Path(...)
>>> @Produces(...)
>>> implements UserService
>>> UserServiceImpl
>>> {
>>>    @GET
>>>    public void list() {... same code over and over again... }
>>>
>>>    @POST
>>>    public void add(User user) {... //same code over and over again... //}
>>> }
>>> /
>>>
>>> I have
>>>
>>>
>>> /@Path(...)
>>> @Produces(...)
>>> UserServiceImpl extends AbstractServiceImpl<User>
>>> implements UserService
>>> {
>>> }
>>>
>>>
>>> abstract AbstractServiceImpl<T>
>>> {
>>>    @GET
>>>    public void list() {... reflection ...}
>>>
>>>    @POST
>>>    public void add(User user) {...// reflection ...//}
>>> }
>>> /
>>>
>>> This works fine for REST-GET but not for REST-POST, there I get a "No message
body reader found for request class : Object, 
>>> ContentType : text/xml". This most definitely has to do with the resolving of
the @POST, because if I add the code below the the 
>>> UserServiceImpl, then it all works ok.
>>>
>>> /    @POST public void add(User user) { super.add(user); }
>>>
>>> /Any suggestions on why?
>>>
>>> Tom
>>>
>>>
>>
>>
> 


Mime
View raw message