On 13/04/2012 18:47, Colm O hEigeartaigh wrote:
Hi Francesco,
I've tried to go the reg-exp route, e.g.:
@RequestMapping(method = RequestMethod.GET, value =
"/deleteByUsername/{username:.*}")
public UserTO delete(@PathVariable final String username)
The username String gets picked up correctly
("[email protected]"). However, I see another error in the
logs:
SEVERE: Servlet.service() for servlet [syncope-core-rest] in context
with path [/syncope] threw exception [Could not resolve view with name
'user/deleteByUsername/delete.by.username@apache' in servlet with name
'syncope-core-rest'] with root cause
javax.servlet.ServletException: Could not resolve view with name
'user/deleteByUsername/delete.by.username@apache' in servlet with name
'syncope-core-rest'
Any ideas?
It seems that:
* when the REST method is annotated with strict matching (i.e.
"/deleteByUsername/{username}"), then Spring will strip off latest part
of {username} (after last '.'); this will result in an incorrect input
("delete.by.username@apache")
* when the REST method is annotated with extended matching (i.e.
"/deleteByUsername/{username:.*}"), then input is correct, but Spring's
ContentNegotiatingViewResolver will not be able to determine which kind
of return format the caller is expecting (registered extensions are
'.json' and '.xml', hence ".org" is not recognized)
After some googling (which led to a nice set of issues on Spring's
JIRA), I came to the conclusion that the following combination is
(probably) the only one working.
Index: core/src/test/java/org/syncope/core/rest/UserTestITCase.java
===================================================================
--- core/src/test/java/org/syncope/core/rest/UserTestITCase.java
(revisione 1326100)
+++ core/src/test/java/org/syncope/core/rest/UserTestITCase.java
(copia locale)
@@ -778,8 +778,7 @@
userTO = restTemplate.postForObject(BASE_URL + "user/create",
userTO, UserTO.class);
long id = userTO.getId();
- userTO =
- restTemplate.getForObject(BASE_URL +
"user/delete?username=" + userTO.getUsername(), UserTO.class);
+ userTO = restTemplate.getForObject(BASE_URL +
"user/deleteByUsername/{username}.json", UserTO.class,
userTO.getUsername());
assertNotNull(userTO);
assertEquals(id, userTO.getId());
Index:
core/src/main/java/org/syncope/core/rest/controller/UserController.java
===================================================================
---
core/src/main/java/org/syncope/core/rest/controller/UserController.java
(revisione 1326100)
+++
core/src/main/java/org/syncope/core/rest/controller/UserController.java
(copia locale)
@@ -440,8 +440,8 @@
}
@PreAuthorize("hasRole('USER_DELETE')")
- @RequestMapping(method = RequestMethod.GET, value = "/delete")
- public UserTO delete(@RequestParam("username") final String username)
+ @RequestMapping(method = RequestMethod.GET, value =
"/deleteByUsername/{username}")
+ public UserTO delete(@PathVariable final String username)
throws NotFoundException, WorkflowException,
PropagationException, UnauthorizedRoleException {
LOG.debug("User delete called with {}", username);
Basically, strict matching is used, but the caller (the integration test
case) must explicitly appending ".json": in this way the latest part of
matching string is stripped, but input is now correctly provided.
WDYT?
Regards.
--
Francesco Chicchiriccò
Apache Cocoon Committer and PMC Member
http://people.apache.org/~ilgrosso/