Class EmbedHelper

  • All Implemented Interfaces:
    javax.ws.rs.core.Feature

    public class EmbedHelper
    extends java.lang.Object
    implements javax.ws.rs.core.Feature
    Helper utility that can be registered in the Jersey environment to be injected into services. It supports checking if the client requested to embed a linked resource. Usage:
       if (embedHelper.isEmbeddingOfRelationRequested("owner")) {
         carResource.setOwner(createPerson(ownerId));
       }
     

    Clients may request to resolve a link as an embedded resource by appending the query param embed to the request uri containing all the named relations they want to embed. embed may be be added multiple times to create an array of relation names or contain multiple relation names separated by comma, e.g.:

    • GET /api/cars?embed=drivers&embed=owner
    • GET /api/cars?embed=drivers,owner
    • Constructor Summary

      Constructors 
      Constructor Description
      EmbedHelper​(io.dropwizard.setup.Environment environment)
      Create a new embed helper instance and register it in the given environment so that it becomes Context aware.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean configure​(javax.ws.rs.core.FeatureContext context)  
      boolean isEmbeddingOfRelationRequested​(java.lang.String relationName)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • EmbedHelper

        public EmbedHelper​(io.dropwizard.setup.Environment environment)
        Create a new embed helper instance and register it in the given environment so that it becomes Context aware.
        Parameters:
        environment - The Dropwizard environment to register this instance in.
    • Method Detail

      • isEmbeddingOfRelationRequested

        public boolean isEmbeddingOfRelationRequested​(java.lang.String relationName)
        Parameters:
        relationName - the name of the relation, e.g. project in @{code { "_links": {"project": {"href": "http..."}}}}
        Returns:
        if the client requested to embed the resource referenced in the link with the given relation name
      • configure

        public boolean configure​(javax.ws.rs.core.FeatureContext context)
        Specified by:
        configure in interface javax.ws.rs.core.Feature