Classe Servidor:
package br.com.alura.loja.modelo;
import java.io.IOException;
import java.net.URI;
import org.glassfish.grizzly.http.server.HttpServer;
import org.glassfish.jersey.grizzly2.httpserver.GrizzlyHttpServerFactory;
import org.glassfish.jersey.server.ResourceConfig;
public class Servidor {
public static void main(String args[]) throws IOException {
URI uri = URI.create("http://localhost:8080");
ResourceConfig config = new ResourceConfig().packages("br.com.alura.loja");
HttpServer server = GrizzlyHttpServerFactory.createHttpServer(uri, config);
System.out.println("Servidor rodando");
System.in.read();
server.stop();
}
}
Classe CarrinhoResource:
package br.com.alura.loja.resource;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import br.com.alura.loja.dao.CarrinhoDAO;
import br.com.alura.loja.modelo.Carrinho;
@Path("carrinhos")
public class CarrinhoResource {
@GET
@Produces("text/xml")
public String busca(){
CarrinhoDAO daoCarrinho = new CarrinhoDAO();
Carrinho carrinhoEncontrado = daoCarrinho.busca(1l);
return carrinhoEncontrado.toXml();
}
}