title: Implementing Hypermedia in RESTful JAX-RS Apache CXF
body: <p>I am working in a RESTful application developed in Apache CXF and I would like to introduce hypermedia functionality to it.</p>
  
  <p>Most of our jaxrs:serviceBeans follow this template:</p>
  
  <pre><code>@GET
  @Path("/{exampleId}")
  public ExampleJSON get(@PathParam("exampleId") Integer exampleId) {
      ExampleJSON example;
      // Load data from repository here...
  
      // Add link to self.
      String href = javax.ws.rs.core.Link.fromResource(ExampleService.class).build().getUri().toString();
  
      // HypermediaLink is a custom object to hold a "href" and "rel" strings
      HypermediaLink linkToSelf = new HypermediaLink();
      linkToSelf.setHref(href + example.getId());
      linkToSelf.setRel("self");
  
      // Inherited method, just adds a HypermediaLink to a collection in the parent class
      example.addHypermediaLink(linkToSelf);
  
      // Return JSON compatible object, JACKSON will serialize it nicely.
      return example;
  }
  </code></pre>
  
  <p>This is the basic concept. Keep in mind that I simplified this code for explanation purposes; so, it can be easily understood.</p>
  
  <p>This code works fine; but I am wondering if there is a better way to do this with Apache CXF. I have some ideas for how to enhancing it; however, it will require some custom annotations.</p>
  
  <p>I see some examples using Jersey, but I would like to stick with Apache CXF.</p>
  
  <p>Any help would be appreciated.</p>
  
  <p>Thanks</p>