@Test public void update() throws Exception { User created = service.create("name", "pwd", "mail"); Response response = WebClient.create("http: .path("/user/update/" + created.getId()) .query("name", "corrected") .query("pwd", "userpwd") .query("mail", "it@is.ok") .post(null); JAXBContext ctx = JAXBContext.newInstance(User.class); Unmarshaller unmarshaller = ctx.createUnmarshaller(); User modified = (User) unmarshaller.unmarshal(InputStream.class.cast(response.getEntity())); assertEquals("corrected", modified.getFullname()); assertEquals("userpwd", modified.getPassword()); assertEquals("it@is.ok", modified.getEmail()); service.delete(created.getId()); }
@Path("/update/{id}") @POST public Response update(@PathParam("id") long id, @QueryParam("name") String name, @QueryParam("pwd") String pwd, @QueryParam("mail") String mail) { User user = em.find(User.class, id); if (user == null) { throw new IllegalArgumentException("user id " + id + " not found"); } user.setFullname(name); user.setPassword(pwd); user.setEmail(mail); em.merge(user); return Response.ok(user.copy()).build(); }
UserService { @Path("/update/{id}") @POST public Response update(@PathParam("id") long id, @QueryParam("name") String name, @QueryParam("pwd") String pwd, @QueryParam("mail") String mail) { User user = em.find(User.class, id); if (user == null) { throw new IllegalArgumentException("user id " + id + " not found"); } user.setFullname(name); user.setPassword(pwd); user.setEmail(mail); em.merge(user); return Response.ok(user.copy()).build(); } }
UserService { @Path("/update/{id}") @POST public Response update(@PathParam("id") long id, @QueryParam("name") String name, @QueryParam("pwd") String pwd, @QueryParam("mail") String mail) { User user = em.find(User.class, id); if (user == null) { throw new IllegalArgumentException("user id " + id + " not found"); } user.setFullname(name); user.setPassword(pwd); user.setEmail(mail); em.merge(user); return Response.ok(user.copy()).build(); }  }
UserService { @Path("/update/{id}") @POST public Response update(@PathParam("id") long id, @QueryParam("name") String name, @QueryParam("pwd") String pwd, @QueryParam("mail") String mail) { User user = em.find(User.class, id); if (user == null) { throw new IllegalArgumentException("user id " + id + " not found"); } user.setFullname(name); user.setPassword(pwd); user.setEmail(mail); em.merge(user); return Response.ok(user.copy()).build(); }  @Path("/create") @PUT User create(@QueryParam("name") String name,
                       @QueryParam("pwd") String pwd,
                       @QueryParam("mail") String mail); @Path("/list") @GET List<User> list(@QueryParam("first") @DefaultValue("0") int first,
                           @QueryParam("max") @DefaultValue("20") int max); @Path("/show/{id}") @GET User find(@PathParam("id") long id); @Path("/delete/{id}") @DELETE void delete(@PathParam("id") long id); @Path("/update/{id}") @POST Response update(@PathParam("id") long id,
                           @QueryParam("name") String name,
                           @QueryParam("pwd") String pwd,
                           @QueryParam("mail") String mail); }
UserService { @Path("/update/{id}") @POST public Response update(@PathParam("id") long id, @QueryParam("name") String name, @QueryParam("pwd") String pwd, @QueryParam("mail") String mail) { User user = em.find(User.class, id); if (user == null) { throw new IllegalArgumentException("user id " + id + " not found"); } user.setFullname(name); user.setPassword(pwd); user.setEmail(mail); em.merge(user); return Response.ok(user.copy()).build(); }  @Path("/create") @PUT User create(@QueryParam("name") String name,
                       @QueryParam("pwd") String pwd,
                       @QueryParam("mail") String mail); @Path("/list") @GET List<User> list(@QueryParam("first") @DefaultValue("0") int first,
                           @QueryParam("max") @DefaultValue("20") int max); @Path("/show/{id}") @GET User find(@PathParam("id") long id); @Path("/delete/{id}") @DELETE void delete(@PathParam("id") long id); @Path("/update/{id}") @POST Response update(@PathParam("id") long id,
                           @QueryParam("name") String name,
                           @QueryParam("pwd") String pwd,
                           @QueryParam("mail") String mail);  }