0

I'm using Jakarta REST API in Jakarta EE 10 and I noticed that if I try to parse an empty @PathParam in a GET method it works only if there are no other REST methods in the same class.

I have the following class, where the getCustomer() method takes the request no matter if it's empty or not. I omitted the method's body for brevity but basically it just returns a List of RestCustomer containing all of them if the request is empty or just the ones that match the request if it's not empty.

@Path("/customer/")
public class CustomerResource {

    @GET @Produces("text/xml")
    @Path("{query: .*}/")
    public List<RestCustomer> getCustomer(@PathParam("query") String query) {
       // method body
    }
}

So far it works good. You can send the request http://example.com/resources/customer/ or http://example.com/resource/customer/5 and it will work both ways.

But once I add other REST methods such as PUT, POST or DELETE, the getCustomer() method just stops working if the request is empty and it throws an HTTP Status 405 - Method not allowed error. Why is this happening? Is there any way to solve it?

Arjan Tijms
  • 37,782
  • 12
  • 108
  • 140
  • Is the server correctly configured to support other methods than GET? Sometimes they are dislabled because of security policies but obviously they have to be allowed if you plan to provide REST endpoints with them. – v-g Aug 16 '23 at 19:39
  • They work, and the GET method also works if it's not empty (ie: `http://example.com/resource/customer/5`). But requesting an empty GET method won't work unless it's the only declared method. – Guillem Chesa Aug 21 '23 at 12:01
  • I suspect a parsing error from the web container due to the regex used, did you try to solve the problem by overloading the `getCustomer` method in an analogous way to https://stackoverflow.com/a/19660557/20161294? – v-g Aug 21 '23 at 13:32

0 Answers0