I'm having a slight issue with using a regex @Path parameter. I'm trying to match path a or b. I've been trying to use:
@Path("/{a: path\\/to\\/resource|resource}")
So that either
or
would both execute the same method. My issue seems to arise when I use two forward-slashes. I can only access the method using
but not the other.
However when doing:
@Path("/{a: path\\/resource|resource}")
It works as intended and I can access the method using
or
I have tried doing an negative lookahead to exclude the first part of the query and only return the common property (resource):
@Path("/{a: (?!path\\/to\\/)resource}")
But that did not work either. It had the same effect as my first implementation, I could only access /resource.
I've also tried:
@Path("/{a: (path\\/to)?}{b: (\\/)?}resource")
Which worked as intended but also worked if I queried
or
Thus creating 4 entry URLs when I want to only have two.
Am I missing something to do with the forward-slashes, why can't my regex pattern contain more than one forward-slash?
I think I may have found out the cause of the issue.
I have several other paths with different HTTP methods (GET, PUT, DELETE) using the same URL (/path/to/resource). I suspect that it tried to match path/to/resource against one of those methods before executing the regex. My reasoning for this suspicion is that when I renamed the POST method to:
@Path("/{a: (notPath\\/to\\/)?}resource"}
It worked as intended. I was able to get a response from both
localhost:1111/notPath/to/resource
and
localhost:1111/resource