Hi
On 24/10/13 14:02, Andreas Sahlbach wrote:
Hi!

I am wondering if I can combine ETag support and the subresource concept of
CXF.

The problem I have is, that for supporting ETags I have to return an
Response object, if the user is doing a GET on my object.
Example:

@GET // necessary but death of subresources
@Path("/object/id/{id}")
  public Response getObject(@PathParam("id") String id, @Context Request
request)
{
     MyObject result = new MyObject().initializeById(id);
     EntityTag eTag = new EntityTag(result.getEtag());
     ResponseBuilder builder = request.evaluatePreconditions(eTag);
     if (builder != null) {
         return builder.build();
     }
     return Response.ok(result).build();
}

But if I return a response object, I am not able to use the concept of
subresources, because for this my method needs to return the object itself
and not a Response containing an entity of the object.

Is there a way to use both concepts? If I just remove the @GET in the
example above, cxf trys to do subresource calls at the response object.

Why do you think that the two concepts are not compatible ?
The idea behind subresources is mainly to push some of the root resource responsibilities down to sub-resources/objects. Eventually a subresource will return a response, wrapped in Response if needed.

Actually, I guess may be you are referring to the fact that Contexts can not be injected into sub-resources ?
If so then in your example, I'd say simply do

new MyObject(request);

or

new MyObject().setRequest(request);

or you can do a JAX-RS 2.0 way, use
https://jax-rs-spec.java.net/nonav/2.0/apidocs/javax/ws/rs/container/ResourceContext.html,

not my favorite approach, but it can let you inject a context directly into a MyObject field for example, if you do not want to introduce setters, etc

HTH, Sergey

Cheers,

Andreas



Reply via email to