In the particular case of 201 (CREATED) responses, you are supposed to also
include a "Location" header whose value is the URI of the newly created
resource. The standard approach (Response.created(uri).entity(entity))
does this for you, but you're own your own if you're wanting to return your
entity class directly like this. How are you planning to address this, so
that the client learns what the URI of the new resource is?
Yes, that means the return type from the endpoint method is typically
Response instead of type-specific. I've addressed that in several services
where I wanted to auto-generate API docs by defining a custom
@Produces(MyEntity.class) annotation, and using that in a custom JavaDoc
plugin.
Regarding annotations on interfaces, make sure you're using the correct
reflection APIs that specifically examine the interfaces implemented by
your endpoints class, not just the class itself.
Craig
On Wed, Apr 15, 2015 at 8:11 AM, Veit Guna <Veit.Guna_at_gmx.de> wrote:
> Hi.
>
> I'm using Jersey 2.17 to implement REST services where annotations are put
> on the interface instead of the resource class.
> My interface returns concrete entity types rather than generic Response
> types, since in my opinion, this is a cleaner approach.
> Also this allows to auto-create a typed Apache CXF client based on the
> interface.
>
> To be able to e.g. set the HTTP status code (e.g. 201 instead of default
> 200 on POST) I would like to use my own annotations
> in combination with a ContainerResponseFilter that evaluates the
> annotations via ContainerResponseContext.getEntityAnnotations():
>
> @POST
> @HttpStatus(Status.CREATED)
> MyEntity create(MyEntity);
>
> This works, if I put the annotation on the resource class, but does NOT
> work when I put the annotation on the interface instead.
> Is this a known limitation? Are there plans to enhance that behavior?
> Since all other annotations (@GET, @Produces etc.) work
> on interfaces as well.
>
> Another thing are proxied REST endpoints.
>
> Background:
> I use Spring-Security and tried to secure some REST methods. It works so
> far. But again, my custom annotations are lost due to
> the fact, that JDK-proxies are used by Spring-Security. Using cglib,
> forces me to put my annotations on the class instead of the
> interface that I don't want. So one can get the interface annotations
> only, when the proxy is unwrapped and the underlying object
> is checked.
>
> So, the only way I can think of is that the annotation detection of jersey
> respects possible proxied REST endpoints and checks
> for annotations on the underlying object. So calling
> ContainerResponseContext.getEntityAnnotations() would return the custom
> annotations on the endpoint interface. Are there any plans to support such
> kind of functionality?
>
> Is there another way to achieve what I want?
>
> Thanks.
> Veit
>
>