web-servicesjerseyjax-rsrestful-architecture

JAX-RS Same @Path Identifier in two Services


I am having the below scenario while implementing JAX-RS web service.

Service A:

@Path("/customer/{customerId}")
public interface ICustomerDataUsageService{

@GET
@Path("/datausage")
public Response getCustomerDataUsage();

//other methods...
}

Service B:

@Path("/")
public interface IHelpDeskService{

@GET
@Path("/customer/{customerId}")
public Response getCustomer();

//other methods...
}

After deployment only the Service A is working (Its registered after the Service B). For the second one I am getting HTTP 404 error.

Unfortunately we cannot change the interfaces since its provided by another entity. We are only having control of the implementation classes for these.

I am using Jersey-2.22.

Is there any way out to have both these services working without changing the interfaces.

Thanks in Advance!


Solution

  • This was indeed a bug and was fixed by the API team by correcting the API. The fix looks as below:

    Service A:

    @Path("/customer")
    public interface ICustomerDataUsageService{
    
    @GET
    @Path("/{customerId}/datausage")
    public Response getCustomerDataUsage();
    
    //other methods also got /{customerId} added in path
    }
    

    Service B:

    @Path("/")
    public interface IHelpDeskService{
    
    @GET
    @Path("/customer/{customerId}")
    public Response getCustomer();
    
    //other methods...
    }