javarestcxfjax-rsuritemplate

Wrong rest service is selected


i have resource with two methods:

@GET
@Path("/{date}")
public Response getPartnerInteractionsByDate(
        @PathParam("partnerId") int partnerId,
        @PathParam("date") String date
);

@GET
@Path("/{interactionId}")
public Response getPartnerInteraction(
        @PathParam("partnerId") int partnerId,
        @PathParam("interactionId") int interactionId
);

how can I select one or another service? if I put "1" for interactionId, still the method with date gets executed. I am using apache cxf 3.0.1. Thank you


Solution

  • There are two problems. The first is that your Path must contain the PathParams you're binding. Second, your two paths are identical in that they both take 2 parameters of the same type (cxf has no way of knowing the difference between an int and a string containing an int).

    Try something like this:

    @GET
    @Path("/{partnerId}/date/{date}")
    public Response getPartnerInteractionsByDate(
            @PathParam("partnerId") int partnerId,
            @PathParam("date") String date
    );
    
    
    @GET
    @Path("/{partnerId}/{interactionId})
    public Response getPartnerInteraction(
            @PathParam("partnerId") int partnerId,
            @PathParam("interactionId") int interactionId
    );