0

I have the following two endpoints:

@Path("/productresource")
public class ProductResource {
    
    private ProductService productService = new ProductService();

    @GET
    @Produces("application/json")
    @Path("/get/products")
    public String getAllProducts(){
        System.out.println("all");
        String response = "";
        try {
            List<Product> allProducts = productService.getAllProducts();
            response = allProducts.toString();
        } catch(NullPointerException e) {
            e.printStackTrace();
        }

        return response;
    }
    
    //1.a: Search item database by product
    @GET
    @Produces("application/json")
    @Path("/get/products/{productId}")
    public String getProductById(@PathParam("productId") String productId){

        System.out.println("byID");
        String result = null;
        
        try {
            Product productWithMatchingId = null;
            productWithMatchingId = productService.findProductById(productId);
            
            //Convert the Book to a Json string, and return it.
            result = null;
            if(productWithMatchingId != null) {
                result = productWithMatchingId.toString();
            }
        } catch(NullPointerException e) {
            e.printStackTrace();
        }

        System.out.println("Product with matching id: " + result);
        return result;
    }

When I send a request to the endpoint with the pathParam argument, the pathparam argument is ignored altogether and the request instead goes to the /get/products endpoint.

Why is my pathParam argument being ignored?

This is the exact postman request I'm sending:

GET http://localhost:8080/BookStoreWebService/productresource/get/products?productId=193648

Vismark Juarez
  • 613
  • 4
  • 14
  • 21

0 Answers0