Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package teste;
- import java.util.LinkedList;
- import java.util.List;
- import javax.ws.rs.DELETE;
- import javax.ws.rs.GET;
- import javax.ws.rs.POST;
- import javax.ws.rs.Path;
- import javax.ws.rs.PathParam;
- import javax.ws.rs.Produces;
- @Path("agenda")
- @Produces( { "text/xml", "application/json" })
- public class Agenda {
- @GET
- @Path("ping")
- @Produces("text/plain")
- public String ping() {
- return "Pong!";
- }
- @GET
- // @Path("all")
- public List<Contato> getContatos() {
- List<Contato> list = new LinkedList<Contato>();
- list.add(new Contato(1, "Fulano 1", "Rua tal", "12345678"));
- list.add(new Contato(2, "Fulano 2", "Rua tal", "12345678"));
- list.add(new Contato(3, "Fulano 3", "Rua tal", "12345678"));
- list.add(new Contato(4, "Fulano 4", "Rua tal", "12345678"));
- list.add(new Contato(5, "Fulano 5", "Rua tal", "12345678"));
- return list;
- }
- @GET
- @Path("{id}")
- public Contato getContato(@PathParam("id") int id) {
- return new Contato(id, "Fulano", "Rua tal", "12345678");
- }
- // XXX como fazer um 200 ok nisso? terei de lidar com o retorno 204?
- @POST
- public void addContato(Contato c) {
- System.out.println(c.printar());
- System.out.println("teste");
- }
- @DELETE
- @Path("{id}")
- public void deleteContato(@PathParam("id") int id) {
- System.out.println("deletado id " + id);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment