Search This Blog

Monday, November 12, 2018

Java JAX-RS Subresource Example - subresource method and subresource locator

If a method is annotated with @Path but not with any request method designator (get, post...) then it is a subresource locator. If a method is annotated with @Path together with @GET or @POST etc, then it is a subresource methodnot a subresource locator

Example:
public Interface Employee {

   @Path("/employees/{empid}")
   public Employee getEmployee(@PathParam("empid") String id) {
        // Find the Employee based on the id path parameter
        Employee emp ;
        if (id.startsWith("SALES")) {
           emp=new SalesEmployee();
        }else{
           emp=new OtherEmployee();
        }
        return emp.getEmployee(id);
    }
}

public class SalesEmployee implements Employee {
  @GET
   public Employee getEmployee(String id) {
   ...
}
}

public class OtherEmployee implements Employee {
  @GET
   public Employee getEmployee(String id) {
   ...
}
}