Note that there are some explanatory texts on larger screens.

plurals
  1. POIs it possible to set ETags using JAX-RS without resorting to Response objects?
    primarykey
    data
    text
    <p>In <a href="https://stackoverflow.com/questions/2085411/how-to-use-cxf-jax-rs-and-http-caching">one of the few questions (with answers)</a> I have found on SO regarding JAX-RS and caching, the answer to generating ETags (for caching) is by setting some values on the Response object. As in the following:</p> <pre><code>@GET @Path("/person/{id}") public Response getPerson(@PathParam("id") String name, @Context Request request){ Person person = _dao.getPerson(name); if (person == null) { return Response.noContent().build(); } EntityTag eTag = new EntityTag(person.getUUID() + "-" + person.getVersion()); CacheControl cc = new CacheControl(); cc.setMaxAge(600); ResponseBuilder builder = request.evaluatePreconditions(person.getUpdated(), eTag); if (builder == null) { builder = Response.ok(person); } return builder.cacheControl(cc).lastModified(person.getUpdated()).build(); } </code></pre> <p>The problem is that will not work for us, since we use the same methods for both SOAP and REST services, by annotating the methods with @WebMethod (SOAP), @GET (and whatever else we might need to expose the service). The previous service would look like this to us (excluding the creation of headers):</p> <pre><code>@WebMethod @GET @Path("/person/{id}") public Person getPerson(@WebParam(name="id") @PathParam("id") String name){ return _dao.getPerson(name); } </code></pre> <p>Is there any way - through some extra configuration - of setting those headers? This is the first time I have found that using Response objects actually has some benefit over just auto-conversion ... </p> <p>We are using Apache CXF.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload