I am trying to create REST based service using Jersey 2.x/Java with two different GET methods. They both need to have same endpoints and one operation is to search a list of products and this takes a list of query parameters. Another operation is to download the product brochure as a pdf file and this takes only a path param. MY My resource class looks like below:
@Path("/domain")
public class MyResource {
@GET
@Path("/home/products")
@Consumes({ MediaType.APPLICATION_JSON })
@Produces({MediaType.APPLICATION_JSON })
public SearchResult loansHomeLoansDocumentsGet(
@QueryParam("productType") String productType,
@QueryParam("productSubType") String productSubType,
@QueryParam("productSource"
@QueryParam("toDate") String toDate) throws Exception {
.......
}
@GET
@Path("/home/products/{productId}")
@Consumes({ MediaType.APPLICATION_JSON })
@Produces({MediaType.APPLICATION_JSON})
public SuccessResponse loansHomeLoansDocumentsDocumentReferenceIdGet(@PathParam("productId") String productId) {
.......
}
......
}
But when I run tried that, it throws 406 not acceptable exception.
javax.ws.rs.NotAcceptableException: HTTP 406 Not Acceptable
at org.glassfish.jersey.server.internal.routing.MethodSelectingRouter.getMethodRouter(MethodSelectingRouter.java:529) ~[jersey-server-2.22.1.jar:?]
at org.glassfish.jersey.server.internal.routing.MethodSelectingRouter.access$000(MethodSelectingRouter.java:94) ~[jersey-server-2.22.1.jar:?]
at org.glassfish.jersey.server.internal.routing.MethodSelectingRouter$4.apply(MethodSelectingRouter.java:779) ~[jersey-server-2.22.1.jar:?]
at org.glassfish.jersey.server.internal.routing.MethodSelectingRouter.apply(MethodSelectingRouter.java:371) ~[jersey-server-2.22.1.jar:?]
at org.glassfish.jersey.server.internal.routing.RoutingStage._apply(RoutingStage.java:109) ~[jersey-server-2.22.1.jar:?]
at org.glassfish.jersey.server.internal.routing.RoutingStage._apply(RoutingStage.java:112) ~[jersey-server-2.22.1.jar:?]
at org.glassfish.jersey.server.internal.routing.RoutingStage._apply(RoutingStage.java:112) ~[jersey-server-2.22.1.jar:?]
at org.glassfish.jersey.server.internal.routing.RoutingStage._apply(RoutingStage.java:112) ~[jersey-server-2.22.1.jar:?]
at org.glassfish.jersey.server.internal.routing.RoutingStage.apply(RoutingStage.java:92) ~[jersey-server-2.22.1.jar:?]
at org.glassfish.jersey.server.internal.routing.RoutingStage.apply(RoutingStage.java:61) ~[jersey-server-2.22.1.jar:?]
at org.glassfish.jersey.process.internal.Stages.process(Stages.java:197) ~[jersey-common-2.22.1.jar:?]
at org.glassfish.jersey.server.ServerRuntime$2.run(ServerRuntime.java:318) [jersey-server-2.22.1.jar:?]
Is that valid to keep two GET methods in this way ? Any comment or input is appreciated.
Thanks.