Question

I'd like to define REST API using Spring. I have these 2 @Controller methods:

@RequestMapping(value = "/{machineId}/workspaces/{workspaceId}", method = RequestMethod.DELETE)
public void removeWorkspace(@PathVariable String machineId, @PathVariable String workspaceId {...}

@RequestMapping(value = "/{machineId}", method = RequestMethod.DELETE)
public void removeVM(@PathVariable String machineId) {...}

The problem is, that this definition causing path conflicts: if I attempt to call

curl -X DELETE http://localhost/machine-1/workspaces/workspace-1

I would expect, that the "removeWorkspace" should be called, but the problem is, that the "removeVM" is called. Does anybody get idea how to avoid such conflict? {machineId} prefix probably cause this conflict. Of course I'd like to keep those paths unchanged.

Thanks

Was it helpful?

Solution

This was a bug fixed meanwhile fixed in version 4.1-RC2, see this JIRA SPR-10576 for further details.

So it seems the only way to fix it in your current version would be to change the URL paths, or to apply the patch manually.

OTHER TIPS

You could try to use a regular expression to explain spring that @RequestMapping(value = "/{machineId}", method = RequestMethod.DELETE) should not match http://localhost/machine-1/workspaces/workspace-1

I have not tryed this before, but maybe it works for you:

  @RequestMapping(value = "/{machineId:[^/]*}", method = RequestMethod.DELETE)
  public void removeVM(@PathVariable String machineId) {...}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top