Im trying to use @DELETE request after a made some simple web application which i
ve tested using soapui. With this application i can add and get users/book to data base. Now im trying to made e @DELETE request but i can
t make it. Here is the code:
//UserServiceImpl
@PersistenceContext
private EntityManager em;
@Override
public void deleteUser(Long id) {
if (null == id || id.longValue() < 1) {
throw new IllegalArgumentException(" User id can not be null or less than zero. ");
}
User u = em.find(User.class, id);
em.remove(u);
}
//UserResource
@Autowired
private UserService userService;
@DELETE
@Path("/delete/{id}")
public Response deleteUser(@PathParam("id") String id) {
Response response;
try {
User user = userService.deleteUser(Long.valueOf(id));//here is the error
if (user != null) {
response = Response.status(HttpServletResponse.SC_OK).entity(user).build();
} else {
response = Response.status(HttpServletResponse.SC_NOT_FOUND).build();
}
} catch (IllegalArgumentException e) {
response = Response.status(HttpServletResponse.SC_NOT_FOUND).build();
}
return response;
}
Aucun commentaire:
Enregistrer un commentaire