Class ContentLocationResponseFilter

java.lang.Object
org.gcube.informationsystem.resourceregistry.rest.providers.ContentLocationResponseFilter
All Implemented Interfaces:
jakarta.ws.rs.container.ContainerResponseFilter

@Provider public class ContentLocationResponseFilter extends Object implements jakarta.ws.rs.container.ContainerResponseFilter
Global JAX-RS response filter emitting Content-Location (RFC 9110 Section 8.7), per 07-api-foundations-and-roles.md: "the canonical URI of the returned payload, or the specific URI that generated a failure in error responses" - for creation/update responses, single-instance reads, and error responses alike.

Every creation/update endpoint in this API follows the idempotent-PUT idiom (the resource's own identifier is already the request path - PUT /contexts/{uuid}, PUT /types/{type-name}, PUT /instances/{type}/{id}, PUT /query-templates/{name}, and their PATCH update counterparts), so the canonical URI of a successful creation/update response is always just the request's own absolute path - no per-endpoint wiring is needed there, unlike X-Warning/ X-Result-Scope/Preference-Applied/Link, which need application code to decide whether/what to report.

Single-instance reads (Context/Type/Instance/Query Template read()) are different: the addressed URI is not always the canonical one - e.g. GET /access/contexts/@current must report the resolved Context's own UUID-based URI, not the @current alias. So, unlike creation/update, reads explicitly opt in via PolicyEnforcementPoint.setContentLocation(String), mirroring the Link-header mechanism. A List/Query response is a collection, not "the" representation of one URI, and therefore never sets it.

For error responses (status >= 400), this fires regardless of which mechanism produced the response - ResourceRegistryExceptionMapper, a bare JAX-RS WebApplicationException, or anything else - since a ContainerResponseFilter sees every outgoing response.

Author:
Luca Frosini (ISTI - CNR)
  • Constructor Details

    • ContentLocationResponseFilter

      public ContentLocationResponseFilter()
  • Method Details

    • filter

      public void filter(jakarta.ws.rs.container.ContainerRequestContext requestContext, jakarta.ws.rs.container.ContainerResponseContext responseContext) throws IOException
      Specified by:
      filter in interface jakarta.ws.rs.container.ContainerResponseFilter
      Throws:
      IOException