Meu CarrinhoResource está dando erro no comando:
URI uri = URI.create("/carrinhos/" + carrinho.getId());
Meu código:
package br.com.alura.loja.resource;
import javax.ws.rs.Consumes; 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; import javax.ws.rs.core.MediaType;
import org.glassfish.grizzly.http.server.Response;
import com.thoughtworks.xstream.XStream;
import br.com.alura.loja.dao.CarrinhoDAO; import br.com.alura.loja.modelo.Carrinho;
@Path("carrinhos") // URI servidor public class CarrinhoResource {
@Path("{id}")
@GET
@Produces(MediaType.APPLICATION_XML)
public String busca(@PathParam("id") long id) {
Carrinho carrinho = new CarrinhoDAO().busca(id);
return carrinho.toXML();
}
@POST
@Consumes(MediaType.APPLICATION_XML)
public Response adiciona(String conteudo) {
Carrinho carrinho = (Carrinho) new XStream().fromXML(conteudo);
new CarrinhoDAO().adiciona(carrinho);
URI uri = URI.create("/carrinhos/" + carrinho.getId());
return Response.created(uri).build();
}
}